关于NRF模块的中断IRQ
程序如下:
u8 NRF_Rx_Dat(u8 *rxbuf)
{
u8 state;
NRF_CE_HIGH();
while(NRF_Read_IRQ()!=0);
NRF_CE_LOW();
state=SPI_NRF_ReadReg(STATUS);
SPI_NRF_WriteReg(NRF_WRITE_REG+STATUS,state);
if(state&RX_DR)
{
SPI_NRF_ReadBuf(RD_RX_PLOAD,rxbuf,RX_PLOAD_WIDTH);
SPI_NRF_WriteReg(FLUSH_RX,NOP);
return RX_DR;
}
else
return ERROR;
}
谢谢!
SPI_NRF_WriteReg(NRF_WRITE_REG + CONFIG, 0x00);
NRF_RX_Mode();
status = NRF_Rx_Dat(rxbuf);
/*?D???óê?×′ì?*/
switch(status)
{
case RX_DR:
GUI_DispStringAt(" RX OK",0,67);
dir=(rxbuf[1]*1+rxbuf[2]*10+rxbuf[3]*100+rxbuf[4]*1000+rxbuf[5]*10000);
mpux=rxbuf[6];
break;
case ERROR:
GUI_DispStringAt(" RX ERROR ",0,67);
break;
}
SPI_NRF_WriteReg(NRF_WRITE_REG + CONFIG, 0x00);
NRF_TX_Mode();
status = NRF_Tx_Dat(txbuf);
switch(status)
{
case MAX_RT:
GUI_DispStringAt(" TX MAX_RT",0,89);
break;
case ERROR:
GUI_DispStringAt(" TX ERROR",0,89);
break;
case TX_DS:
txbuf[0]=3;
GUI_DispStringAt(" TX OK ",0,85);
break;
}
还是有点错误,有一边发送不了
stm 32 硬件spi 双向通信完美,欢迎交流 154382415
delay_ms(20);
while(1)
{ mode(); //可以视为重置无线模块
t_while = t_tx;
while(t_while--)
{
status=nrf_RxTx('t',txbuf); //·¢?í?£ê?
if(status==TX_DS)
break;
}
mode();
t_while = t_rx ;
while(t_while--)
{
status=nrf_RxTx('r',rxbuf);
if(status==RX_DR)
break;
}
conversion(HMC_MultipleRead());
txbuf[0]=GetData(ACCEL_XOUT_H);
txbuf[1]=ge;
txbuf[2]=shi;
txbuf[3]=bai;
txbuf[4]=qian;
txbuf[5]=wan;
txbuf[6]=rxbuf[0];
看手册呀,问别人还不如看手册
不懂- -、、。
