- Mon Oct 08, 2007 6:44 am
#36068
Hi brennen
I transplanted some code from MIRF V2 according to what you have told me .
Now the transmitter can give the TX_DS interrupt but the reciever still can't gets the RX_DR interrupt and can't get any data in the RX FIFO.
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.
Please respond if you have any clue. I'm really stuck at the moment!
These are part of code.
tx mode:
I am haihong.I get register configurations from the devices.
I transplanted some code from MIRF V2 according to what you have told me .
Now the transmitter can give the TX_DS interrupt but the reciever still can't gets the RX_DR interrupt and can't get any data in the RX FIFO.
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.
Please respond if you have any clue. I'm really stuck at the moment!
These are part of code.
tx mode:
Code: Select all
rx mode :
void config_ptx(void)
{
//config PTX
CE_0;
CSN_0;
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x38);
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(0x26);
SPI_MasterTransmit(0x07);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x25);
SPI_MasterTransmit(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(0x21);
SPI_MasterTransmit(0x00);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x27);
SPI_MasterTransmit(0x7E);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x5A);
CSN_1;
}
void main(void)
{
unsigned char i;
SPI_MasterInit();
config_ptx();
while(1)
{
while (1)
{
transmit_data();
LED = 1;
delay_ms(10);
LED = 0;
delay_ms(500);
}
}
}
void transmit_data(void)
{
unsigned char i, data, cmd;
CSN_0;
//clear previous ints
SPI_MasterTransmit(0x27);
SPI_MasterTransmit(0x7E);
CSN_1;
CSN_0;
//PWR_UP = 1
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x3A);
CSN_1;
CSN_0;
//clear TX fifo
//the data sheet says that this is supposed to come up 0 after POR, but that doesn't seem to be the case
SPI_MasterTransmit(0xE1);
CSN_1;
CSN_0;
//4 byte payload
SPI_MasterTransmit(0xA0);
SPI_MasterTransmit(0x34);
SPI_MasterTransmit(0x33);
SPI_MasterTransmit(0x32);
SPI_MasterTransmit(0x31);
CSN_1;
//Pulse CE to start transmission
CE_1;
delay_ms(1);
CE_0;
}
Code: Select all
void config_prx(void)
{
CSN_1;
delay_us(10);
CSN_0;
CE_0;
SPI_MasterTransmit(0x20);
SPI_MasterTransmit(0x39);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x21);
SPI_MasterTransmit(0x00);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x23);
SPI_MasterTransmit(0x03);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x26);
SPI_MasterTransmit(0x07);
CSN_1;
CSN_0;
SPI_MasterTransmit(0x31);
SPI_MasterTransmit(0x04); //接收4字节有效数据
CSN_1;
CSN_0;
SPI_MasterTransmit(0x25);
SPI_MasterTransmit(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(0x3B);
CSN_1;
CE_1; //activate receiver
}
void main(void)
{
unsigned char i;
SPI_MasterInit();
config_prx();
while(1)
{
if (SPI_IRQ == 0) //wait for anything
{
for (i = 0; i < 5; i++) //flash LED 5 times if data received
{
LED = 1;
delay_ms(10);
LED = 0;
delay_ms(10);
}
delay_ms(200);
reset_RX();
}
}
}
void reset_RX(void)
{
unsigned char i, j;
unsigned char buffer[4];
//Read RX payload
CSN_0;
SPI_MasterTransmit(0x61);
for (j = 0; j < 4; j++)
{
buffer[j] = SPI_MasterTransmit(0);
}
CSN_1;
//Flush RX FIFO
CSN_0;
SPI_MasterTransmit(0xE2);
CSN_1;
CSN_0;
//reset int
SPI_MasterTransmit(0x27);
SPI_MasterTransmit(0x40);
CSN_1;
}
//---------------------------外部中断0-----------------------------------//
#pragma interrupt_handler INT0_ovf_isr:2
void INT0_ovf_isr(void)
{ unsigned int temp_data;
SPI_IRQ == 0;
}
I am haihong.I get register configurations from the devices.
Code: Select all
rx: 3B 00 03 03 03 02 07 0E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 04 00 00 00 00 00 11 .
Code: Select all
Please respond if you have any clue. I'm really stuck at the moment!tx: 5A 00 03 03 00 02 07 2E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 00 00 00 00 00 00 11 .