diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-02-01 11:25:19 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-02-01 11:25:19 +0800 |
| commit | 50deb9d280254c8e17624b368ea778f69dd86767 (patch) | |
| tree | 5ca1724ebdee3ff2a786dc37b6cc266ba9cb0585 /rf69/recv.c | |
| parent | a7644c020c4c2b72fc0f13aeea4be47ba08f1961 (diff) | |
| download | smart-home-50deb9d280254c8e17624b368ea778f69dd86767.tar.gz | |
Start work on nRF24L01.
Diffstat (limited to 'rf69/recv.c')
| -rw-r--r-- | rf69/recv.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/rf69/recv.c b/rf69/recv.c new file mode 100644 index 0000000..1c6ac0f --- /dev/null +++ b/rf69/recv.c @@ -0,0 +1,64 @@ +#include <avr/io.h> +#include <avr/interrupt.h> + +#include "radio.h" +#include "serial.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 + +#define MAX_PAYLOAD_LEN 60 + +static char *s = "hello, world!"; +static uint8_t slen = 13; + +int main(void) +{ + struct radio_cfg cfg; + + cfg.netid = 0x01; + cfg.nodeid = 0x01; + cfg.payload_len = slen; + + RX_DDR &= ~(1 << RX_PIN); + RX_PORT &= ~(1 << RX_PIN); + PCICR |= (1 << RX_PCIE); + RX_PCMSK |= (1 << RX_PCINT); + + serial_init(); + + radio_init(&cfg); + radio_listen(); + + sei(); + + for (;;) + ; + + return 0; +} + +ISR(RX_PCINTVEC) +{ + uint8_t i, n; + char buf[MAX_PAYLOAD_LEN]; + + cli(); + + serial_write_line("Detected pin change IRQ"); + + n = radio_recv(buf, MAX_PAYLOAD_LEN - 1); + buf[n] = '\0'; + + for (i = 0; i < n; i++) + serial_write(buf[i]); + serial_write('\r'); + serial_write('\n'); + + sei(); +} |
