Skip to content

Commit

Permalink
checks NRF24 hardware faults
Browse files Browse the repository at this point in the history
  • Loading branch information
vad7 committed Mar 17, 2023
1 parent dd7fcfc commit 0e4bb3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/nrf24/nrf24.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,22 @@ uint8_t nrf24_set_packetlen(FuriHalSpiBusHandle* handle, uint8_t len) {
}

// packet_size: 0 - dyn payload (read from PL_WID), 1 - read from pipe size, >1 - override
// Return STATUS reg + additional: RX_DR - new data available, 0x80 - NRF24 hardware error
uint8_t nrf24_rxpacket(FuriHalSpiBusHandle* handle, uint8_t* packet, uint8_t* ret_packetsize, uint8_t packet_size) {
uint8_t status = 0;
uint8_t buf[33]; // 32 max payload size + 1 for command

status = nrf24_status(handle);
if(!(status & RX_DR)) {
if((nrf24_read_register(handle, REG_FIFO_STATUS) & 1) == 0) {
uint8_t st = nrf24_read_register(handle, REG_FIFO_STATUS);
if(st == 0xFF || st == 0) return 0x80; // hardware error
if((st & 1) == 0) {
FURI_LOG_D("NRF", "FIFO PKT");
status |= RX_DR; // packet in FIFO buffer
}
}
if(status & RX_DR) {
if(status & 0x80) return 0x80; // hardware error
if(packet_size == 1)
packet_size = nrf24_get_packetlen(handle, (status >> 1) & 7);
else if(packet_size == 0){
Expand Down
3 changes: 3 additions & 0 deletions nrf24batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ bool nrf24_read_newpacket() {
}
//notification_message(APP->notification, &sequence_blink_white_100);
found = true;
} else if(st & 0x80) { // NRF24 hardware error
NRF_ERROR = 1;
NRF_INITED = 0;
}
return found;
}
Expand Down

0 comments on commit 0e4bb3d

Please sign in to comment.