summaryrefslogtreecommitdiffstats
path: root/rf_test
diff options
context:
space:
mode:
Diffstat (limited to 'rf_test')
-rw-r--r--rf_test/radio.c36
-rw-r--r--rf_test/recv.c6
2 files changed, 27 insertions, 15 deletions
diff --git a/rf_test/radio.c b/rf_test/radio.c
index 4926280..d7d8819 100644
--- a/rf_test/radio.c
+++ b/rf_test/radio.c
@@ -64,17 +64,17 @@ void radio_send(const char *data, uint8_t n)
;
// todo: do a more reliable check
- _delay_ms(5);
+ _delay_ms(10);
// ListenOn
write_reg(0x01, (read_reg(0x01) | 0x40));
}
-uint8_t radio_recv(char *buf, uint8_t n)
+uint8_t radio_recv(char *buf, uint8_t buflen)
{
- uint8_t i;
+ uint8_t i, n, readlen;
- i = 0;
+ readlen = 0;
if ((read_reg(0x28) & 0x04))
{
@@ -83,18 +83,27 @@ uint8_t radio_recv(char *buf, uint8_t n)
;
SPI_PORT &= ~(1 << SPI_SS);
+
SPDR = 0x00 | 0x7F;
while (!(SPSR & (1 << SPIF)))
;
- while (i < n) {
+
+ SPDR = 0;
+ while (!(SPSR & (1 << SPIF)))
+ ;
+ n = SPDR;
+
+ for (i = 0; i < n; i++) {
SPDR = 0;
while (!(SPSR & (1 << SPIF)))
;
- buf[i++] = SPDR;
+ if (readlen < buflen)
+ buf[readlen++] = SPDR;
}
+
SPI_PORT |= (1 << SPI_SS);
}
- return i;
+ return readlen;
}
void radio_init(struct radio_cfg *cfg)
@@ -103,12 +112,15 @@ void radio_init(struct radio_cfg *cfg)
SPI_PORT |= (1 << SPI_SS);
SPCR |= (1 << SPE) | (1 << MSTR);
- if (cfg->payload_len > 0)
- write_reg(0x38, cfg->payload_len);
+ // standby
+ write_reg(0x01, 0x04);
+ while ((read_reg(0x27) >> 7) != 1)
+ ;
- // enable power amplifiers PA1 and PA2 for transmission
+ // enable power amplifiers PA1 and PA2
write_reg(0x13, 0x0F);
write_reg(0x11, ((read_reg(0x11) & 0x1F) | 0x60));
+
+ // enable ListenOn
+ write_reg(0x01, (read_reg(0x01) | 0x40));
}
-
-
diff --git a/rf_test/recv.c b/rf_test/recv.c
index 64451a0..74d1672 100644
--- a/rf_test/recv.c
+++ b/rf_test/recv.c
@@ -4,7 +4,7 @@
#include "radio.h"
#include "serial.h"
-#define PAYLOAD_LEN 13
+#define BUFLEN 61
#define RX_PIN PB0
#define RX_DDR DDRB
@@ -38,13 +38,13 @@ int main(void)
ISR(RX_PCINTVEC)
{
uint8_t i, n;
- char buf[PAYLOAD_LEN + 1];
+ char buf[BUFLEN + 1];
cli();
serial_write_line("Handling pin change IRQ");
- n = radio_recv(buf, PAYLOAD_LEN);
+ n = radio_recv(buf, BUFLEN);
buf[n] = '\0';
for (i = 0; i < n; i++)