[SX126x] Added BUSY timeout
This commit is contained in:
parent
b0cd4b5125
commit
ea1e6fea68
2 changed files with 14 additions and 6 deletions
|
@ -1172,14 +1172,18 @@ int16_t SX126x::SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, boo
|
||||||
return(SX126x::SPItransfer(cmdBuffer, 1, false, NULL, data, numBytes, waitForBusy));
|
return(SX126x::SPItransfer(cmdBuffer, 1, false, NULL, data, numBytes, waitForBusy));
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy) {
|
int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout) {
|
||||||
// get pointer to used SPI interface and the settings
|
// get pointer to used SPI interface and the settings
|
||||||
SPIClass* spi = _mod->getSpi();
|
SPIClass* spi = _mod->getSpi();
|
||||||
SPISettings spiSettings = _mod->getSpiSettings();
|
SPISettings spiSettings = _mod->getSpiSettings();
|
||||||
|
|
||||||
// ensure BUSY is low (state meachine ready)
|
// ensure BUSY is low (state meachine ready)
|
||||||
// TODO timeout
|
uint32_t start = millis();
|
||||||
while(digitalRead(_mod->getRx()));
|
while(digitalRead(_mod->getRx())) {
|
||||||
|
if(millis() - start >= timeout) {
|
||||||
|
return(ERR_SPI_CMD_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// start transfer
|
// start transfer
|
||||||
digitalWrite(_mod->getCs(), LOW);
|
digitalWrite(_mod->getCs(), LOW);
|
||||||
|
@ -1242,10 +1246,14 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
||||||
digitalWrite(_mod->getCs(), HIGH);
|
digitalWrite(_mod->getCs(), HIGH);
|
||||||
|
|
||||||
// wait for BUSY to go high and then low
|
// wait for BUSY to go high and then low
|
||||||
// TODO timeout
|
|
||||||
if(waitForBusy) {
|
if(waitForBusy) {
|
||||||
delayMicroseconds(1);
|
delayMicroseconds(1);
|
||||||
while(digitalRead(_mod->getRx()));
|
start = millis();
|
||||||
|
while(digitalRead(_mod->getRx())) {
|
||||||
|
if(millis() - start >= timeout) {
|
||||||
|
return(ERR_SPI_CMD_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse status
|
// parse status
|
||||||
|
|
|
@ -738,7 +738,7 @@ class SX126x: public PhysicalLayer {
|
||||||
// common low-level SPI interface
|
// common low-level SPI interface
|
||||||
int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
|
int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
|
||||||
int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
|
int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);
|
||||||
int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy);
|
int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout = 5000);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue