//////////////////////////////////////////
引脚分布,
IRQ PA2
CE PA4
CS PA3
SPI1 (记住是SPI1的接口)
SCK PA5
MISO PA6
MOSI PA7
////////////////////////////////////////
接好引脚,初始化好就可以使用了。记住,里面的文件配置都不用改,改引脚是ok 的
http://download.csdn.net/download/hes_c/10140988
这是RX初始化
NRF24L01_Init();
while(NRF24L01_Check())
{
led_on();
printf("NRF NOrn");
delay_ms(100);
}
printf("NRF OKrn");
NRF24L01_RX_Mode();
这是TX初始化
NRF24L01_Init();
while(NRF24L01_Check())
{
led_on();
printf("NRF NOrn");
delay_ms(100);
}
printf("NRF OKrn");
NRF24L01_TX_Mode();
因为NRF通信会比较容易掉包
所有下面写了一个通信校验和加密(就不给全部代码了)
这是发送,添加校验和加密
//发送信息
int send_mes(u32 ID,u32 t_TX_voltage,u32 t_TX_electricity,u32 t_RX_voltage,u32 t_RX_electricity)
{
int n=0;
u32 temp=0;
temp=t_TX_voltage+t_TX_electricity+t_RX_voltage+t_RX_electricity+BCD+ID;
//ID
buf_mes[n++]=(ID>>24)&0x000000ff;
buf_mes[n++]=(ID>>16)&0x000000ff;
buf_mes[n++]=(ID>>8)&0x000000ff;
buf_mes[n++]=(ID>>0)&0x000000ff;
//TX电压
buf_mes[n++]=(t_TX_voltage>>24)&0x000000ff;
buf_mes[n++]=(t_TX_voltage>>16)&0x000000ff;
buf_mes[n++]=(t_TX_voltage>>8)&0x000000ff;
buf_mes[n++]=(t_TX_voltage>>0)&0x000000ff;
//TX电流
buf_mes[n++]=(t_TX_electricity>>24)&0x000000ff;
buf_mes[n++]=(t_TX_electricity>>16)&0x000000ff;
buf_mes[n++]=(t_TX_electricity>>8)&0x000000ff;
buf_mes[n++]=(t_TX_electricity>>0)&0x000000ff;
//RX电压
buf_mes[n++]=(t_RX_voltage>>24)&0x000000ff;
buf_mes[n++]=(t_RX_voltage>>16)&0x000000ff;
buf_mes[n++]=(t_RX_voltage>>8)&0x000000ff;
buf_mes[n++]=(t_RX_voltage>>0)&0x000000ff;
//RX电流
buf_mes[n++]=(t_RX_electricity>>24)&0x000000ff;
buf_mes[n++]=(t_RX_electricity>>16)&0x000000ff;
buf_mes[n++]=(t_RX_electricity>>8)&0x000000ff;
buf_mes[n++]=(t_RX_electricity>>0)&0x000000ff;
//校验码
buf_mes[n++]=(temp>>24)&0x000000ff;
buf_mes[n++]=(temp>>16)&0x000000ff;
buf_mes[n++]=(temp>>8)&0x000000ff;
buf_mes[n++]=(temp>>0)&0x000000ff;
buf_mes[32]='