From 8096af0fd2902e4143f645bde4ff49b4340b3b34 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Mon, 2 Dec 2024 20:43:43 +0800 Subject: wip: rx. --- rf_test/send.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/rf_test/send.c b/rf_test/send.c index 752d231..7290c71 100644 --- a/rf_test/send.c +++ b/rf_test/send.c @@ -22,11 +22,6 @@ #define RX_PCMSK PCMSK0 #define RX_PCINTVEC PCINT0_vect -#define RX_BUFLEN 32 - -static char rxbuf[RX_BUFLEN]; -static volatile uint8_t rx_ready = 0; - static inline uint8_t read_reg(uint8_t reg) { SPI_PORT &= ~(1 << SPI_SS); @@ -81,13 +76,25 @@ static inline void radio_send(const char *data, uint8_t n) while ((read_reg(0x27) >> 7) != 1) ; - // STDBY + ListenOn mode + // enable ListenOn in STDBY mode write_reg(0x01, (read_reg(0x01) | 0x40)); } -static inline void radio_recv(char *buf, uint8_t n) +static inline uint8_t radio_recv(char *buf, uint8_t n) { uint8_t i; + + if ((read_reg(0x28) & 0x04) != 0) + { + write_reg(0x01, 0x04); + while ((read_reg(0x27) >> 7) != 1) + ; + + for (i = 0; i < n; i++) { + } + } + + return i; } static inline void radio_init(void) @@ -121,12 +128,10 @@ int main(void) ISR(RX_PCINTVEC) { - uint8_t i; - char buf[RX_BUFLEN]; + uint8_t n; - if ((read_reg(0x28) & 0x04) != 0) - { - for (i = 0; i < RX_BUFLEN; i++) { - } - } + const uint8_t buflen = 32; + char buf[buflen]; + + n = radio_recv(buf, buflen); } -- cgit v1.2.3