NRF24L01检测是否存在,成功了。但是发不出数据。。
测试是IRQ引脚没有反应。
代码如下:
mian.c代码:
SysInit(); //ϵͳ³õʼ»¯º¯Êý
UsartInit();//´®¿Ú³õʼ»¯º¯Êý
LCD_init(); //LCD5110³õʼ»¯º¯Êý
SPI_init(); //SPI×ÜÏߵijõʼ»¯
LCD_clear();
//³õʼ½çÃæ
LCD_write_string(0,0,"Please Wait...");//5110½çÃæ
SendString("Hello!"); //´®¿Ú´òÓ¡Êý¾Ý
SendString("
");
SendString("This is NRF24L01 Test..");
SendString("
");
SendString("xiaoxiao110");
SendString("
");
SendString("2014-07-09");
SendString("
");
SendString("
");
SendString("
");
Delay50ms(20);
while(1)//¼ì²âNRF24L01ÊÇ·ñÔÚÏß
{
if(NRF24L01_Check()) //ûÓмì²âµ½NRF24L01 É豸
{
LCD_write_string(0,0,"NRF24L01 Check Failed!"); //ÔÚ5110ÏÔʾÔÚÏß½á¹û
SendString("NRF24L01 Check Failed...");//´®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("
");
SendString("
");
Delay50ms(50);
}
else //ÕÒµ½NRF24L01 É豸
{
LCD_clear();
LCD_write_string(0,0,"NRF24L01 Check Success..."); //ÔÚ5110ÏÔʾÔÚÏß½á¹û
LCD_write_string(0,27,"NRF24L01 is OK!");
SendString("NRF24L01 Check Success...");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("
");
SendString("
");
Delay50ms(50);
break;
}
}
TX_Mode(); //ÉèÖÃNRF24L01Ϊ·¢ËÍģʽ
LCD_clear();
LCD_write_string(0,0,"Please Wait...");
LCD_write_string(0,18,"NRF24L01 in Sending Data...");
SendString("Please Wait...");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("NRF24L01 in Sending Data...");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("2014-07-09");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("
");
Delay50ms(50);
Delay50ms(50);
TX_Mode();
while(1)
{
TX_Mode();
if(NRF24L01_TxPacket(NRF_SendBuf) == TX_OK)
{
LCD_clear();
LCD_write_string(0,0,"NRF24L01 Send Success..."); //ÔÚ5110ÏÔʾÔÚÏß½á¹û
SendString("NRF24L01 Send Success...");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("2014-07-09");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("
");
Delay50ms(20);
Delay50ms(20);
}
else
{
LCD_clear();
LCD_write_string(0,0,"NRF24L01 Send Failed..."); //ÔÚ5110ÏÔʾÔÚÏß½á¹û
SendString("NRF24L01 Send Failed...");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("2014-07-09");//Óô®¿Ú½«½á¹û´òÓ¡³öÀ´
SendString("
");
SendString("
");
Delay50ms(20);
Delay50ms(20);
}
子函数代码:
void TX_Mode(void)
{
// unsigned char temp;
CE=0;
SPI_Write_Buf(SPI_WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // Writes TX_Address to nRF24L01
SPI_Write_Buf(SPI_WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr for Auto.Ack
SPI_Write_Buf(WR_TX_PLOAD, NRF_SendBuf, TX_PLOAD_WIDTH); // Writes data to TX payload
SPI_RW_Reg(SPI_WRITE_REG + EN_AA, 0x01); // Enable Auto.Ack:Pipe0
SPI_RW_Reg(SPI_WRITE_REG + EN_RXADDR, 0x01); // Enable Pipe0
SPI_RW_Reg(SPI_WRITE_REG + SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...
SPI_RW_Reg(SPI_WRITE_REG + RF_CH, 40); // Select RF channel 40
SPI_RW_Reg(SPI_WRITE_REG + RF_SETUP, 0x07); // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
SPI_RW_Reg(SPI_WRITE_REG + CONFIG, 0x0e);
// temp = SPI_RW_Reg(SPI_WRITE_REG + CONFIG, 0x0e); // Set PWR_UP bit, enable CRC(2 bytes) & Prim:TX. MAX_RT & TX_DS enabled..
// SendChar(temp);
// SendString("
"); //²âÊÔʹÓÃ
CE=1;
}
unsigned char NRF24L01_TxPacket(unsigned char *txbuf)
{
unsigned char state;
unsigned int timeout = 0;
CE=0;
SPI_Write_Buf(SPI_WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
SPI_Write_Buf(WR_TX_PLOAD,txbuf,TX_PLOAD_WIDTH);//дÊý¾Ýµ½TX BUF 32¸ö×Ö½Ú
// SPI_RW_Reg(SPI_WRITE_REG + CONFIG, 0x0e);
CE=1; //Æô¶¯·¢ËÍ
while(IRQ != 0) //µÈ´ý·¢ËÍÍê³É
{
;
// timeout++;
// if(timeout >9000)
// break;
}
state = SPI_Read(STATUS); //¶Áȡ״̬¼Ä´æÆ÷µÄÖµ
SendChar(state);
SendString("
");
SPI_RW_Reg(SPI_WRITE_REG+STATUS,state); //Çå³ýTX_DS»òMAX_RTÖжϱêÖ¾
if(state&MAX_TX) //´ïµ½×î´óÖØ·¢´ÎÊý
{
SPI_RW_Reg(FLUSH_TX,0xff); //Çå³ýTX FIFO¼Ä´æÆ÷
return MAX_TX;
}
if(state&TX_OK) //·¢ËÍÍê³É
{
return TX_OK;
}
return 0xff; //ÆäËûÔÒò·¢ËÍʧ°Ü
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
好的,谢谢哈。兄弟。
一周热门 更多>