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

nrf24l01+ Tx status flag does not clear, Rx status flag always zero

Hi,

I'm using two STM32F407 discovery kits with one nrf24L01+ module attached to each kit.

Here is my common init code (common for both Tx and Rx):

RF_Init(); /* set CE and CSN to initialization value */

delay(100);
RF_WriteRegister(RF24_RF_SETUP, RF24_RF_SETUP_RF_PWR_0|RF24_RF_SETUP_RF_DR_250);
delay(100);
RF_WriteRegister(RF24_RX_PW_P0, PAYLOAD_SIZE); /* number of payload bytes we want to send and receive */
delay(100);

/* Enable RX_ADDR_P0 address matching */
RF_WriteRegister(RF24_EN_RXADDR, RF24_EN_RXADDR_ERX_P0); /* enable data pipe 0 */
delay(100);
RF_WriteRegister(RF24_SETUP_AW, RF24_SETUP_AW_DEFAULT_VAL); // Setup address width 5 bytes
delay(100);

RF_WriteRegister(RF24_RF_CH, CHANNEL_NO); /* set channel */
delay(100);

/* Set RADDR and TADDR as the transmit address since we also enable auto acknowledgment */
RF_WriteRegisterData(RF24_RX_ADDR_P0, (uint8_t*)TADDR, sizeof(TADDR));
delay(100);
RF_WriteRegisterData(RF24_TX_ADDR, (uint8_t*)TADDR, sizeof(TADDR));
delay(100);


/* clear interrupt flags */
status = RF_GetStatus();
delay(100);
RF_ResetStatusIRQ(RF24_STATUS_RX_DR|RF24_STATUS_TX_DS|RF24_STATUS_MAX_RT);
delay(100);
status = RF_GetStatus();
delay(100);

I am sending single character. Here is my sending code (have disabled auto-acknowledgement for testing purpose):

void sendData(void) { int i = 0; int TxFullFlag = 0; int cntr = 0;

RF_WriteRegister(RF24_EN_AA, RF24_EN_AA_ENAA_NONE); /* disable auto acknowledge. RX_ADDR_P0 needs to be equal to TX_ADDR! */
RF_WriteRegister(RF24_SETUP_RETR, RF24_SETUP_RETR_ARD_750|RF24_SETUP_RETR_ARC_15); /* Important: need 750 us delay between every retry */
RF_ResetStatusIRQ(RF24_STATUS_RX_DR|RF24_STATUS_TX_DS|RF24_STATUS_MAX_RT); // clear bit
status = RF_GetStatus();
TX_POWERUP();  /* Power up in transmitting mode */
RF_CE_LOW();   /* Will pulse this later to send data */

cntr = 0;
while(1)
{
	cntr++;
	if (cntr==2)
	{ // send data every 2 ms
		cntr = 0;
		status = RF_GetStatus();
		status2 = GetFIFOStatus();
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
		RF_TxPayload(payload1, sizeof(payload1)); // send data
		status = RF_GetStatus();
	}

	status = RF_GetStatus();
	if (intFlag)
	{ // check if we have received an interrupt


		status = RF_GetStatus();
		if (status&RF24_STATUS_RX_DR)
		{ 
                           // data received interrupt
			status = RF_GetStatus();
			RF_RxPayload(payload2, sizeof(payload2)); /* will reset RX_DR bit */
			RF_ResetStatusIRQ(RF24_STATUS_RX_DR); // clear bit
			GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
		}
		if (status&RF24_STATUS_TX_DS)
		{ 
                           // data sent interrupt
			RF_Write(RF24_FLUSH_TX); /* flush old data */
			RF_ResetStatusIRQ(RF24_STATUS_TX_DS); // clear bit
			GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
			status = RF_GetStatus();
		}
		intFlag = 0; // reset interrupt flag
	}
	if (status&RF24_STATUS_MAX_RT)
	{ // retry timeout interrupt
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
		RF_ResetStatusIRQ(RF24_STATUS_MAX_RT); // clear bit
	}
	delay(500000);
}

}

Here is my receiving code on the other kit:

void recvData(void) { int i = 0; int cntr = 0;

status = RF_GetStatus();

RF_WriteRegister(RF24_EN_AA, RF24_EN_AA_ENAA_NONE); /* disable auto acknowledge. RX_ADDR_P0 needs to be equal to TX_ADDR! */
status = RF_GetStatus();
RF_WriteRegister(RF24_SETUP_RETR, RF24_SETUP_RETR_ARD_750|RF24_SETUP_RETR_ARC_15); /* Important: need 750 us delay between every retry */
status = RF_GetStatus();
RF_ResetStatusIRQ(RF24_STATUS_RX_DR|RF24_STATUS_TX_DS|RF24_STATUS_MAX_RT); // clear bit
status = RF_GetStatus();

RX_POWERUP();  /* Power up in receiving mode */
RF_CE_HIGH();   /* Listening for packets */
delay(100);

cntr = 0;
while(1)
{
	status = RF_GetStatus();
	RF_RxPayload(payload2, sizeof(payload2)); /* will reset RX_DR bit */
	delay(10000);
	if (intFlag)
	{ // interrupt?

		status = RF_GetStatus();
		status2 = GetFIFOStatus();
		RF_RxPayload(payload2, sizeof(payload2)); /* will reset RX_DR bit */
		if (status&RF24_STATUS_RX_DR)
		{ // data received interrupt
			RF_ResetStatusIRQ(RF24_STATUS_RX_DR); // clear bit
                    }
		else
		{
			RF_ResetStatusIRQ(RF24_STATUS_RX_DR|RF24_STATUS_TX_DS|RF24_STATUS_MAX_RT); /* make sure we reset all flags. Need to have the pipe number too */
		}
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
		intFlag = 0; // reset interrupt flag
	}
	if (status&RF24_STATUS_RX_DR)
	{ // data received interrupt
		RF_ResetStatusIRQ(RF24_STATUS_RX_DR|RF24_STATUS_TX_DS|RF24_STATUS_MAX_RT); /* make sure we reset all flags. Need to have the pipe number too */
		status = RF_GetStatus();
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
	}
	if (status&RF24_STATUS_TX_DS)
	{ // data sent interrupt
		RF_ResetStatusIRQ(RF24_STATUS_TX_DS); // clear bit
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
	}
	if (status&RF24_STATUS_MAX_RT)
	{ // retry timeout interrupt
		RF_ResetStatusIRQ(RF24_STATUS_MAX_RT); // clear bit
		GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
	}
}

}

When i switch-on both the kits, (1) the sender keeps sending the data, but the status flag remains 0x20, does not clear the flag even after resetting the status and/or flushing the Tx buffer (2) the receiver keep getting the data and raises interrupt, but (a) the status flag always remains 0 ( b) the data content is always 0 Whenever i stop the Tx kit, the receiver does not get data and no interrupt is received.

Can anyone please help me check what i may be messing around ?

Thanks and Regards, R.Senthil.

Related