/* 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