From de096ea780245c8beb748839120e5669fe37d457 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 9 Apr 2025 19:31:30 +0800 Subject: Rename and fix pdlen read. --- nrfm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'nrfm.c') diff --git a/nrfm.c b/nrfm.c index afbb1d9..1c3444a 100644 --- a/nrfm.c +++ b/nrfm.c @@ -163,6 +163,9 @@ static inline uint8_t rx_pdlen(void) { SPI_PORT &= ~(1 << SPI_SS); SPDR = 0b01100000; + while (!(SPSR & (1 << SPIF))) + ; + SPDR = NOP; while (!(SPSR & (1 << SPIF))) ; SPI_PORT |= (1 << SPI_SS); @@ -287,8 +290,8 @@ void radio_listen(void) uint8_t radio_recv(char *buf, uint8_t n) { - char s[5]; - uint8_t rxdr, readlen, pdlen, maxlen; + char s[3]; + uint8_t readlen, pdlen, maxlen; pdlen = 0; disable_chip(); @@ -300,8 +303,14 @@ uint8_t radio_recv(char *buf, uint8_t n) uart_write_line("ERROR: PDLEN = 0, abort read"); return 0; } + + s[2] = '\0'; + pdlen = 0; + pdlen = rx_pdlen(); + itoa(pdlen, s, 10); + uart_write("DEBUG: PDLEN="); + uart_write_line(s); - // for some reason, PDLEN reads as 64 causing the below check to fail //if (pdlen > MAXPDLEN) { // flush_rx(); // reset_irqs(); -- cgit v1.2.3