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. --- dong.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 dong.c (limited to 'dong.c') diff --git a/dong.c b/dong.c new file mode 100644 index 0000000..70006dc --- /dev/null +++ b/dong.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +#include "nrfm.h" +#include "uart.h" + +#define RX_PIN PD7 +#define RX_DDR DDRD +#define RX_PORT PORTD +#define RX_PCIE PCIE2 +#define RX_PCINT PCINT23 +#define RX_PCMSK PCMSK2 +#define RX_PCINTVEC PCINT2_vect + +static int rxdr = 0; + +int main(void) +{ + uint8_t n; + char buf[MAXPDLEN + 1]; + + uint8_t rxaddr[] = { 194, 178, 83 }; + + RX_DDR &= ~(1 << RX_PIN); + RX_PORT |= (1 << RX_PIN); + PCICR |= (1 << RX_PCIE); + RX_PCMSK |= (1 << RX_PCINT); + + uart_init(); + radio_init(rxaddr); + radio_print_config(); + + sei(); + radio_listen(); + + for (;;) { + if (rxdr) { + uart_write_line("IRQ recv, reading data"); + n = radio_recv(buf, MAXPDLEN); + buf[n] = '\0'; + rxdr = 0; + if (n > 0) { + uart_write("INFO: "); + uart_write_line(buf); + } + } else { + uart_write_line("No IRQ"); + _delay_ms(2000); + } + } + + return 0; +} + +ISR(RX_PCINTVEC) +{ + rxdr = 1; +} -- cgit v1.2.3