From c3d001a15f759051cfc5994cd6dbc21013a3f2f3 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 24 Apr 2025 10:28:12 +0800 Subject: Fix recv() return value, still sending 2 packets. --- nrfm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nrfm.c b/nrfm.c index 5b2dfe9..5f0202c 100644 --- a/nrfm.c +++ b/nrfm.c @@ -316,13 +316,13 @@ uint8_t radio_recv(char *buf, uint8_t n) return 0; } - readmax = (n - 1) < pdlen ? (n - 1) : pdlen; + readmax = n < pdlen ? n : pdlen; SPI_PORT &= ~(1 << SPI_SS); SPDR = 0b01100001; while (!(SPSR & (1 << SPIF))) ; - for (readlen = 0; readlen <= readmax; readlen++) { + for (readlen = 0; readlen < readmax; readlen++) { SPDR = NOP; while (!(SPSR & (1 << SPIF))) ; @@ -334,5 +334,5 @@ uint8_t radio_recv(char *buf, uint8_t n) reset_irqs(); enable_chip(); - return readlen - 1; + return readlen; } -- cgit v1.2.3