From f2801a35b43f4117d97dd4d8eba9db480454c9e3 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 6 Apr 2025 10:11:09 +0800 Subject: Fix programming errors in setting the address registers. --- Send.Makefile | 2 +- nrfm.c | 2 +- nrfm.h | 2 +- recv.c | 1 - send.c | 12 +++++++++--- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Send.Makefile b/Send.Makefile index 7c20759..941fa0f 100644 --- a/Send.Makefile +++ b/Send.Makefile @@ -1,6 +1,6 @@ CC = avr-gcc MCU = atmega328p -TARGET = app +TARGET = sender SRC = send.c uart.c nrfm.c OBJ = $(SRC:.c=.o) diff --git a/nrfm.c b/nrfm.c index 29484e6..c3f8ec9 100644 --- a/nrfm.c +++ b/nrfm.c @@ -81,7 +81,7 @@ static inline void read_reg_bulk(uint8_t reg, uint8_t *data, uint8_t n) static inline void setaddr(uint8_t reg, const uint8_t addr[ADDRLEN]) { - uint8_t i; + int i; SPI_PORT &= ~(1 << SPI_SS); SPDR = (reg & 0x1F) | W_REGISTER; diff --git a/nrfm.h b/nrfm.h index 43f7c62..22a9b89 100644 --- a/nrfm.h +++ b/nrfm.h @@ -3,7 +3,7 @@ #include -#define ADDRLEN 5 +#define ADDRLEN 3 #define MAXPDLEN 32 void radio_init(const uint8_t rxaddr[ADDRLEN]); diff --git a/recv.c b/recv.c index efff67e..31dbc0f 100644 --- a/recv.c +++ b/recv.c @@ -39,7 +39,6 @@ int main(void) n = radio_recv(buf, MAXPDLEN); buf[n] = '\0'; rxdr = 0; - uart_write("INFO: "); uart_write_line(buf); diff --git a/send.c b/send.c index fed243c..21ca541 100644 --- a/send.c +++ b/send.c @@ -1,5 +1,6 @@ #include #include +#include #include "nrfm.h" #include "uart.h" @@ -7,15 +8,20 @@ int main(void) { const char *s = "hello world!"; + uint8_t slen = strlen(s); - uint8_t rxaddr[] = { 194, 178, 82 }; - uint8_t txaddr[] = { 194, 178, 83 }; + uint8_t rxaddr[ADDRLEN] = { 194, 178, 82 }; + uint8_t txaddr[ADDRLEN] = { 194, 178, 83 }; uart_init(); radio_init(rxaddr); radio_print_config(); - radio_sendto(txaddr, s, strlen(s)); + for (;;) { + radio_sendto(txaddr, s, slen); + _delay_ms(1000); + } + return 0; } -- cgit v1.2.3