- halSpiStrobe(CCxxx0_SIDLE);
- delay_ms(10);
- halRfSendPacket(txBuffer,3);
- delay_ms(100);
- void halRfSendPacket(INT8U *txBuffer, INT8U size)
- {
- halSpiStrobe(CCxxx0_SFTX);//清空缓冲区
- halSpiWriteReg(CCxxx0_TXFIFO, size);//这个必须要
- halSpiWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size); //写入要发送的数据
- halSpiStrobe(CCxxx0_STX); //进入发送模式发送数据
- // Wait for GDO0 to be set -> sync transmitted
- while (!(GDO0));
- // Wait for GDO0 to be cleared -> end of packet
- while (GDO0);
- //halSpiStrobe(CCxxx0_SFTX);
- }
while (!(GDO0));
// Wait for GDO0 to be cleared -> end of packet
while (GDO0);
//halSpiStrobe(CCxxx0_SFTX);这条指令 能运行通过,没有卡住,说明发送成功?(不知道对不对)
接收部分的程序
- halSpiStrobe(CCxxx0_SIDLE);
- delay_ms(10);
- halRfReceivePacket(rcBuffer,3);
- INT8U halRfReceivePacket(INT8U *rxBuffer, INT8U length)
- {
- INT8U status[2];
- INT8U packetLength;
- INT8U i=(length)*4; // 具体多少要根据datarate和length来决定
- halSpiStrobe(CCxxx0_SRX); //进入接收状态
- delay_us(100);
- //while (GDO0)
- while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4))
- {
- delay_us(100);
- --i;
- }
-
- if ((halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO)) //如果接的字节数不为0
- {
- packetLength = halSpiReadReg(CCxxx0_RXFIFO);//读出第一个字节,此字节为该帧数据长度
- if (packetLength <= length) //如果所要的有效数据长度小于等于接收到的数据包的长度
- {
- halSpiReadBurstReg(CCxxx0_RXFIFO, rxBuffer, packetLength); //读出所有接收到的数据
- length = packetLength; //把接收数据长度的修改为当前数据的长度
- // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI)
- halSpiReadBurstReg(CCxxx0_RXFIFO, status, 2); //读出CRC校验位
- halSpiStrobe(CCxxx0_SFRX); //清洗接收缓冲区
- return (status[1] & CRC_OK); //如果校验成功返回接收成功
- }
- else
- {
- length = packetLength;
- halSpiStrobe(CCxxx0_SFRX); //清洗接收缓冲区
- return 0;
- }
-
- }
- else
- return 0;
- }
一直接收不到数据,
接收发送的寄存器配置都是一样的
- const RF_SETTINGS rfSettings =
- {
- 0x00,
- 0x08, // FSCTRL1 Frequency synthesizer control.
- 0x00, // FSCTRL0 Frequency synthesizer control.
- 0x10, // FREQ2 Frequency control word, high byte.
- 0xA7, // FREQ1 Frequency control word, middle byte.
- 0x62, // FREQ0 Frequency control word, low byte.
- 0x5B, // MDMCFG4 Modem configuration.
- 0xF8, // MDMCFG3 Modem configuration.
- 0x03, // MDMCFG2 Modem configuration.
- 0x22, // MDMCFG1 Modem configuration.
- 0xF8, // MDMCFG0 Modem configuration.
- 0x00, // CHANNR Channel number.
- 0x47, // DEVIATN Modem deviation setting (when FSK modulation is enabled).
- 0xB6, // FREND1 Front end RX configuration.
- 0x10, // FREND0 Front end RX configuration.
- 0x18, // MCSM0 Main Radio Control State Machine configuration.
- 0x1D, // FOCCFG Frequency Offset Compensation Configuration.
- 0x1C, // BSCFG Bit synchronization Configuration.
- 0xC7, // AGCCTRL2 AGC control.
- 0x00, // AGCCTRL1 AGC control.
- 0xB2, // AGCCTRL0 AGC control.
- 0xEA, // FSCAL3 Frequency synthesizer calibration.
- 0x2A, // FSCAL2 Frequency synthesizer calibration.
- 0x00, // FSCAL1 Frequency synthesizer calibration.
- 0x11, // FSCAL0 Frequency synthesizer calibration.
- 0x59, // FSTEST Frequency synthesizer calibration.
- 0x81, // TEST2 Various test settings.
- 0x35, // TEST1 Various test settings.
- 0x09, // TEST0 Various test settings.
- 0x0B, // IOCFG2 GDO2 output pin configuration.
- 0x06, // IOCFG0D GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
- 0x05, // PKTCTRL1 Packet automation control.
- 0x05, // PKTCTRL0 Packet automation control.
- 0x01, // ADDR Device address.
- 0x20 // PKTLEN Packet length.
- };
小弟现在实在是找不到头绪了,望各位大神不吝赐教!!!!!!