diff --git a/Rmodule/Rmodule.aps b/Rmodule/Rmodule.aps
index 669788f..3e88755 100755
--- a/Rmodule/Rmodule.aps
+++ b/Rmodule/Rmodule.aps
@@ -1 +1 @@
-Rmodule14-Nov-2013 11:48:5709-Dec-2013 21:08:58241014-Nov-2013 11:48:5744, 19, 0, 730AVR GCCdefault\Rmodule.elfc:\Hard\Git\Rmodule\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cC:\Hard\Git\Rmodule\nrf24l01\radioPinFunctions.cC:\Hard\Git\Rmodule\nrf24l01\nrf24.cC:\Hard\Git\Rmodule\nrf24l01\nRF24L01.hC:\Hard\Git\Rmodule\nrf24l01\nrf24.hdefault\Rmodule.lssdefault\Rmodule.mapdefaultNOatmega811
Rmodule.elfdefault\1-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exeC:\Hard\Git\Rmodule\nrf24l01\nRF24L01.hC:\Hard\Git\Rmodule\nrf24l01\nrf24.hc:\Hard\Git\Rmodule\main.cC:\Hard\Git\Rmodule\nrf24l01\radioPinFunctions.cC:\Hard\Git\Rmodule\nrf24l01\nrf24.c00000main.c1
+Rmodule14-Nov-2013 11:48:5711-Dec-2013 13:32:48241014-Nov-2013 11:48:5744, 19, 0, 730AVR GCCdefault\Rmodule.elfc:\Hard\Git\Rmodule\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cC:\Hard\Git\Rmodule\onewire\onewire.cC:\Hard\Git\Rmodule\onewire\crc8.cC:\Hard\Git\Rmodule\nrf24l01\nrf24l01.cC:\Hard\Git\Rmodule\spi\spi.cC:\Hard\Git\Rmodule\onewire\crc8.hC:\Hard\Git\Rmodule\onewire\onewire.hC:\Hard\Git\Rmodule\nrf24l01\nrf24l01registers.hC:\Hard\Git\Rmodule\nrf24l01\nrf24l01.hC:\Hard\Git\Rmodule\spi\spi.hdefault\Rmodule.lssdefault\Rmodule.mapdefaultNOatmega811
Rmodule.elfdefault\1-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exe00000main.c100001nrf24l01\nrf24l01.c100002nrf24l01\nrf24l01.h1
diff --git a/Rmodule/default/Makefile b/Rmodule/default/Makefile
index 8b056c5..543ed81 100755
--- a/Rmodule/default/Makefile
+++ b/Rmodule/default/Makefile
@@ -37,7 +37,7 @@ HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
-OBJECTS = main.o radioPinFunctions.o nrf24.o
+OBJECTS = main.o onewire.o crc8.o nrf24l01.o spi.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
@@ -49,10 +49,16 @@ all: $(TARGET) Rmodule.hex Rmodule.eep Rmodule.lss size
main.o: ../main.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
-radioPinFunctions.o: ../nrf24l01/radioPinFunctions.c
+onewire.o: ../onewire/onewire.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
-nrf24.o: ../nrf24l01/nrf24.c
+crc8.o: ../onewire/crc8.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+nrf24l01.o: ../nrf24l01/nrf24l01.c
+ $(CC) $(INCLUDES) $(CFLAGS) -c $<
+
+spi.o: ../spi/spi.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
##Link
diff --git a/Rmodule/main.c b/Rmodule/main.c
index 47edfd3..b97b064 100755
--- a/Rmodule/main.c
+++ b/Rmodule/main.c
@@ -2,47 +2,76 @@
#include
#include
+#include
#include
#include
-#include "nrf24l01/nrf24.h"
+#include
+#include "nrf24l01/nrf24l01.h"
+#include "onewire/onewire.h"
-typedef struct data_arr{
- uint8_t buffer[32];
-}data_array;
+typedef struct t_data{
+ uint8_t from;
+ uint8_t to;
+ char cmd[5];
+ uint8_t value[25];
+}t_data;
+uint8_t* address_at_eeprom_location = (uint8_t*)0;
+
+uint8_t getid(void){
+ uint8_t result = 0;
+ if ( eeprom_read_byte(address_at_eeprom_location) == 0xdf ){
+ result = eeprom_read_byte(address_at_eeprom_location+1);
+ }else{
+ result =0x00;
+ }
+ return result;
+}
+
+void getListDevices(t_data data){
+ uint8_t i;
+ uint8_t id[OW_ROMCODE_SIZE];
+ uint8_t diff;
+
+ ow_reset();
+ diff = OW_SEARCH_FIRST;
+ while ( diff != OW_LAST_DEVICE) {
+ diff = ow_rom_search( diff, &id[0] );
+ if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR) {
+ for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
+ data.value[i] = id[i];
+ }
+ data.value[OW_ROMCODE_SIZE] = 0x00;
+ }
+ if (nrf24l01_write((uint8_t*) &data)){
+ }
+ }
+}
+
+uint8_t mac[NRF24L01_ADDRSIZE] = {0xF0, 0xF0, 0xF0, 0xF0, 0xF0};
-uint8_t tx_mac[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
-uint8_t rx_mac[5] = {0xD7,0xD7,0xD7,0xD7,0xD7};
-
int main(void){
-
- /* initializes hardware pins */
- nrf24_init();
-
- /* RF channel: #2 , payload length: 4 */
- nrf24_config(2,32);
-
- /* Set the module's own address */
- nrf24_rx_address(rx_mac);
-
- /* Set the transmit address */
- nrf24_tx_address(tx_mac);
-
+
+ uint8_t id = getid();
+ nrf24l01_init();
sei();
- data_array buff;
+ nrf24l01_setrxaddr(0, mac);
+ mac[4] = 0xF0 & ( 0x0F & id);
+ nrf24l01_settxaddr(mac);
+
+ t_data data;
while(1){
- if(nrf24_dataReady()){
- nrf24_getData((uint8_t *) &buff);
- nrf24_send((uint8_t*) &buff);
- /* Wait for transmission to end */
- while(nrf24_isSending());
- /* Optionally, go back to RX mode ... */
- nrf24_powerUpRx();
-
- /* Wait a little ... */
- _delay_ms(10);
+ if(nrf24l01_readready(&id)){
+ nrf24l01_read((uint8_t*) &data);
+ if (data.to==id && data.from==0x00){ // åñëè ýòî íàì è îò ñåðâåðà
+ if (strcmp(data.cmd, "ld")==0){ // êîìàíäà îïðîñà øèíû
+ data.from = id;
+ data.to = 0x00;
+ getListDevices(data);
+ }
+ }
}
}
}
diff --git a/Rmodule/nrf24l01/nRF24L01.h b/Rmodule/nrf24l01/nRF24L01.h
index 6ec69fe..7683866 100644
--- a/Rmodule/nrf24l01/nRF24L01.h
+++ b/Rmodule/nrf24l01/nRF24L01.h
@@ -1,130 +1,101 @@
/*
- Copyright (c) 2007 Stefan Engelke
+nrf24l01 lib 0x02
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use, copy,
- modify, merge, publish, distribute, sublicense, and/or sell copies
- of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
+copyright (c) Davide Gironi, 2012
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
+References:
+ - This library is based upon nRF24L01 avr lib by Stefan Engelke
+ http://www.tinkerer.eu/AVRLib/nRF24L01
+ - and arduino library 2011 by J. Coliz
+ http://maniacbug.github.com/RF24
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
-
- $Id$
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
*/
-/* Memory Map */
-#define CONFIG 0x00
-#define EN_AA 0x01
-#define EN_RXADDR 0x02
-#define SETUP_AW 0x03
-#define SETUP_RETR 0x04
-#define RF_CH 0x05
-#define RF_SETUP 0x06
-#define STATUS 0x07
-#define OBSERVE_TX 0x08
-#define CD 0x09
-#define RX_ADDR_P0 0x0A
-#define RX_ADDR_P1 0x0B
-#define RX_ADDR_P2 0x0C
-#define RX_ADDR_P3 0x0D
-#define RX_ADDR_P4 0x0E
-#define RX_ADDR_P5 0x0F
-#define TX_ADDR 0x10
-#define RX_PW_P0 0x11
-#define RX_PW_P1 0x12
-#define RX_PW_P2 0x13
-#define RX_PW_P3 0x14
-#define RX_PW_P4 0x15
-#define RX_PW_P5 0x16
-#define FIFO_STATUS 0x17
-#define DYNPD 0x1C
+#ifndef _NRF24L01_H_
+#define _NRF24L01_H_
-/* Bit Mnemonics */
+#include
-/* configuratio nregister */
-#define MASK_RX_DR 6
-#define MASK_TX_DS 5
-#define MASK_MAX_RT 4
-#define EN_CRC 3
-#define CRCO 2
-#define PWR_UP 1
-#define PRIM_RX 0
+//CE and CSN port definitions
+#define NRF24L01_DDR DDRB
+#define NRF24L01_PORT PORTB
+#define NRF24L01_CE PB0
+#define NRF24L01_CSN PB1
-/* enable auto acknowledgment */
-#define ENAA_P5 5
-#define ENAA_P4 4
-#define ENAA_P3 3
-#define ENAA_P2 2
-#define ENAA_P1 1
-#define ENAA_P0 0
+//define the spi path
+#define NRF24L01_SPIPATH "../spi/spi.h" //spi lib path
-/* enable rx addresses */
-#define ERX_P5 5
-#define ERX_P4 4
-#define ERX_P3 3
-#define ERX_P2 2
-#define ERX_P1 1
-#define ERX_P0 0
+//CE and CSN functions
+#define nrf24l01_CSNhi NRF24L01_PORT |= (1< wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* This library is based on this library:
-* https://github.com/aaronds/arduino-nrf24l01
-* Which is based on this library:
-* http://www.tinkerer.eu/AVRLib/nRF24L01
-* -----------------------------------------------------------------------------
-*/
-#include "nrf24.h"
-
-uint8_t payload_len;
-
-/* init the hardware pins */
-void nrf24_init()
-{
- nrf24_setupPins();
- nrf24_ce_digitalWrite(LOW);
- nrf24_csn_digitalWrite(HIGH);
-}
-
-/* configure the module */
-void nrf24_config(uint8_t channel, uint8_t pay_length)
-{
- /* Use static payload length ... */
- payload_len = pay_length;
-
- // Set RF channel
- nrf24_configRegister(RF_CH,channel);
-
- // Set length of incoming payload
- nrf24_configRegister(RX_PW_P0, 0x00); // Auto-ACK pipe ...
- nrf24_configRegister(RX_PW_P1, payload_len); // Data payload pipe
- nrf24_configRegister(RX_PW_P2, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P3, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P4, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P5, 0x00); // Pipe not used
-
- // 1 Mbps, TX gain: 0dbm
- nrf24_configRegister(RF_SETUP, (0< wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* This library is based on this library:
-* https://github.com/aaronds/arduino-nrf24l01
-* Which is based on this library:
-* http://www.tinkerer.eu/AVRLib/nRF24L01
-* -----------------------------------------------------------------------------
-*/
-#ifndef NRF24
-#define NRF24
-
-#include "nRF24L01.h"
-#include
-
-#define LOW 0
-#define HIGH 1
-
-#define nrf24_ADDR_LEN 5
-#define nrf24_CONFIG ((1< Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_ce_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 CE pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_csn_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 SCK pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_sck_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 MOSI pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_mosi_digitalWrite(uint8_t state);
-
-/* -----------------------------------------*/
-/* nrf24 MISO pin read function */
-/* - returns: Non-zero if the pin is high */
-/* -----------------------------------------*/
-extern uint8_t nrf24_miso_digitalRead();
-
-#endif
diff --git a/Rmodule/nrf24l01/nrf24l01.c b/Rmodule/nrf24l01/nrf24l01.c
new file mode 100644
index 0000000..3049547
--- /dev/null
+++ b/Rmodule/nrf24l01/nrf24l01.c
@@ -0,0 +1,433 @@
+/*
+nrf24l01 lib 0x02
+
+copyright (c) Davide Gironi, 2012
+
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
+*/
+
+
+#include
+#include
+#include
+#include
+#include
+
+#include "nrf24l01.h"
+#include "nrf24l01registers.h"
+
+//include spi library functions
+#include NRF24L01_SPIPATH
+
+//address variables
+static uint8_t nrf24l01_addr0[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP0;
+static uint8_t nrf24l01_addr1[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP1;
+static uint8_t nrf24l01_addr2[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP2;
+static uint8_t nrf24l01_addr3[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP3;
+static uint8_t nrf24l01_addr4[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP4;
+static uint8_t nrf24l01_addr5[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP5;
+static uint8_t nrf24l01_addrtx[NRF24L01_ADDRSIZE] = NRF24L01_ADDRTX;
+
+/*
+ * read one register
+ */
+uint8_t nrf24l01_readregister(uint8_t reg) {
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_REGISTER | (NRF24L01_CMD_REGISTER_MASK & reg));
+ uint8_t result = spi_writereadbyte(NRF24L01_CMD_NOP); //read write register
+ nrf24l01_CSNhi; //high CSN
+ return result;
+}
+
+/*
+ * read many registers
+ */
+void nrf24l01_readregisters(uint8_t reg, uint8_t *value, uint8_t len) {
+ uint8_t i = 0;
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_REGISTER | (NRF24L01_CMD_REGISTER_MASK & reg));
+ for(i=0; i> NRF24L01_REG_RX_P_NO) & 0b111;
+ }
+ return ret;
+}
+
+/*
+ * get data
+ */
+void nrf24l01_read(uint8_t *data) {
+ uint8_t i = 0;
+ //read rx register
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_RX_PAYLOAD);
+ for(i=0; i wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* Please define your platform spesific functions in this file ...
-* -----------------------------------------------------------------------------
-*/
-
-#include
-
-#define set_bit(reg,bit) reg |= (1<
+
diff --git a/Rmodule/spi/spi.c b/Rmodule/spi/spi.c
new file mode 100644
index 0000000..8611f16
--- /dev/null
+++ b/Rmodule/spi/spi.c
@@ -0,0 +1,43 @@
+/*
+spi lib 0x01
+
+copyright (c) Davide Gironi, 2012
+
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
+*/
+
+#include "spi.h"
+
+#include
+#include
+
+
+/*
+ * spi initialize
+ */
+void spi_init() {
+ SPI_DDR &= ~((1<
+
+//spi ports
+#define SPI_DDR DDRB
+#define SPI_PORT PORTB
+#define SPI_MISO PB4
+#define SPI_MOSI PB3
+#define SPI_SCK PB5
+#define SPI_SS PB2
+
+extern void spi_init();
+extern uint8_t spi_writereadbyte(uint8_t data);
+
+#endif
diff --git a/Smodule/Smodule.aps b/Smodule/Smodule.aps
index 2b8ea54..9b1d8d1 100644
--- a/Smodule/Smodule.aps
+++ b/Smodule/Smodule.aps
@@ -1 +1 @@
-Smodule04-Dec-2013 09:22:0908-Dec-2013 13:26:42241004-Dec-2013 09:22:0944, 19, 0, 730AVR GCCdefault\Smodule.elfc:\Hard\Git\Smodule\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cuart\uart_addon.cuart\uart.cnrf24l01\nrf24.cnrf24l01\radioPinFunctions.cres\strings.huart\uart.huart\uart_addon.hnrf24l01\nrf24.hnrf24l01\nRF24L01.hdefault\Smodule.lssdefault\Smodule.mapdefaultNOatmega811
Smodule.elfdefault\1-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exec:\Hard\Git\Smodule\res\strings.hc:\Hard\Git\Smodule\uart\uart.hc:\Hard\Git\Smodule\uart\uart_addon.hc:\Hard\Git\Smodule\nrf24l01\nrf24.hc:\Hard\Git\Smodule\nrf24l01\nRF24L01.hc:\Hard\Git\Smodule\main.cc:\Hard\Git\Smodule\uart\uart_addon.cc:\Hard\Git\Smodule\uart\uart.cc:\Hard\Git\Smodule\nrf24l01\nrf24.cc:\Hard\Git\Smodule\nrf24l01\radioPinFunctions.c00000main.c100001res\strings.h1
+Smodule04-Dec-2013 09:22:0911-Dec-2013 13:32:45241004-Dec-2013 09:22:0944, 19, 0, 730AVR GCCdefault\Smodule.elfc:\Hard\Git\Smodule\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cuart\uart_addon.cuart\uart.cC:\Hard\Git\Smodule\spi\spi.cC:\Hard\Git\Smodule\nrf24l01\nrf24l01.cres\strings.huart\uart.huart\uart_addon.hC:\Hard\Git\Smodule\spi\spi.hC:\Hard\Git\Smodule\nrf24l01\nrf24l01registers.hC:\Hard\Git\Smodule\nrf24l01\nrf24l01.hdefault\Smodule.lssdefault\Smodule.mapdefaultNOatmega811
Smodule.elfdefault\1-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exeC:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exe00000main.c1
diff --git a/Smodule/default/Makefile b/Smodule/default/Makefile
index a994629..f2fdeed 100644
--- a/Smodule/default/Makefile
+++ b/Smodule/default/Makefile
@@ -37,7 +37,7 @@ HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
-OBJECTS = main.o uart_addon.o uart.o nrf24.o radioPinFunctions.o
+OBJECTS = main.o uart_addon.o uart.o spi.o nrf24l01.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
@@ -55,10 +55,10 @@ uart_addon.o: ../uart/uart_addon.c
uart.o: ../uart/uart.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
-nrf24.o: ../nrf24l01/nrf24.c
+spi.o: ../spi/spi.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
-radioPinFunctions.o: ../nrf24l01/radioPinFunctions.c
+nrf24l01.o: ../nrf24l01/nrf24l01.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
##Link
diff --git a/Smodule/main.c b/Smodule/main.c
index 778aecc..0c8b0b0 100644
--- a/Smodule/main.c
+++ b/Smodule/main.c
@@ -1,16 +1,24 @@
-// Ïðîøèâêà äëÿ óäàëåííîãî ðàäèîìîäóëÿ
+// Ïðîøèâêà äëÿ ñåðâåðíîãî ðàäèîìîäóëÿ
#include
#include
+#include
#include
#include
#include "uart/uart.h"
#include "uart/uart_addon.h"
#include "res/strings.h"
-#include "nrf24l01/nrf24.h"
+#include "nrf24l01/nrf24l01.h"
#define UART_BAUD_RATE 9600
+typedef struct t_data{
+ uint8_t from;
+ uint8_t to;
+ char cmd[5];
+ uint8_t value[25];
+}t_data;
+
unsigned char get_uart_char(void){
unsigned int res;
do{
@@ -19,8 +27,8 @@ unsigned char get_uart_char(void){
return (unsigned char) res;
}
-static int get_uart_line(char *pbuf, int len_ln){
- int i = 0;
+static uint8_t get_uart_line(char *pbuf, uint8_t len_ln){
+ uint8_t i = 0;
unsigned char c;
len_ln=len_ln-1;
@@ -33,77 +41,44 @@ static int get_uart_line(char *pbuf, int len_ln){
return i;
}
-typedef struct data_arr{
- uint8_t buffer[32];
-}data_array;
-
-
-uint8_t rx_mac[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
-uint8_t tx_mac[5] = {0xD7,0xD7,0xD7,0xD7,0xD7};
-uint8_t temp;
+uint8_t mac[NRF24L01_ADDRSIZE] = {0xF0, 0xF0, 0xF0, 0xF0, 0xF0};
int main(void){
- uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
+ t_data data;
+ uint8_t i;
+
+ uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
+ nrf24l01_init();
- /* initializes hardware pins */
- nrf24_init();
-
- /* RF channel: #2 , payload length: 4 */
- nrf24_config(2,32);
-
- /* Set the module's own address */
- nrf24_rx_address(rx_mac);
-
- /* Set the transmit address */
- nrf24_tx_address(tx_mac);
-
sei();
- data_array buff;
- char cmd[5];
- uint8_t i;
- unsigned int len_line=0;
+ nrf24l01_settxaddr(mac);
+ for (i=1; i<6; i++){
+ mac[4] = 0xF0 & ( 0x0F & i);
+ nrf24l01_setrxaddr(i, mac);
+ }
uart_puts_p(CmdPrompt);
while(1){
if (!(UCSRA & (1 << RXC))){
- len_line=get_uart_line(&cmd[0],sizeof(cmd));
- if (len_line>0){
- if (strcmp(cmd, CmdLD)==0){
- /* Automatically goes to TX mode */
- nrf24_send((uint8_t*) &cmd);
-
- /* Wait for transmission to end */
- while(nrf24_isSending());
+ i=get_uart_line(&data.cmd[0],sizeof(data.cmd));
+ if (i>0){
+ data.from = 0;
+ data.to = 0xFF;
+ if (strcmp(data.cmd, CmdLD)==0){
+
+ i = nrf24l01_write((uint8_t*) &data);
- /* Make analysis on last tranmission attempt */
- temp = nrf24_lastMessageStatus();
-
- if(temp == NRF24_TRANSMISSON_OK){
+ if(i == 1){
uart_puts_p(TransOK);
- }else if(temp == NRF24_MESSAGE_LOST){
+ }else{
uart_puts_p(TransLost);
}
-
- /* Retranmission count indicates the tranmission quality */
- temp = nrf24_retransmissionCount();
- uart_puts_p(ReTransCnt);
- uart_put_int(temp);
-
uart_puts_p(CmdPrompt);
-
- /* Optionally, go back to RX mode ... */
- nrf24_powerUpRx();
-
- /* Or you might want to power down after TX */
- // nrf24_powerDown();
-
- /* Wait a little ... */
- _delay_ms(10);
}
- if (strcmp(cmd, CmdHelp)==0){
+ if (strcmp(data.cmd, CmdHelp)==0){
uart_puts_p(HelpTitle);
uart_puts_p(HelpItem1);
uart_puts_p(HelpItem2);
@@ -111,10 +86,16 @@ int main(void){
}
}
}
- if(nrf24_dataReady()){
- nrf24_getData((uint8_t *) &buff);
- for ( i=0; i < sizeof(buff.buffer); i++ ){
- uart_puthex_byte(buff.buffer[i]);
+ if(nrf24l01_readready(0)){
+ nrf24l01_read((uint8_t*) &data);
+ uart_puts(data.cmd);
+ uart_putc('-');
+ uart_puthex_byte(data.from);
+ uart_putc('>');
+ uart_puthex_byte(data.to);
+ uart_putc(':');
+ for ( i=0; i < sizeof(data.value); i++ ){
+ uart_puthex_byte(data.value[i]);
uart_putc(' ');
}
uart_puts(CRLF);
diff --git a/Smodule/nrf24l01/nRF24L01.h b/Smodule/nrf24l01/nRF24L01.h
index 6ec69fe..7683866 100644
--- a/Smodule/nrf24l01/nRF24L01.h
+++ b/Smodule/nrf24l01/nRF24L01.h
@@ -1,130 +1,101 @@
/*
- Copyright (c) 2007 Stefan Engelke
+nrf24l01 lib 0x02
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use, copy,
- modify, merge, publish, distribute, sublicense, and/or sell copies
- of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
+copyright (c) Davide Gironi, 2012
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
+References:
+ - This library is based upon nRF24L01 avr lib by Stefan Engelke
+ http://www.tinkerer.eu/AVRLib/nRF24L01
+ - and arduino library 2011 by J. Coliz
+ http://maniacbug.github.com/RF24
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
-
- $Id$
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
*/
-/* Memory Map */
-#define CONFIG 0x00
-#define EN_AA 0x01
-#define EN_RXADDR 0x02
-#define SETUP_AW 0x03
-#define SETUP_RETR 0x04
-#define RF_CH 0x05
-#define RF_SETUP 0x06
-#define STATUS 0x07
-#define OBSERVE_TX 0x08
-#define CD 0x09
-#define RX_ADDR_P0 0x0A
-#define RX_ADDR_P1 0x0B
-#define RX_ADDR_P2 0x0C
-#define RX_ADDR_P3 0x0D
-#define RX_ADDR_P4 0x0E
-#define RX_ADDR_P5 0x0F
-#define TX_ADDR 0x10
-#define RX_PW_P0 0x11
-#define RX_PW_P1 0x12
-#define RX_PW_P2 0x13
-#define RX_PW_P3 0x14
-#define RX_PW_P4 0x15
-#define RX_PW_P5 0x16
-#define FIFO_STATUS 0x17
-#define DYNPD 0x1C
+#ifndef _NRF24L01_H_
+#define _NRF24L01_H_
-/* Bit Mnemonics */
+#include
-/* configuratio nregister */
-#define MASK_RX_DR 6
-#define MASK_TX_DS 5
-#define MASK_MAX_RT 4
-#define EN_CRC 3
-#define CRCO 2
-#define PWR_UP 1
-#define PRIM_RX 0
+//CE and CSN port definitions
+#define NRF24L01_DDR DDRB
+#define NRF24L01_PORT PORTB
+#define NRF24L01_CE PB0
+#define NRF24L01_CSN PB1
-/* enable auto acknowledgment */
-#define ENAA_P5 5
-#define ENAA_P4 4
-#define ENAA_P3 3
-#define ENAA_P2 2
-#define ENAA_P1 1
-#define ENAA_P0 0
+//define the spi path
+#define NRF24L01_SPIPATH "../spi/spi.h" //spi lib path
-/* enable rx addresses */
-#define ERX_P5 5
-#define ERX_P4 4
-#define ERX_P3 3
-#define ERX_P2 2
-#define ERX_P1 1
-#define ERX_P0 0
+//CE and CSN functions
+#define nrf24l01_CSNhi NRF24L01_PORT |= (1< wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* This library is based on this library:
-* https://github.com/aaronds/arduino-nrf24l01
-* Which is based on this library:
-* http://www.tinkerer.eu/AVRLib/nRF24L01
-* -----------------------------------------------------------------------------
-*/
-#include "nrf24.h"
-
-uint8_t payload_len;
-
-/* init the hardware pins */
-void nrf24_init()
-{
- nrf24_setupPins();
- nrf24_ce_digitalWrite(LOW);
- nrf24_csn_digitalWrite(HIGH);
-}
-
-/* configure the module */
-void nrf24_config(uint8_t channel, uint8_t pay_length)
-{
- /* Use static payload length ... */
- payload_len = pay_length;
-
- // Set RF channel
- nrf24_configRegister(RF_CH,channel);
-
- // Set length of incoming payload
- nrf24_configRegister(RX_PW_P0, 0x00); // Auto-ACK pipe ...
- nrf24_configRegister(RX_PW_P1, payload_len); // Data payload pipe
- nrf24_configRegister(RX_PW_P2, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P3, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P4, 0x00); // Pipe not used
- nrf24_configRegister(RX_PW_P5, 0x00); // Pipe not used
-
- // 1 Mbps, TX gain: 0dbm
- nrf24_configRegister(RF_SETUP, (0< wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* This library is based on this library:
-* https://github.com/aaronds/arduino-nrf24l01
-* Which is based on this library:
-* http://www.tinkerer.eu/AVRLib/nRF24L01
-* -----------------------------------------------------------------------------
-*/
-#ifndef NRF24
-#define NRF24
-
-#include "nRF24L01.h"
-#include
-
-#define LOW 0
-#define HIGH 1
-
-#define nrf24_ADDR_LEN 5
-#define nrf24_CONFIG ((1< Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_ce_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 CE pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_csn_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 SCK pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_sck_digitalWrite(uint8_t state);
-
-/* -------------------------------------------------------------------------- */
-/* nrf24 MOSI pin control function
- * - state:1 => Pin HIGH
- * - state:0 => Pin LOW */
-/* -------------------------------------------------------------------------- */
-extern void nrf24_mosi_digitalWrite(uint8_t state);
-
-/* -----------------------------------------*/
-/* nrf24 MISO pin read function */
-/* - returns: Non-zero if the pin is high */
-/* -----------------------------------------*/
-extern uint8_t nrf24_miso_digitalRead();
-
-#endif
diff --git a/Smodule/nrf24l01/nrf24l01.c b/Smodule/nrf24l01/nrf24l01.c
new file mode 100644
index 0000000..3049547
--- /dev/null
+++ b/Smodule/nrf24l01/nrf24l01.c
@@ -0,0 +1,433 @@
+/*
+nrf24l01 lib 0x02
+
+copyright (c) Davide Gironi, 2012
+
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
+*/
+
+
+#include
+#include
+#include
+#include
+#include
+
+#include "nrf24l01.h"
+#include "nrf24l01registers.h"
+
+//include spi library functions
+#include NRF24L01_SPIPATH
+
+//address variables
+static uint8_t nrf24l01_addr0[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP0;
+static uint8_t nrf24l01_addr1[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP1;
+static uint8_t nrf24l01_addr2[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP2;
+static uint8_t nrf24l01_addr3[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP3;
+static uint8_t nrf24l01_addr4[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP4;
+static uint8_t nrf24l01_addr5[NRF24L01_ADDRSIZE] = NRF24L01_ADDRP5;
+static uint8_t nrf24l01_addrtx[NRF24L01_ADDRSIZE] = NRF24L01_ADDRTX;
+
+/*
+ * read one register
+ */
+uint8_t nrf24l01_readregister(uint8_t reg) {
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_REGISTER | (NRF24L01_CMD_REGISTER_MASK & reg));
+ uint8_t result = spi_writereadbyte(NRF24L01_CMD_NOP); //read write register
+ nrf24l01_CSNhi; //high CSN
+ return result;
+}
+
+/*
+ * read many registers
+ */
+void nrf24l01_readregisters(uint8_t reg, uint8_t *value, uint8_t len) {
+ uint8_t i = 0;
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_REGISTER | (NRF24L01_CMD_REGISTER_MASK & reg));
+ for(i=0; i> NRF24L01_REG_RX_P_NO) & 0b111;
+ }
+ return ret;
+}
+
+/*
+ * get data
+ */
+void nrf24l01_read(uint8_t *data) {
+ uint8_t i = 0;
+ //read rx register
+ nrf24l01_CSNlo; //low CSN
+ spi_writereadbyte(NRF24L01_CMD_R_RX_PAYLOAD);
+ for(i=0; i wrote this file. As long as you retain this notice you
-* can do whatever you want with this stuff. If we meet some day, and you think
-* this stuff is worth it, you can buy me a coffee in return.
-* -----------------------------------------------------------------------------
-* Please define your platform spesific functions in this file ...
-* -----------------------------------------------------------------------------
-*/
-
-#include
-
-#define set_bit(reg,bit) reg |= (1<
+
diff --git a/Smodule/spi/spi.c b/Smodule/spi/spi.c
new file mode 100644
index 0000000..8611f16
--- /dev/null
+++ b/Smodule/spi/spi.c
@@ -0,0 +1,43 @@
+/*
+spi lib 0x01
+
+copyright (c) Davide Gironi, 2012
+
+Released under GPLv3.
+Please refer to LICENSE file for licensing information.
+*/
+
+#include "spi.h"
+
+#include
+#include
+
+
+/*
+ * spi initialize
+ */
+void spi_init() {
+ SPI_DDR &= ~((1<
+
+//spi ports
+#define SPI_DDR DDRB
+#define SPI_PORT PORTB
+#define SPI_MISO PB4
+#define SPI_MOSI PB3
+#define SPI_SCK PB5
+#define SPI_SS PB2
+
+extern void spi_init();
+extern uint8_t spi_writereadbyte(uint8_t data);
+
+#endif
diff --git a/boot/boot.aps b/boot/boot.aps
index 1c6ccec..37fe4ab 100755
--- a/boot/boot.aps
+++ b/boot/boot.aps
@@ -1 +1 @@
-boot12-Nov-2013 16:48:0108-Dec-2013 20:52:26241012-Nov-2013 16:48:0144, 19, 0, 730AVR GCCc:\Hard\Git\boot\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cmakefiledefaultYESC:\Hard\boot\makefileatmega811
boot.elfdefault\0-Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault0C:\WinAVR\bin\avr-gcc.exeC:\WinAVR\utils\bin\make.exec:\Hard\Git\boot\main.c00000main.c1
+boot12-Nov-2013 16:48:0109-Dec-2013 21:15:24241012-Nov-2013 16:48:0144, 19, 0, 730AVR GCCc:\Hard\Git\boot\AVR SimulatorATmega8.xmlfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto000main.cmakefiledefaultYESC:\Hard\Git\boot\makefileatmega811
boot.elfdefault\0-Wall -gdwarf-2 -std=gnu99 -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault0C:\WinAVR\bin\avr-gcc.exeC:\WinAVR\utils\bin\make.exe00000main.c1
diff --git a/boot/boot.aws b/boot/boot.aws
index 3567b1d..a04e65b 100755
--- a/boot/boot.aws
+++ b/boot/boot.aws
@@ -1 +1 @@
-
+