@@ -135,39 +135,58 @@ static int8_t si4463_channel_prev = (int8_t) -1;
135
135
static bool si4463_receive_active = false ;
136
136
static bool si4463_transmit_complete = false ;
137
137
138
- static u1_t si4463_readReg (u1_t addr) {
138
+ static bool si4463_CommandRead (uint8_t cmd, uint8_t * read_buf, uint8_t read_len)
139
+ {
140
+ bool done = false ;
141
+
139
142
#if defined(USE_BASICMAC)
140
- hal_spi_select (1 );
143
+ hal_spi_select (1 );
141
144
#else
142
- hal_pin_nss (0 );
145
+ hal_pin_nss (0 );
143
146
#endif
144
- hal_spi (addr & 0x7F );
145
- u1_t val = hal_spi (0x00 );
147
+
148
+ hal_spi (cmd);
149
+
146
150
#if defined(USE_BASICMAC)
147
- hal_spi_select (0 );
151
+ hal_spi_select (0 );
148
152
#else
149
- hal_pin_nss (1 );
153
+ hal_pin_nss (1 );
150
154
#endif
151
- return val;
152
- }
153
155
154
- static void si4463_writeReg (u1_t addr, u1_t data) {
156
+ uint16_t count; // Number of times we have tried to get CTS
157
+ for (count = 0 ; !done && count < RH_RF24_CTS_RETRIES; count++)
158
+ {
155
159
#if defined(USE_BASICMAC)
156
160
hal_spi_select (1 );
157
161
#else
158
162
hal_pin_nss (0 );
159
163
#endif
160
- hal_spi (addr | 0x80 );
161
- hal_spi (data);
164
+
165
+ hal_spi (RH_RF24_CMD_READ_BUF);
166
+ if (hal_spi (0x00 ) == RH_RF24_REPLY_CTS) {
167
+ // Now read any expected reply data
168
+ if (read_buf && read_len) {
169
+ while (read_len--)
170
+ *read_buf++ = hal_spi (0x00 );
171
+ }
172
+ done = true ;
173
+ }
174
+
162
175
#if defined(USE_BASICMAC)
163
176
hal_spi_select (0 );
164
177
#else
165
178
hal_pin_nss (1 );
166
179
#endif
180
+ }
181
+
182
+ return done;
167
183
}
168
184
169
185
static bool si4463_probe ()
170
186
{
187
+ uint8_t buf[8 ];
188
+ uint16_t deviceType;
189
+
171
190
SoC->SPI_begin ();
172
191
173
192
lmic_hal_init (nullptr );
@@ -178,22 +197,27 @@ static bool si4463_probe()
178
197
hal_pin_rst (0 ); // drive SDN pin low
179
198
delay (100 );
180
199
181
- #if 0
182
- u1_t v = si4463_readReg(RH_RF22_REG_01_VERSION_CODE);
183
-
184
- Serial.print("si4463 version = "); Serial.println(v, HEX);
200
+ bool status = si4463_CommandRead (RH_RF24_CMD_PART_INFO, buf, sizeof (buf));
185
201
186
202
pinMode (lmic_pins.nss , INPUT);
187
203
RadioSPI.end ();
188
204
189
205
hal_pin_rst (2 ); // configure SDN pin floating!
190
206
191
- if (v == RADIOHEAD_SI443X_DEVICE_VERSION) {
207
+ if (!status) {
208
+ return false ; // SPI error ? Not connected ?
209
+ }
210
+
211
+ deviceType = (buf[1 ] << 8 ) | buf[2 ];
212
+
213
+ Serial.print (" si44xx device = " ); Serial.println (deviceType, HEX);
214
+
215
+ // Check PART to be either 0x4460, 0x4461, 0x4463, 0x4464
216
+ if (deviceType != 0x4460 && deviceType != 0x4461 &&
217
+ deviceType != 0x4463 && deviceType != 0x4464 ) {
218
+ return false ; // Unknown radio type, or not connected
219
+ } else {
192
220
return true ;
193
- } else
194
- #endif
195
- {
196
- return false ;
197
221
}
198
222
}
199
223
0 commit comments