extern void nRF24L01_interrupt () { uint8_t status; // If still in transmitting mode then finish transmission PORTD ^= 1<<0; //toggle bit if (PTX) { // Read nRF24L01 status nRF24L01_CSN_lo; // Pull down chip select status = spi_transmit_byte(NOP); // Read status register nRF24L01_CSN_hi; // Pull up chip select nRF24L01_CSN_lo; // Pull down chip select spi_transmit_byte( FLUSH_TX ); // Write cmd to flush tx fifo nRF24L01_CSN_hi; // Pull up chip select nRF24L01_CE_lo; // Deactivate transreceiver RX_POWERUP; // Power up in receiving mode nRF24L01_CE_hi; // Listening for pakets PTX = 0; // Set to receiving mode // Reset status register for further interaction nRF24L01_config_register(STATUS,(1<<TX_DS)|(1<<MAX_RT)); // Reset status register } }
extern void nRF24L01_interrupt () { // Read nRF24L01 status uint8_t status; nRF24L01_CSN_lo; // Pull down chip select status = spi_transmit_byte(NOP); // Read status register nRF24L01_CSN_hi; // Pull up chip select //based upon the status register decide what to do //if TX sucess if ( status & (1<<TX_DS) ) { nRF24L01_powerdown(); // Return to low power state } //maximum retrys reached else if ( status & (1<<MAX_RT) ) { //set some flag nRF24L01_powerdown(); // Return to low power state } //recieved a packet else if ( status & (1<<RX_DR) ) { nRF24L01_get_data(buffer); nRF24L01_powerdown(); } // Reset status register for further interaction nRF24L01_config_register(STATUS,( (1<<RX_DR) | (1<<TX_DS) | (1<<MAX_RT) ) ); // Reset status register }
void nRF24L01_config() // Sets the important registers in the nRF24L01 module and powers the module // in receiving mode { // Set RF channel nRF24L01_config_register(RF_CH,nRF24L01_CH); // Set length of incoming payload nRF24L01_config_register(RX_PW_P0, nRF24L01_PAYLOAD); // Reset status register nRF24L01_config_register(STATUS,((1<<TX_DS)|(1<<MAX_RT))); // Start receiver PTX = 0; // Start in receiving mode RX_POWERUP; // Power up in receiving mode nRF24L01_CE_hi; // Listening for pakets }
void nRF24L01_config() // Sets the important registers in the nRF24L01 module and powers the module // in receiving mode { // Set RF channel nRF24L01_config_register(RF_CH,nRF24L01_CH); // Set length of incoming payload nRF24L01_config_register(RX_PW_P0, nRF24L01_PAYLOAD); //configure 1Mbps uint8_t nRF24L01_PWR_RATE = ( (0<<LNA_HCURR) | (00<RF_PWR) | (0<<RF_DR)); // 18dbm & 1Mbps nRF24L01_write_register(RF_SETUP, &nRF24L01_PWR_RATE,1); // Reset status register nRF24L01_config_register(STATUS,((1<<TX_DS)|(1<<MAX_RT))); // Start receiver //PTX = 0; // Start in receiving mode RX_POWERUP; // Power up in receiving mode nRF24L01_CE_hi; // Listening for pakets //nRF24L01_CE_lo; }
extern void nRF24L01_get_data(uint8_t * data) // Reads nRF24L01_PAYLOAD bytes into data array { nRF24L01_CSN_lo; // Pull down chip select nRF24L01_CE_lo; spi_transmit_byte( R_RX_PAYLOAD ); // Send cmd to read rx payload spi_transfer_array(data,data,nRF24L01_PAYLOAD); // Read payload nRF24L01_CSN_hi; // Pull up chip select nRF24L01_config_register(STATUS,(1<<RX_DR)); // Reset status register nRF24L01_CE_hi; //Clear the TX FIFO nRF24L01_CSN_lo; // Pull down chip select spi_transmit_byte( FLUSH_TX ); // Write cmd to flush tx fifo nRF24L01_CSN_hi; // Pull up chip select }