Skip to content

Commit fa57a48

Browse files
committed
[Si4463] add probing procedure [skip ci]
1 parent fa56474 commit fa57a48

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

software/firmware/source/SoftRF/src/driver/radio/radiohead.cpp

+45-21
Original file line numberDiff line numberDiff line change
@@ -135,39 +135,58 @@ static int8_t si4463_channel_prev = (int8_t) -1;
135135
static bool si4463_receive_active = false;
136136
static bool si4463_transmit_complete = false;
137137

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+
139142
#if defined(USE_BASICMAC)
140-
hal_spi_select(1);
143+
hal_spi_select(1);
141144
#else
142-
hal_pin_nss(0);
145+
hal_pin_nss(0);
143146
#endif
144-
hal_spi(addr & 0x7F);
145-
u1_t val = hal_spi(0x00);
147+
148+
hal_spi(cmd);
149+
146150
#if defined(USE_BASICMAC)
147-
hal_spi_select(0);
151+
hal_spi_select(0);
148152
#else
149-
hal_pin_nss(1);
153+
hal_pin_nss(1);
150154
#endif
151-
return val;
152-
}
153155

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+
{
155159
#if defined(USE_BASICMAC)
156160
hal_spi_select(1);
157161
#else
158162
hal_pin_nss(0);
159163
#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+
162175
#if defined(USE_BASICMAC)
163176
hal_spi_select(0);
164177
#else
165178
hal_pin_nss(1);
166179
#endif
180+
}
181+
182+
return done;
167183
}
168184

169185
static bool si4463_probe()
170186
{
187+
uint8_t buf[8];
188+
uint16_t deviceType;
189+
171190
SoC->SPI_begin();
172191

173192
lmic_hal_init (nullptr);
@@ -178,22 +197,27 @@ static bool si4463_probe()
178197
hal_pin_rst(0); // drive SDN pin low
179198
delay(100);
180199

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));
185201

186202
pinMode(lmic_pins.nss, INPUT);
187203
RadioSPI.end();
188204

189205
hal_pin_rst(2); // configure SDN pin floating!
190206

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 {
192220
return true;
193-
} else
194-
#endif
195-
{
196-
return false;
197221
}
198222
}
199223

software/firmware/source/SoftRF/src/platform/PSoC4.h

+1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ extern softSerial swSer;
215215
//#define EXCLUDE_LR11XX
216216
#define EXCLUDE_CC1101
217217
#define EXCLUDE_SI443X
218+
#define EXCLUDE_SI446X
218219
#define EXCLUDE_SX1231
219220

220221
#define USE_TIME_SLOTS

0 commit comments

Comments
 (0)