summaryrefslogtreecommitdiffstats
path: root/nRF24L01
diff options
context:
space:
mode:
Diffstat (limited to 'nRF24L01')
-rw-r--r--nRF24L01/Recv.Makefile43
-rw-r--r--nRF24L01/Send.Makefile44
-rw-r--r--nRF24L01/radio.c133
-rw-r--r--nRF24L01/radio.h19
-rw-r--r--nRF24L01/recv.c64
-rw-r--r--nRF24L01/send.c34
-rw-r--r--nRF24L01/serial.c33
-rw-r--r--nRF24L01/serial.h8
8 files changed, 0 insertions, 378 deletions
diff --git a/nRF24L01/Recv.Makefile b/nRF24L01/Recv.Makefile
deleted file mode 100644
index 67ac41f..0000000
--- a/nRF24L01/Recv.Makefile
+++ /dev/null
@@ -1,43 +0,0 @@
-CC = avr-gcc
-MCU = atmega328p
-TARGET = recv
-
-SRC = radio.c recv.c serial.c
-OBJ = $(SRC:.c=.o)
-
-CFLAGS = -std=gnu99
-CFLAGS += -Os
-CFLAGS += -Wall
-CFLAGS += -mmcu=$(MCU)
-CFLAGS += -DBAUD=115200
-CFLAGS += -DF_CPU=16000000UL
-CFLAGS += -ffunction-sections -fdata-sections
-
-LDFLAGS = -mmcu=$(MCU)
-LDFLAGS += -Wl,--gc-sections
-
-HEX_FLAGS = -O ihex
-HEX_FLAGS += -j .text -j .data
-
-AVRDUDE_FLAGS = -p $(MCU)
-AVRDUDE_FLAGS += -c arduino
-AVRDUDE_FLAGS += -P /dev/cuaU0
-AVRDUDE_FLAGS += -D -U
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-elf: $(OBJ)
- $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf
-
-hex: elf
- avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex
-
-upload: hex
- avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i
-
-.PHONY: clean
-
-clean:
- rm *.o *.elf *.hex
-
diff --git a/nRF24L01/Send.Makefile b/nRF24L01/Send.Makefile
deleted file mode 100644
index 06e083b..0000000
--- a/nRF24L01/Send.Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
-CC = avr-gcc
-MCU = atmega328p
-TARGET = send
-
-SRC = radio.c send.c serial.c
-OBJ = $(SRC:.c=.o)
-
-CFLAGS = -std=gnu99
-CFLAGS += -Os
-CFLAGS += -Wall
-CFLAGS += -mmcu=$(MCU)
-CFLAGS += -DBAUD=115200
-CFLAGS += -DF_CPU=16000000UL
-CFLAGS += -ffunction-sections -fdata-sections
-
-LDFLAGS = -mmcu=$(MCU)
-LDFLAGS += -Wl,--gc-sections
-
-HEX_FLAGS = -O ihex
-HEX_FLAGS += -j .text -j .data
-
-AVRDUDE_FLAGS = -p $(MCU)
-AVRDUDE_FLAGS += -c arduino
-AVRDUDE_FLAGS += -P /dev/cuaU0
-AVRDUDE_FLAGS += -D -U
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-elf: $(OBJ)
- $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf
-
-hex: elf
- avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex
-
-upload: hex
- avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i
-
-.PHONY: clean
-
-clean:
- rm *.o *.elf *.hex
-
-
diff --git a/nRF24L01/radio.c b/nRF24L01/radio.c
deleted file mode 100644
index c26e5f7..0000000
--- a/nRF24L01/radio.c
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <stdlib.h>
-
-#include <avr/io.h>
-#include <util/delay.h>
-
-#include "radio.h"
-#include "serial.h"
-
-#define SPI_SS PB2
-#define SPI_SCK PB5
-#define SPI_MISO PB4
-#define SPI_MOSI PB3
-#define SPI_DDR DDRB
-#define SPI_PORT PORTB
-
-#define NRF24L01_CE PB0
-#define NRF24L01_CE_DDR DDRB
-#define NRF24L01_CE_PORT DDRB
-
-#define NRF24L01_POWER_ON_RST_DELAY 100
-
-#define NRF24L01_REG_CONFIG 0x00
-#define NRF24L01_REG_EN_AA 0x01
-#define NRF24L01_REG_EN_RXADDR 0x02
-#define NRF24L01_REG_SETUP_AW 0x03
-#define NRF24L01_REG_SETUP_RETR 0x04
-#define NRF24L01_REG_RF_CH 0x05
-#define NRF24L01_REG_RF_SETUP 0x06
-#define NRF24L01_REG_STATUS 0x07
-#define NRF24L01_REG_OBSERVE_TX 0x08
-#define NRF24L01_REG_RPD 0x09
-#define NRF24L01_REG_RX_ADDR_P0 0x0A
-#define NRF24L01_REG_RX_ADDR_P1 0x0B
-#define NRF24L01_REG_RX_ADDR_P2 0x0C
-#define NRF24L01_REG_RX_ADDR_P3 0x0D
-#define NRF24L01_REG_RX_ADDR_P4 0x0E
-#define NRF24L01_REG_RX_ADDR_P5 0x0F
-#define NRF24L01_REG_TX_ADDR 0x10
-#define NRF24L01_REG_RX_PW_P0 0x11
-#define NRF24L01_REG_RX_PW_P1 0x12
-#define NRF24L01_REG_RX_PW_P2 0x13
-#define NRF24L01_REG_RX_PW_P3 0x14
-#define NRF24L01_REG_RX_PW_P4 0x15
-#define NRF24L01_REG_RX_PW_P5 0x16
-#define NRF24L01_REG_FIFO_STATUS 0x17
-#define NRF24L01_REG_DYNPD 0x1C
-#define NRF24L01_REG_FEATURE 0x1D
-
-#define NRF24L01_NOP 0xFF
-#define NRF24L01_R_REGISTER 0x00
-#define NRF24L01_W_REGISTER 0x20
-#define NRF24L01_R_RX_PAYLOAD 0x60
-#define NRF24L01_W_TX_PAYLOAD 0xA0
-#define NRF24L01_FLUSH_TX 0xE1
-#define NRF24L01_FLUSH_RX 0xE2
-
-#define NRF24L01_MASK_RX_DR 6
-#define NRF24L01_MASK_TX_DS 5
-#define NRF24L01_MASK_MAX_RT 4
-#define NRF24L01_PWR_UP 1
-#define NRF24L01_PRIM_RX 0
-#define NRF24L01_ERX_P1 1
-#define NRF24L01_ERX_P0 0
-
-static inline uint8_t read_reg(uint8_t reg)
-{
- SPI_PORT &= ~(1 << SPI_SS);
- SPDR = NRF24L01_R_REGISTER | reg;
- while (!(SPSR & (1 << SPIF)))
- ;
- SPDR = 0;
- while (!(SPSR & (1 << SPIF)))
- ;
- SPI_PORT |= (1 << SPI_SS);
- return SPDR;
-}
-
-static inline void write_reg(uint8_t reg, uint8_t val)
-{
- SPI_PORT &= ~(1 << SPI_SS);
- SPDR = NRF24L01_W_REGISTER | reg;
- while (!(SPSR & (1 << SPIF)))
- ;
- SPDR = val;
- while (!(SPSR & (1 << SPIF)))
- ;
- SPI_PORT |= (1 << SPI_SS);
-}
-
-void radio_send(const char *data, uint8_t n)
-{
-}
-
-uint8_t radio_recv(char *buf, uint8_t n)
-{
-}
-
-void radio_listen(void)
-{
-}
-
-void radio_init(const struct radio_cfg *cfg)
-{
- uint8_t conf;
-
- SPI_DDR |= (1 << SPI_SS) | (1 << SPI_SCK) | (1 << SPI_MOSI);
- SPI_PORT |= (1 << SPI_SS);
- SPCR |= (1 << SPE) | (1 << MSTR);
-
- NRF24L01_CE_DDR |= (1 << NRF24L01_CE);
- NRF24L01_CE_PORT &= ~(1 << NRF24L01_CE);
-
- _delay_ms(NRF24L01_POWER_ON_RST_DELAY);
-
- // disable IRQs, set CRC encoding scheme to 2 bytes
- conf = 0;
- conf |= (1 << NRF24L01_MASK_RX_DR);
- conf |= (1 << NRF24L01_MASK_TX_DS);
- conf |= (1 << NRF24L01_MASK_MAX_RT);
- conf |= (1 << NRF24L01_CRCO);
- write_reg(NRF24L01_REG_CONFIG, conf);
-
- // only use data pipe 0
- conf = 0;
- conf &= ~(1 << NRF24L01_ERX_P1);
- conf |= (1 << NRF24L01_ERX_P0);
- write_reg(NRF24L01_REG_EN_RXADDR, conf);
-
- // set address width to 3 bytes
- write_reg(NRF24L01_REG_SETUP_AW, 0x01);
-
-
-}
diff --git a/nRF24L01/radio.h b/nRF24L01/radio.h
deleted file mode 100644
index a44d67e..0000000
--- a/nRF24L01/radio.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef RADIO_H
-#define RADIO_H
-
-#include <stdint.h>
-
-struct radio_cfg {
- uint8_t netid;
- uint8_t nodeid;
-};
-
-void radio_init(const struct radio_cfg *cfg);
-
-void radio_listen(void);
-
-void radio_send(const char *data, uint8_t n);
-
-uint8_t radio_recv(char *buf, uint8_t n);
-
-#endif
diff --git a/nRF24L01/recv.c b/nRF24L01/recv.c
deleted file mode 100644
index 1c6ac0f..0000000
--- a/nRF24L01/recv.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#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();
-}
diff --git a/nRF24L01/send.c b/nRF24L01/send.c
deleted file mode 100644
index b390cf3..0000000
--- a/nRF24L01/send.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-
-#include "radio.h"
-#include "serial.h"
-
-int main(void)
-{
- uint8_t n;
- struct radio_cfg cfg;
- const char *s = "hello, world!";
-
- n = strlen(s);
-
- cfg.netid = 0x01;
- cfg.nodeid = 0x02;
- cfg.payload_len = n;
-
- serial_init();
- radio_init(&cfg);
- radio_set_tx_power(18);
-
- for (;;) {
- radio_send(s, n);
- serial_write_line("sent");
- _delay_ms(1500);
- }
-
- return 0;
-}
diff --git a/nRF24L01/serial.c b/nRF24L01/serial.c
deleted file mode 100644
index 782e848..0000000
--- a/nRF24L01/serial.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <avr/io.h>
-#include <util/setbaud.h>
-
-#include "serial.h"
-
-void serial_init(void)
-{
- UBRR0H = UBRRH_VALUE;
- UBRR0L = UBRRL_VALUE;
-#if USE_2X
- UCSR0A |= (1 << U2X0);
-#else
- UCSR0A &= ~(1 << U2X0);
-#endif
- UCSR0B = (1 << TXEN0) | (1 << RXEN0);
- UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
-}
-
-void serial_write(char data)
-{
- while (!(UCSR0A & (1 << UDRE0)))
- ;
- UDR0 = data;
-}
-
-void serial_write_line(const char *s)
-{
- for (; *s; s++)
- serial_write(*s);
-
- serial_write('\r');
- serial_write('\n');
-}
diff --git a/nRF24L01/serial.h b/nRF24L01/serial.h
deleted file mode 100644
index 0f9415b..0000000
--- a/nRF24L01/serial.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef SA_SERIAL_H
-#define SA_SERIAL_H
-
-void serial_init(void);
-void serial_write(char data);
-void serial_write_line(const char *s);
-
-#endif /* SA_SERIAL_H */