hello,
I am working on nrf24l01 to receive some data, and i success to transmit and receive the data.
However, received data (32 bytes) are all equal to first byte.
=> send 0x00, 0x01, 0x02…
received 0x00, 0x00, 0x00…
I am not sure that transmitter or receiver problem, but does any one has similar experience?
First i think payload length problem, but it was not.
below code is used sample code for receiver.
i did not used CRC and auto ack.
void delay()
{
uchar i=100;
while( --i ){};
}
// USE THIS FOR READING
uchar SPI_RW_CSN(uchar spi_data)
{
CSN = 0;
spi_flag = 0;
SPI0DAT = spi_data;
while (!spi_flag);
CSN = 1;
return SPI0DAT;
}
// DO NOT USED THIS FOR READING
uchar SPI_RW(uchar spi_data)
{
spi_flag = 0;
SPI0DAT = spi_data;
while (!spi_flag);
return SPI0DAT;
}
uchar SPI_RW_Reg(uchar reg, uchar value)
{
uchar reg_status;
CSN = 0; // CSN low, init SPI transaction
spi_flag = 0;
SPI0DAT = reg;
while (!spi_flag);
reg_status = SPI0DAT;
SPI0DAT = value;
spi_flag = 0;
while (!spi_flag);
CSN = 1; // CSN high again
return(reg_status); // return nRF24L01 status byte
}
uchar SPI_Write_Buf(uchar reg, uchar *pBuf, uchar bytes)
{
uchar buf_status,byte_ctr;
CSN_Pin0; // Set CSN low, init SPI tranaction
buf_status = SPI_RW(reg); // Select register to write to and read status byte
for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
SPI_RW(*pBuf++);
CSN_Pin1; // Set CSN high again
return(buf_status); // return nRF24L01 status byte
}
uchar SPI_Read_Buf(uchar reg, uchar *pBuf, uchar bytes)
{
uchar status,i;
CSN = 0; // Set CSN low, init SPI tranaction
status = SPI_RW(reg); // Select register to write to and read status byte
for(i=0; i<bytes; i++){
pBuf = SPI_RW(0);
-
}*
-
CSN = 1; // Set CSN high again*
-
return(status); // return nRF24L01 status byte*
}
void rs232_transmittion(uchar *pbuf, uchar num_data)
{ -
uchar i;*
-
TR1 = 1;*
-
TI0 = 1;*
-
for(i=0; i<num_data ; i++){*
printf( " %d", (int) rx_buf );
* }*
* printf (“\n”);*
* TR1 = 0;*
}
void nrf_setup()
{
* CE = 0;*
* // clear buffer*
* L01_Flush_TX;
L01_Flush_RX;
_ // clear interrupt*_
* SPI_RW_Reg(WRITE_REG+STATUS, 0x70);
_ // disable all auto ack*_
* SPI_RW_Reg(WRITE_REG + EN_AA, 0x00);
_ // Enable receive pipe => bidirectional communication*_
* SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);
_ // disable retransmittion when ack is not arrive*_
* SPI_RW_Reg(WRITE_REG + SETUP_RETR,0x00);
_ // Channel 0*_
* SPI_RW_Reg(WRITE_REG + RF_CH, 0);
_ // Select same RX0 payload width as TX Payload width*_
* SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PL_W);
_ // disable the CRC, 2 bytes crc, power up, receiver mode,_
SPI_RW_Reg(WRITE_REG + CONFIG, 0x03);
_ // setup address width 3 bytes*_
// SPI_RW_Reg(WRITE_REG + SETUP_AW, (TX_AW-2));
* // setup address*
// SPI_Write_Buf(WRITE_REG + TX_ADDR,TX_ADDRESS__,TX_AW);
* // rf setup , IF PLL is on, no channel change?*
* // data rate 1 bps, 0 dbm, LNA gain*
* // low power mode => data rate 1 bps, -18 dbm, LNA off*
* // SPI_RW_Reg(WRITE_REG + RF_SETUP, 6);
_ // performance mode => data rate 1 Mbps, -18 dbm, LNA on*_
* SPI_RW_Reg(WRITE_REG + RF_SETUP, 1);
_ CE = 0;_
_}_
void Test_tx(){
SPI_Write_Buf(WR_TX_PLOAD,TX_PAYLOAD_,TX_PL_W);*
* transmit;*
* // check status and clear => must clear or transmit once*
* do{*
* sta = SPI_RW_Reg(READ_REG + STATUS, 0x70);
_ }while( sta == 0x0e );_
_ // turn off transmittion => mode 2*_
* CE_off;*
}
//--------------------------------------------------------------------
// Main Routine
//--------------------------------------------------------------------
void main(void)
{
* uchar i, temp;*
* uint count;*
* uint data_to_pc=0;
_ P0 = 0xff;_
_ P1 = 0xff;_
_ CE = 0;_
_ P2 = 0xff;_
Init_Device(); *
* nrf_setup();
_ while (1){_
_ CE = 1;*_
* count = 0;*
* do{*
* // read register STATUS’s value*
* sta = SPI_RW_CSN(READ_REG + STATUS);
}while( !rx_dr );
_ // IF OVERFLOWED THAN CLEAR ALL*_
* if(MAX_RT) L01_Flush_RX;*
* CE = 0;*
* SPI_Read_Buf(RD_RX_PLOAD,rx_buf,RX_PL_W);
sta = SPI_RW_CSN(READ_REG + STATUS);
_ // CLEAR STATUS => IMPORTANT*_
* SPI_RW_Reg(WRITE_REG + STATUS, sta);
sta = SPI_RW_CSN(READ_REG + STATUS);*
* rs232_transmittion(rx_buf, RX_PL_W);
_ CE = 1;_
_}_
_}*_