This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF24L01+ doesn't communicate after first burst

I have a transmitter that sends 24 bytes of data every 10 ms. Whenever I run the receiver I only get new data once, then nothing. Here's my code

void mirf_config() 
{
    uint8_t initial_config = 0;
    // Set RF channel
    mirf_config_register(RF_CH, mirf_CH);

    //Set long-range 250k mode
    mirf_config_register(RF_SETUP, 0x27);

    //Disable auto-ACK
    //mirf_config_register(EN_AA, 0);

    // Set length of incoming payload: mirf_PAYLOAD = 24
   mirf_config_register(RX_PW_P0, mirf_PAYLOAD);
   mirf_config_register(RX_PW_P1, mirf_PAYLOAD);
   mirf_config_register(EN_RXADDR, 0x0F);

   // Start receiver 
   PTX = 0;        // Start in receiving mode
   initial_config =  mirf_CONFIG |  (1<<PWR_UP) | (1<<PRIM_RX) ;
   mirf_config_register(CONFIG, initial_config);
   RX_POWERUP;     // Power up in receiving mode
   mirf_CE_hi;     // Listening for packets
}

void mirf_init(){
// Initializes pins ans interrupt to communicate with the MiRF module
// Should be called in the early initializing phase at startup.

// Define CSN and CE as Output and set them to default
//DDRB |= ((1<<CSN)|(1<<CE));
mirf_CE_lo;
mirf_CSN_hi;
// Initialize spi module
spi_init();
}

extern uint8_t mirf_data_ready() 
// Checks if data is available for reading
{
  if (PTX) return 0;
  uint8_t status;
  uint8_t fifo_status;
  // Read MiRF status 
  mirf_CSN_lo;                                // Pull down chip select
  status = spi_fast_shift(NOP);               // Read status register
  fifo_status = spi_fast_shift(FIFO_STATUS);
  mirf_CSN_hi;                                // Pull up chip select
  return status & (1<<RX_DR);
}

void mirf_read_register(uint8_t reg, uint8_t * value, uint8_t len)
// Reads an array of bytes from the given start position in the MiRF registers.
{
  mirf_CSN_lo;
  _delay_us(10);
  spi_fast_shift(R_REGISTER | (REGISTER_MASK & reg));
  _delay_us(10);
  spi_transfer_sync(value,value,len);
  _delay_us(10);
  mirf_CSN_hi;
  _delay_us(10);
}

extern void mirf_get_data(uint8_t * data) 
// Reads mirf_PAYLOAD bytes into data array
{
  mirf_CSN_lo;                               // Pull down chip select
  spi_fast_shift( R_RX_PAYLOAD );            // Send cmd to read rx payload
  spi_transfer_sync(data,data,mirf_PAYLOAD); // Read payload
  mirf_CSN_hi;                               // Pull up chip select
  mirf_config_register(STATUS,(1<<RX_DR));   // Reset status register
}

int main(void){
mirf_init();
_delay_ms(25);
mirf_config();
while(1){
  mirf_read_register(FIFO_STATUS,recvdata,1);

  if (t10mSecCtr)
  {
    recvdata[1] = mirf_data_ready();
    mirf_read_register(CONFIG,recvdata+2,1);
    //if (mirf_data_ready())
     if(!(recvdata[0] & 0x01) || mirf_data_ready())
     {
          mirf_get_data(recvdata);
    }
}

Any suggestions as to why it only receives the data once? At one point I changed the RF_SETUP register to 0x20 and it seemed to work, but it's not working any more. Thanks for your help!

Related