新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2018-4-21
- 在线时间
- 2 小时
|
5金钱
使用的2块相同的战舰V3开发板。已拔掉st-link运行程序。
程序也是从最新的战舰V3hal库版本中直接用的。
但接收端一直是send failed
主函数
int main(void)
{
u8 key,mode;
u16 t=0;
u8 tmp_buf[33];
HAL_Init(); //3õê¼»ˉHAL¿a
Stm32_Clock_Init(RCC_PLL_MUL9); //éèÖÃê±Öó,72M
delay_init(72); //3õê¼»ˉÑóê±oˉêy
uart_init(115200); //3õê¼»ˉ′®¿ú
LED_Init(); //3õê¼»ˉLED
KEY_Init(); //3õê¼»ˉ°′¼ü
LCD_Init(); //3õê¼»ˉLCD FSMC½ó¿ú
NRF24L01_Init(); //3õê¼»ˉNRF24L01
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"WarShip STM32");
LCD_ShowString(30,70,200,16,16,"NRF24L01 TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2017/6/1");
while(NRF24L01_Check())
{
LCD_ShowString(30,130,200,16,16,"NRF24L01 Error");
delay_ms(200);
LCD_Fill(30,130,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,130,200,16,16,"NRF24L01 OK");
while(1)
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
mode=0;
break;
}else if(key==KEY1_PRES)
{
mode=1;
break;
}
t++;
if(t==100)LCD_ShowString(10,150,230,16,16,"KEY0:RX_Mode KEY1:TX_Mode"); //éá˸ÏÔê¾ìáê¾DÅÏ¢
if(t==200)
{
LCD_Fill(10,150,230,150+16,WHITE);
t=0;
}
delay_ms(5);
}
LCD_Fill(10,150,240,166,WHITE);//Çå¿ÕéÏÃæμÄÏÔê¾
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
if(mode==0)//RXÄ£ê½
{
LCD_ShowString(30,150,200,16,16,"NRF24L01 RX_Mode");
LCD_ShowString(30,170,200,16,16,"Received DATA:");
NRF24L01_RX_Mode();
while(1)
{
if(NRF24L01_RxPacket(tmp_buf)==0)//ò»μ©½óêÕμ½DÅÏ¢,ÔòÏÔê¾3öà′.
{
tmp_buf[32]=0;//¼óèë×Ö·û′®½áêø·û
LCD_ShowString(0,190,lcddev.width-1,32,16,tmp_buf);
}else delay_us(100);
t++;
if(t==10000)//′óÔ¼1sÖó¸Ä±äò»′Î×′ì¬
{
t=0;
LED0=!LED0;
}
};
}else//TXÄ£ê½
{
LCD_ShowString(30,150,200,16,16,"NRF24L01 TX_Mode");
NRF24L01_TX_Mode();
mode=' ';//′ó¿Õ¸ñ¼ü¿aê¼
while(1)
{
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
LCD_ShowString(30,170,239,32,16,"Sended DATA:");
LCD_ShowString(0,190,lcddev.width-1,32,16,tmp_buf);
key=mode;
for(t=0;t<32;t++)
{
key++;
if(key>('~'))key=' ';
tmp_buf[t]=key;
}
mode++;
if(mode>'~')mode=' ';
tmp_buf[32]=0;//¼óèë½áêø·û
}else
{
LCD_Fill(0,170,lcddev.width,170+16*3,WHITE);//Çå¿ÕÏÔê¾
LCD_ShowString(30,170,lcddev.width-1,32,16,"Send Failed ");
};
LED0=!LED0;
delay_ms(1500);
};
}
}
发送数据函数
u8 NRF24L01_TxPacket(u8 *txbuf)
{
u8 sta;
SPI2_SetSpeed(SPI_BAUDRATEPRESCALER_8); //spiËù¶èÎa6.75Mhz£¨24L01μÄ×î′óSPIê±ÖóÎa10Mhz£©
NRF24L01_CE=0;
NRF24L01_Write_Buf(WR_TX_PLOAD,txbuf,TX_PLOAD_WIDTH);//D′êy¾Yμ½TX BUF 32¸ö×Ö½ú
NRF24L01_CE=1; //Æô¶ˉ·¢Ëí
while(NRF24L01_IRQ!=0); //μè′y·¢Ëííê3é
sta=NRF24L01_Read_Reg(STATUS); //¶áè¡×′쬼Ä′æÆ÷μÄÖμ
NRF24L01_Write_Reg(NRF_WRITE_REG+STATUS,sta); //Çå3yTX_DS»òMAX_RTÖD¶Ï±êÖ¾
if(sta&MAX_TX) //′ïμ½×î′óÖØ·¢′Îêy
{
NRF24L01_Write_Reg(FLUSH_TX,0xff); //Çå3yTX FIFO¼Ä′æÆ÷
return MAX_TX;
}
if(sta&TX_OK) //·¢Ëííê3é
{
return TX_OK;
}
return 0xff;//ÆäËûÔ-òò·¢Ëí꧰ü
|
|