Hi,
I have atmeg168v with the nrf24L01. I have made use of the Crash_Maxed’s code .Here ,thanks for his help.
Now the transmitter can give the TX_DS interrupt but the reciever can’t gets the RX_DR interrupt and can’t get any data in the RX FIFO. After .So i think the trans is working well.
I am able to communicate through SPI to the nrf24L01.I read Internal regs that i used and they are set right but the reciever wont recieve any bytes.
These are part of code.
tx code :
void main(void)
{
unsigned int i;
unsigned char temp0;
CLI();
PortInit();
timer0_init();
timer1_init();
Usart_init();
TIMSK1|=(1<<TOIE1); //定时器开中断
SPI_MasterInit();
SEI();
while(1)
{
CSN_1;
for(i=0; i<15; i++)
{
Usart_transmit(0x11);
delay_ms(10);
}
Usart_transmit(0x22);
config_ptx();
Usart_transmit(0x33);
//send a packet
CSN_0;
SPI_MasterTransmit(0xE1);
CSN_1;
CSN_0;
SPI_MasterTransmit(0xA0);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0xA0);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0xA0);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x07);
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR);
Usart_transmit(0x44);
CSN_1;
Usart_transmit(0x55);
CE_1; //activate transmitter
delay_ms(1);
CE_0;; //disable transmitter
delay_ms(20); //Debugging - can measure the PTX's IRQ line with a
//logic probe, voltmeter, or o-scope to make sure line is low
CSN_0;
SPI_MasterTransmit(0x07); //Read the status register
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR);
Usart_transmit(0x66);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x27); //Clear the TX_DS bit in the status register
SPI_MasterTransmit(0x20);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x07);
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(temp0);
Usart_transmit(0x77);
CSN_1;
delay_ms(20);
}
}
void config_ptx(void)
{
//config PTX
CSN_0;
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x0a); //0x5c
CSN_1;
CSN_0;
SPI_MasterTransmit(0x24);
SPI_MasterTransmit(0x00);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x23);
SPI_MasterTransmit(0x03);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x22);
SPI_MasterTransmit(0x00); //0x01
CSN_1;
CSN_0;
SPI_MasterTransmit(0x26);
SPI_MasterTransmit(0x07);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x25);
SPI_MasterTransmit(40);//0x02
CSN_1;
CSN_0;
SPI_MasterTransmit(0x31);
SPI_MasterTransmit(0x00); //RX_PW_P0
CSN_1;
CSN_0;
SPI_MasterTransmit(0x30);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x2A);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x21);
SPI_MasterTransmit(0x00);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x27);
SPI_MasterTransmit(0x7E);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x0A); //5E
CSN_1;
}
rx code:
main()
{
unsigned char temp0;
CLI();
PortInit();
timer0_init();
timer1_init();
Usart_init();
TIMSK1|=(1<<TOIE1); //定时器开中断
SPI_MasterInit();
SEI();
while(1)
config_prx();
Usart_transmit(0x22);
delay_us(1000);
CE_0;
CSN_0;
SPI_MasterTransmit(0x61);
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out received data
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out received data
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out received data
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out received data
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out received data
CSN_1;
CSN_0;
SPI_MasterTransmit(0xE2); //Flush RX FIFO
CSN_1;
Usart_transmit(0x33);
CSN_0;
SPI_MasterTransmit(0x07); //Read the status register
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out status register
CSN_1;
CSN_0;
SPI_MasterTransmit(0x27); //Clear the RX_DR bit in the status register
SPI_MasterTransmit(0x40);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x07);
temp0 = SPI_MasterTransmit(0x00);
Usart_transmit(SPDR); //Print out status register
CSN_0;
CE_1;
Usart_transmit(0x44);
delay_ms(500);
showregisters_prx();
}
}
void config_prx(void)
{
CE_0;
//config PRX
CSN_1;
delay_us(10);
CSN_0;
SPI_MasterTransmit(0x20);
//SPI_MasterTransmit(0x3D); //3D
SPI_MasterTransmit(0x0D); //0D
CSN_1;
showregisters_prx_macro(0x00);//读00地址寄存器
CSN_0;
SPI_MasterTransmit(0x21);
SPI_MasterTransmit(0x00);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x22);
SPI_MasterTransmit(0x01); //enable pipe0
CSN_1;
CSN_0;
SPI_MasterTransmit(0x23);
SPI_MasterTransmit(0x03);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x24);
SPI_MasterTransmit(0x00); //SETUP_RETP
CSN_1;
showregisters_prx_macro(0x03);//读00地址寄存器
CSN_0;
SPI_MasterTransmit(0x26);
SPI_MasterTransmit(0x07);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x2A); //use the same address on the RX device as the TX device
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x2B); //use the same address on the RX device as the TX device
SPI_MasterTransmit(0xC2);
SPI_MasterTransmit(0xC2);
SPI_MasterTransmit(0xC2);
SPI_MasterTransmit(0xC2);
SPI_MasterTransmit(0xC2); //NEW ADD
CSN_1;
CSN_0;
SPI_MasterTransmit(0x31);
//SPI_MasterTransmit(0x04); //接收4字节有效数据
SPI_MasterTransmit(0x05); //接收5字节有效数据
CSN_1;
CSN_0;
SPI_MasterTransmit(0x32);
SPI_MasterTransmit(0x08); //接收4字节有效数据
CSN_1; //NEW ADD
CSN_0;
SPI_MasterTransmit(0x25);
SPI_MasterTransmit(40); //0x02
CSN_1;
CSN_0;
SPI_MasterTransmit(0x30);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
SPI_MasterTransmit(0xE7);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x20);
//SPI_MasterTransmit(0x3F);
SPI_MasterTransmit(0x0b); //0x0f
CSN_1;
showregisters_prx_macro(0x00);//读00地址寄存器
CSN_0;
SPI_MasterTransmit(0xE2);
CSN_1;
delay_ms(5);
CE_1; //activate receiver
}