From e0021c1579ae329e8a78eda6979616fa7ceb456e Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Tue, 10 Dec 2024 19:47:36 +0800 Subject: wip: rx. --- rf_test/radio.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/rf_test/radio.c b/rf_test/radio.c index 83bd7c2..9dc3528 100644 --- a/rf_test/radio.c +++ b/rf_test/radio.c @@ -75,24 +75,21 @@ uint8_t radio_recv(char *buf, uint8_t n) read_len = 0; - if ((read_reg(0x28) & 0x04)) - { - write_reg(0x01, 0x04); - while ((read_reg(0x27) >> 7) != 1) - ; + write_reg(0x01, 0x04); + while ((read_reg(0x27) & 0x80)) + ; - SPI_PORT &= ~(1 << SPI_SS); - SPDR = 0x00 | 0x7F; + SPI_PORT &= ~(1 << SPI_SS); + SPDR = 0x00 | 0x7F; + while (!(SPSR & (1 << SPIF))) + ; + while (read_len < n) { + SPDR = 0; while (!(SPSR & (1 << SPIF))) ; - while (read_len < n) { - SPDR = 0; - while (!(SPSR & (1 << SPIF))) - ; - buf[read_len++] = SPDR; - } - SPI_PORT |= (1 << SPI_SS); - } + buf[read_len++] = SPDR; + } + SPI_PORT |= (1 << SPI_SS); return read_len; } -- cgit v1.2.3