Browse Source

Print message when CC2500 status changes.

Thomas Buck 8 years ago
parent
commit
97306bbe4f
1 changed files with 125 additions and 3 deletions
  1. 125
    3
      src/cc2500.c

+ 125
- 3
src/cc2500.c View File

@@ -6,47 +6,169 @@
6 6
 
7 7
 #include "spi.h"
8 8
 #include "cc2500.h"
9
+#include "main.h"
10
+
11
+#ifdef DEBUG
12
+
13
+static void cc2500PrintStatusByte(uint8_t status) {
14
+    static int16_t lastStatusByte = -1;
15
+    //if ((status & ~CC2500_STATUS_FIFO_BYTES_AVAILABLE_BM) != (lastStatusByte & ~CC2500_STATUS_FIFO_BYTES_AVAILABLE_BM)) {
16
+    if (status != lastStatusByte) {
17
+        lastStatusByte = status;
18
+
19
+        debugWrite("\nStatus change: 0x");
20
+        debugHex(status);
21
+        debugWrite("\n");
22
+
23
+        if (status & CC2500_STATUS_CHIP_RDYn_BM) {
24
+            debugWrite("  Power/Crystal NOT ready!\n");
25
+        }
26
+
27
+        debugWrite("  State: ");
28
+        switch (status & CC2500_STATUS_STATE_BM) {
29
+            case CC2500_STATE_IDLE:
30
+                debugWrite("IDLE");
31
+                break;
32
+
33
+            case CC2500_STATE_RX:
34
+                debugWrite("RX");
35
+                break;
36
+
37
+            case CC2500_STATE_TX:
38
+                debugWrite("TX");
39
+                break;
40
+
41
+            case CC2500_STATE_FSTXON:
42
+                debugWrite("Freq Synth TX on");
43
+                break;
44
+
45
+            case CC2500_STATE_CALIBRATE:
46
+                debugWrite("Freq Synth Calibration");
47
+                break;
48
+
49
+            case CC2500_STATE_SETTLING:
50
+                debugWrite("PLL settling");
51
+                break;
52
+
53
+            case CC2500_STATE_RX_OVERFLOW:
54
+                debugWrite("RX FIFO Overflow");
55
+                break;
56
+
57
+            case CC2500_STATE_TX_UNDERFLOW:
58
+                debugWrite("TX FIFO Underflow");
59
+                break;
60
+
61
+            default:
62
+                debugWrite("UNKNOWN");
63
+                break;
64
+        }
65
+        debugWrite("\n");
66
+
67
+        debugWrite("  FIFO Bytes available: 0x");
68
+        debugHex(status & CC2500_STATUS_FIFO_BYTES_AVAILABLE_BM);
69
+        debugWrite("\n\n");
70
+    }
71
+}
72
+#endif
9 73
 
10 74
 void cc2500ReadRegisterMulti(uint8_t address, uint8_t data[], uint8_t length) {
11 75
     CS_off;
76
+
77
+#ifdef DEBUG
78
+    uint8_t status = spiWrite(address);
79
+#else
12 80
     spiWrite(address);
81
+#endif
82
+
13 83
     for (uint8_t i = 0; i < length; i++) {
14 84
         data[i] = spiRead();
15 85
     }
86
+
16 87
     CS_on;
88
+
89
+#ifdef DEBUG
90
+    cc2500PrintStatusByte(status);
91
+#endif
17 92
 }
18 93
 
19 94
 void cc2500WriteRegisterMulti(uint8_t address, const uint8_t data[], uint8_t length) {
20 95
     CS_off;
96
+
97
+#ifdef DEBUG
98
+    uint8_t status = spiWrite(CC2500_WRITE_BURST | address);
99
+#else
21 100
     spiWrite(CC2500_WRITE_BURST | address);
101
+#endif
102
+
22 103
     for (uint8_t i = 0; i < length; i++) {
23 104
         spiWrite(data[i]);
24 105
     }
106
+
25 107
     CS_on;
108
+
109
+#ifdef DEBUG
110
+    cc2500PrintStatusByte(status);
111
+#endif
26 112
 }
27 113
 
28 114
 void cc2500WriteReg(uint8_t address, uint8_t data) {
29 115
     CS_off;
116
+
117
+#ifdef DEBUG
118
+    uint8_t status = spiWrite(address);
119
+#else
30 120
     spiWrite(address);
121
+#endif
122
+
31 123
     NOP();
32 124
     spiWrite(data);
33 125
     CS_on;
126
+
127
+#ifdef DEBUG
128
+    cc2500PrintStatusByte(status);
129
+#endif
34 130
 }
35 131
 
36 132
 uint8_t cc2500ReadReg(uint8_t address) {
37
-    uint8_t result;
38 133
     CS_off;
39
-    address |= 0x80; // bit 7 =1 for reading
134
+
135
+    if ((address >= 0x30) && (address <= 0x3D)) {
136
+        // Status Registers need a burst read
137
+        address |= CC2500_READ_BURST;
138
+    } else {
139
+        address |= CC2500_READ_SINGLE;
140
+    }
141
+
142
+#ifdef DEBUG
143
+    uint8_t status = spiWrite(address);
144
+#else
40 145
     spiWrite(address);
41
-    result = spiRead();
146
+#endif
147
+
148
+    uint8_t result = spiRead();
42 149
     CS_on;
150
+
151
+#ifdef DEBUG
152
+    cc2500PrintStatusByte(status);
153
+#endif
154
+
43 155
     return result;
44 156
 }
45 157
 
46 158
 void cc2500Strobe(uint8_t address) {
47 159
     CS_off;
160
+
161
+#ifdef DEBUG
162
+    uint8_t status = spiWrite(address);
163
+#else
48 164
     spiWrite(address);
165
+#endif
166
+
49 167
     CS_on;
168
+
169
+#ifdef DEBUG
170
+    cc2500PrintStatusByte(status);
171
+#endif
50 172
 }
51 173
 
52 174
 void cc2500ResetChip(void) {

Loading…
Cancel
Save