感谢蒋粤的提醒。PCB上的丝印和实际的引脚不对应。引脚PG8对应的丝印应该是PG6.
同时,前几天调不通的时候测试了下PB15,与插针PB15 和片子上的引脚不通。
于是就拆掉板子上的NRF插座。换成插针,使用杜邦线连接NRF24L01模块。见下图
1、使用的硬件
SPI2、NRF24L01模块、PC6、7、PB13、14、15、PG6
2、使用原子的板子作为通信的另一端。
程序工作过程:
1、EEPW板双工模式收发数据
当收到串口发送过来的数据是,将串口数据发送。
接收数据,发PC端显示
2、原子板工作过程
启动按压Key1工作在发送模式,按压Key2工作在接受模式
串口处理代码:
void USART1_IRQHandler()
{
uint8_t Res;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!= RESET) //检查串口1是否是否发生了中断
{
Res = USART_ReceiveData(USART1);
if((USART_RX_STA&0x80)==0)//接收未完成
{
if(USART_RX_STA&0x40)//接收到了0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
else
{
USART_RX_STA|=0x80; //接收完成了
TX_Mode(); //设置为发送模式
NRF24L01_TxPacket(USART_RX_BUF); //发送数据
USART_RX_STA = 0; //情况串口数据标志
RX_Mode(); //继续接收
}
}
else //还没收到0X0D
{
if(Res==0x0d)USART_RX_STA|=0x40;
else
{
USART_RX_BUF[USART_RX_STA&0X3F]=Res ;
USART_RX_STA++;
if(USART_RX_STA>63)USART_RX_STA=0;//接收数据错误,重新开始接收
}
}
}
}
}
主函数中使用:
NRF24L01_Init(); //初始化,包含了SPI2的初始化
if(NRF24L01_Check()) //检测无线模块是否存在
{
printf("NRF24L01检查失败");
}
else
{
printf("NRF24L01检测成功");
}
printf("请输入要发生的数据,以回车结束\r\n");
RX_Mode(); //设置成接收模式
while(1) //循环检查是否收到数据
{
if(NRF24L01_RxPacket(tmp_buf)==0)
{
printf("收到数据:%s\r\n",tmp_buf);
}
}
图如下:
1、硬件连接
2、串口监视图片
单工模式串口监视

两个串口

双工模式收发数据

再来一张图

硬件图




