请教一下用过A7102的朋友,看下这段程序哪里出了问题 不胜感激!
昨天还能通讯上 不知道动了哪里通不上了 看了半天A7102手册资料也改不出个究竟
void NRF903_Init(void)
{
SCS_DDR_OUT();
SCS_CR1();
SCS_CR2();
SCK_DDR_OUT();
SCK_CR1();
SCK_CR2();
SDIO_DDR_IN();
SDIO_CR1();
SDIO_CR2();
IRQ_DDR_IN();
IRQ_CR1();
IRQ_CR2();
PWR_DDR_OUT(); //开无线模块电源
PWR_CR1();
PWR_CR2();
SPI_Init();
PWR_OFF();
delay_ms(4);
PWR_ON();
delay_ms(4);
SCS_OFF();
SPI_Write(NRF903_CMD_RESET); //复位
SCS_ON();
delay_ms(4);
NRF903_WriteReg(ADDR_CRYSTAL,0x0015);//High current 时钟使能 外部石英振荡器开
delay_ms(4);
NRF903_WriteReg(ADDR_MODECONTROL,0x00c0); //FIFO 模式 RF使能
delay_ms(4);
NRF903_Write_ID(NRF903_RxAddr); //写入接收地址
delay_ms(4);
NRF903_WriteReg(ADDR_SYSTEMCLOCK,0x0079);
NRF903_WriteReg(ADDR_PLL_I,0x0043);
NRF903_WriteReg(ADDR_PLL_II,C_Tx_Frequency);
NRF903_WriteReg(ADDR_PLL_III,0x0000);
NRF903_WriteReg(ADDR_PLL_IV,0x066c);
NRF903_WriteReg(ADDR_TXI,0x1520);
NRF903_WriteReg(ADDR_TXII,0x0337);
NRF903_WriteReg(ADDR_RXI,0x1813);
NRF903_WriteReg(ADDR_RXII,0x500b);
NRF903_WriteReg(ADDR_ADC,0x0000);
NRF903_WriteReg(ADDR_FIFO,0x4000|(NRF903_TxRxBuf_Len-1));
NRF903_WriteReg(ADDR_CODE,0x150f);
NRF903_WriteReg(ADDR_PINCONTROL,0x0022);
NRF903_WriteReg(ADDR_CALIBRATION,0x4886);
NRF903_WriteReg(ADDR_MODECONTROL,0x00e0);
delay_ms(4);
TX_Freq_Calibration = NRF903_Calibration_Frequency((uint16)C_Tx_Frequency);
RX_Freq_Calibration = NRF903_Calibration_Frequency((uint16)C_Rx_Frequency);
SCS_OFF();
SPI_Write(NRF903_CMD_FIFORX_RESET);
SCS_ON();
SCS_OFF();
SPI_Write(NRF903_CMD_FIFOTX_RESET);
SCS_ON();
}
复制代码
设置为接收状态:
void NRF903_SetRxMode(void)
{
NRF903_Write_ID(NRF903_RxAddr); //写入接收地址
NRF903_WriteReg(ADDR_MODECONTROL,VALUE_W_FMS|VALUE_W_CER);
NRF903_WriteReg(ADDR_PLL_II,C_Rx_Frequency);
NRF903_WriteReg(ADDR_CALIBRATION,RX_Freq_Calibration);
NRF903_WriteReg(ADDR_MODECONTROL,VALUE_W_FMS|VALUE_W_CER|VALUE_W_TRER);//FIFO模式RS使能设置为接收模式
// NRF903_WriteReg(ADDR_MODECONTROL,0x00e8);
}
复制代码
接收数据包:
uint8 NRF903_RxPacket(void)
{
uint8 i;
if(!IRQ_IN)
{
return FALSE;
}
if(NRF903_ReadReg(ADDR_MODECONTROL)&VALUE_R_CRCF) //检测crc
{
SCS_OFF();
SPI_Write(NRF903_CMD_FIFORX_RESET);
SCS_ON();
NRF903_SetRxMode();
return FALSE;
}
SCS_OFF();
SPI_Write(NRF903_CMD_READ_FIFORX);
for(i = 0;i < NRF903_TxRxBuf_Len;i++)
{
NRF903_TxRxBuf[i] = SPI_Read();
}
SCS_ON();
return TRUE;
}
复制代码
数据包发送函数:
void NRF903_TxPacket(void)
{
uint8 i;
SCS_OFF();
SPI_Write(NRF903_CMD_WRITE_FIFOTX); //读取FIFO模式接收到的数据
for(i = 0;i <NRF903_TxRxBuf_Len;i++)
{
SPI_Write(NRF903_TxRxBuf[i]);
}
SCS_ON();
NRF903_Write_ID(NRF903_TxAddr);
NRF903_WriteReg(ADDR_MODECONTROL,VALUE_W_FMS|VALUE_W_CER|VALUE_W_PLLE); //FIFO模式RS使能PLL使能
NRF903_WriteReg(ADDR_PLL_II,C_Tx_Frequency); //射频锁相环小数部分设置
NRF903_WriteReg(ADDR_CALIBRATION,TX_Freq_Calibration); //校准频率
NRF903_WriteReg(ADDR_MODECONTROL,0x00d8); //FIFO模式RS使能设置为发送模式
while(IRQ_IN);
// while(!IRQ_IN);
}
复制代码转载
|