si4438 cca 侦听
/* set GPIO0 for RSSI interrupt / CCA */
txbuf[0] = CMD_GPIO_PIN_CFG;
txbuf[1] = 27; /* GPIO[0] = 27: CCA or 37: CCA_LATCH */
txbuf[2] = 0; /* GPIO[1] = DONOTHING */
txbuf[3] = 0; /* GPIO[2] = DONOTHING */
txbuf[4] = 0; /* GPIO[3] = DONOTHING */
txbuf[5] = 0; /* NIRQ = behavior not modified */
txbuf[6] = 0; /* SDO = behavior not modified*/
txbuf[7] = 0; /* GEN_CONFIG = GPIO outputs will have the highest drive strength*/
si446x_SendCommand(8, txbuf);
si446x_WaitForCTS();
/* set RSSI threshold */
txbuf[0] = CMD_SET_PROPERTY;
txbuf[1] = PROP_MODEM_GROUP;
txbuf[2] = 0x03; /* num of property */
txbuf[3] = PROP_MODEM_RSSI_THRESH;/* start address */
txbuf[4] = 30; /* MODEM_RSSI_THRESH: if < 30, CCA GPIO0 becomes low */
txbuf[5] = 0x0c; /* MODEM_RSSI_JUMP_THRESH: default */
txbuf[6] = 0x22; /* MODEM_RSSI_CONTROL: check thresh after latch, latch RSSI when sync word is detected */
si446x_SendCommand(5, txbuf);
si446x_WaitForCTS();
- #include <reg51.h>
- #include <string.h>
- #include "radio.h"
- #include"spi.h"
- #include"uart.h"
- #define U8 unsigned char
- #define SEND_OUT_MESSAGE_WITH_ACK "NEED_ACK"
- #define SEND_OUT_MESSAGE_NO_ACK "NO_ACK"
- #define SEND_OUT_ACK "ACK!"
- #define SEND_OUT_MESSAGE_WITH_ACK_LEN 8
- #define SEND_OUT_MESSAGE_NO_ACK_LEN 6
- #define SEND_OUT_ACK_LEN 4
- #define SNED_OUT_MSG_MAX_LEN 8 //It is the maxium length of the send out packet.
- extern idata U8 ItStatus1,ItStatus2;
- void delay_ms(unsigned int ms)
- {
- unsigned int i;
- unsigned char j;
- for(i=0;i<ms;i++)
- {
- for(j=0;j<200;j++);
- for(j=0;j<102;j++);
- }
- }
- void Init_Device(void)
- {
- // Reset_Sources_Init();
- // PCA_Init();
- // Port_IO_Init(); // Oscillator_Init();
- // Timer0_Init();
- SPI_Init();
- EA = 1; //Enable Gloable interruption.
- //启动射频模块,模块的SDN引脚拉低后必须延时至少30ms,实际上可以直接把SDN引脚接地,这样就不用在程序中初始化了;
- RF_SDN=0;
- delay_ms(30);
- delay_ms(30);
- // RF_SDN = 0;
- // DelayMs(30);
- // NSEL = 1;
- // SCLK = 0;
- SpiWriteRegister(0x0B, 0xCA);
- SpiWriteRegister(0x0C, 0xCA);
- SpiWriteRegister(0x0D, 0xCA);
- //1.Blink the LED to show that the initialization is finished.
- //2.Wait for more than 16ms to wait for the radio chip to work correctly.
- // TurnOnAllLEDs();
- // DelayMs(20);
- delay_ms(20);
- // TurnOffAllLEDs();
- }
- void main(void)
- {
- U8 length,temp8, *str, sendLen;
- U8 payload[10];
- //Initialize the MCU:
- UART_Init();
- Init_Device();
- UART_Send_Str("MCU初始化完毕....\n");
- //读取中断状态寄存器清除中断标志以便释放NIRQ引脚
- //如果中断来了,那么NIRQ引脚会被拉低;如果这时候中断状态寄存器0x03和0x04被读取,那么NIRQ引脚会被释放恢复高电平
- ItStatus1 = SpiReadRegister(0x03); //read the Interrupt Status1 register
- ItStatus2 = SpiReadRegister(0x04); //read the Interrupt Status2 register
- //SW reset,软件复位这个模块主控芯片
- SpiWriteRegister(0x07, 0x80); //write 0x80 to the Operating & Function Control1 register
- // DelayMs(20);
- delay_ms(20);
- delay_ms(20);
- //wait for POR interrupt from the radio (while the nIRQ pin is high)
- //wait for chip ready interrupt from the radio (while the nIRQ pin is high)
- //等待软复位完成,当软复位完成后有中断发生。客户也可以在这里直接延时至少20ms而不用等待中断来;等待至少20ms后复位完成,这时候必须读中断状态寄存器释放中断引脚
- while ( NIRQ == 1);
- //read interrupt status registers to clear the interrupt flags and release NIRQ pin
- ItStatus1 = SpiReadRegister(0x03); //read the Interrupt Status1 register
- ItStatus2 = SpiReadRegister(0x04); //read the Interrupt Status2 register
- //根据不同的射频参数初始化射频模块;
- RF_init();
- UART_Send_Str("RF芯片si4432初始化完毕....\n");
- //Enable two interrupts:
- // a) one which shows that a valid packet received: 'ipkval'
- // b) second shows if the packet received with incorrect CRC: 'icrcerror'
- //设置中断使能寄存器,这里设置为只有当有效的数据包被接收或者接收到的数据包数据CRC校验出错才来中断;具体设置参考0x05和0x06寄存器
- SpiWriteRegister(0x05, 0x03); //write 0x03 to the Interrupt Enable 1 register
- SpiWriteRegister(0x06, 0x00); //write 0x00 to the Interrupt Enable 2 register
- //output dummy data.
- PB1_TX = 1;
- PB2_TX = 1;
- str = SEND_OUT_MESSAGE_WITH_ACK;
- sendLen = SEND_OUT_MESSAGE_WITH_ACK_LEN;
- //设置模块处于接收状态,当没有按键按下的时候一直处于接收状态,等待接收数据
- RFSetRxMode();
- UART_Send_Str("模块处于接收状态....\n");
- /*MAIN Loop*/
- while(1)
- {
- //当按键被按下就有一个数据包被发出;
- if(PB1_TX == 0)
- {
- while( PB1_TX == 0 );
- UART_Send_Str("按键按下,开始发送....\n");
- RFFIFOSendData(sendLen, str);
- //after packet transmission set the interrupt enable bits according receiving mode
- //Enable two interrupts:
- // a) one which shows that a valid packet received: 'ipkval'
- // b) second shows if the packet received with incorrect CRC: 'icrcerror'
- //设置中断使能寄存器,这里设置为只有当有效的数据包被接收或者接收到的数据包数据CRC校验出错才来中断;具体设置参考0x05和0x06寄存器
- SpiWriteRegister(0x05, 0x03); //write 0x03 to the Interrupt Enable 1 register
- SpiWriteRegister(0x06, 0x00); //write 0x00 to the Interrupt Enable 2 register
- //发射完毕后设置模块让它又工作在接收状态下;
- RFSetRxMode();
- UART_Send_Str("发送完毕,恢复到接收状态....\n");
- }
- //check whether interrupt occured
- //查询中断是否到来,如果中断来了,根据我们前面中断使能寄存器的设置,说明有效数据包已经收到,或者收到的数据包CRC校验出错;
- //如果客户采用中断触发的方式,那么服务程序必须包括这些内容。在中断服务程序中必须判断被使能的那些中断的状态位是否被置位,然后根据不同的
- //状态位进行处理
- if( NIRQ == 0 )
- {
- //设置模块处于空闲模式,处理收到的数据包,不继续接收数据
- RFSetIdleMode();
- UART_Send_Str("中断来了....\n");
- /*CRC Error interrupt occured*/
- //判断是否由于CRC校验出错引发的中断;在RFSetIdleMode中已经读出了中断状态寄存器的值
- if( (ItStatus1 & 0x01) == 0x01 )
- {
- //reset the RX FIFO
- //如果是CRC校验出错,那么接收FIFO复位;
- SpiWriteRegister(0x08, 0x02); //write 0x02 to the Operating Function Control 2 register
- SpiWriteRegister(0x08, 0x00); //write 0x00 to the Operating Function Control 2 register
- //blink all LEDs to show the error
- //闪灯提示,客户移植代码的时候这个闪灯操作根据不同客户不同操作
- // TurnOnAllLEDs();
- // DelayMs(2);
- UART_Send_Str("CRC校验出错中断....\n");
- // TurnOffAllLEDs();
- }
- /*packet received interrupt occured*/
- //判断是否是数据包已经被正确接收。
- if( (ItStatus1 & 0x02) == 0x02 )
- {
- //Read the length of the received payload
- //数据包已经被正确接收,读取收到的数据包长度
- length = SpiReadRegister(0x4B); //read the Received Packet Length register
- //根据长度判断相应的操作。客户可以不做这些,而直接从FIFO读出收到的数据;
- //check whether the received payload is not longer than the allocated buffer in the MCU
- if(length <= SNED_OUT_MSG_MAX_LEN)
- {
- //Get the reeived payload from the RX FIFO
- //直接从FIFO中读取收到的数据。客户只要读出FIFO的数据就算收到数据。
- for(temp8=0;temp8 < length;temp8++)
- {
- payload[temp8] = SpiReadRegister(0x7F); //read the FIFO Access register
- }
- for(temp8=0;temp8 < length;temp8++)
- {
- UART_Send_Byte(payload[temp8]); //向串口发送接收到的数据
- }
- UART_Send_Str("向串口发送接收到的数据....\n");
- //check whether the acknowledgement packet received
- //判断是否是预先设定的数据;一般应用情况客户可以不理会这个,这个判断只是我们demo板的应用。客户只要读出FIFO的数据就算收到数据;
- if(( length == SEND_OUT_ACK_LEN ) || (length == SEND_OUT_MESSAGE_NO_ACK_LEN))
- {
- if((memcmp(&payload[0], SEND_OUT_ACK, SEND_OUT_ACK_LEN - 1) == 0 )
- || (memcmp(&payload[0], SEND_OUT_MESSAGE_NO_ACK, SEND_OUT_MESSAGE_NO_ACK_LEN - 1) == 0))
- {
- //blink LED2 to show that ACK received
- // RxLEDOn();
- //Show the Rx LED for about 10ms
- UART_Send_Str("数据包已经被正确接收....\n");
- // DelayMs(2);
- // TurnOffAllLEDs();
- }
- }
- //check whether an expected packet received, this should be acknowledged
- //判断是否是需要发送回答信号的数据包。这个只是根据收到的数据做的不同操作,在客户那里可能是根据收到的数据做的特定的操作,例如控制某个开关
- if( length == SEND_OUT_MESSAGE_WITH_ACK_LEN )
- {
- //必须发送应答信号,启动发送
- if( memcmp(&payload[0], SEND_OUT_MESSAGE_WITH_ACK, SEND_OUT_MESSAGE_WITH_ACK_LEN - 1) == 0 )
- {
- //blink LED2 to show that the packet received
- //RxLEDOn();
- //Show the Rx LED for about 10ms
- // DelayMs(2);
- UART_Send_Str("发送应答....\n");
- // TurnOffAllLEDs();
- //发送应答信号。
- /*send back an acknowledgement*/
- RFFIFOSendData(SEND_OUT_ACK_LEN, SEND_OUT_ACK);
- //after packet transmission set the interrupt enable bits according receiving mode
- //Enable two interrupts:
- // a) one which shows that a valid packet received: 'ipkval'
- // b) second shows if the packet received with incorrect CRC: 'icrcerror'
- SpiWriteRegister(0x05, 0x03); //write 0x03 to the Interrupt Enable 1 register
- SpiWriteRegister(0x06, 0x00); //write 0x00 to the Interrupt Enable 2 register
- //read interrupt status registers to release all pending interrupts
- ItStatus1 = SpiReadRegister(0x03); //read the Interrupt Status1 register
- ItStatus2 = SpiReadRegister(0x04); //read the Interrupt Status2 register
- }
- }
- }
- }
- //reset the RX FIFO
- SpiWriteRegister(0x08, 0x02); //write 0x02 to the Operating Function Control 2 register
- SpiWriteRegister(0x08, 0x00); //write 0x00 to the Operating Function Control 2 register
- RFSetRxMode();
- }
- }
- }</pre>
- <p>
- </p>
- <br>
- <p>
- <br>
- </p>
多谢版主帮修饰,确实好看多了!
回LS的: 并不完全兼容,下面是我请世强的杨工提供的采用Si4438的部分代码,大家可以参考下,完整的代码可以找深圳世强的FAE杨工要。大家可以对比研究下。
- #include "compiler_defs.h"
- #include "c8051f960_defs.h"
- #include "hardware_defs.h"
- #include "control_IO.h"
- #include "spi.h"
- #include "Si446x_B0_defs.h"
- #include "ezrp_next_api.h"
- #include "modem_params.h"
- // Define capacitor bank value
- #define CAP_BANK_VALUE 0x48 // Capacitor bank value for adjusting the XTAL frequency
- // Note that it may varies on different test cards
- /*------------------------------------------------------------------------*/
- /* GLOBAL variables */
- /*------------------------------------------------------------------------*/
- // Set up modem parameters database; data is retrieved from modem_params.h header file which is
- // automatically generated by the WDS (Wireless Development Suite)
- SEG_CODE U8 ModemTrx1[] = {7, MODEM_MOD_TYPE_7};
- SEG_CODE U8 ModemTrx2[] = {5, MODEM_CLKGEN_BAND_5};
- SEG_CODE U8 ModemTrx3[] = {11, SYNTH_PFDCP_CPFF_11};
- SEG_CODE U8 ModemTrx4[] = {12, FREQ_CONTROL_INTE_12};
- SEG_CODE U8 ModemRx1[] = {11, MODEM_MDM_CTRL_11};
- SEG_CODE U8 ModemRx2[] = {14, MODEM_BCR_OSR_1_14};
- SEG_CODE U8 ModemRx3[] = {12, MODEM_AFC_GEAR_12};
- SEG_CODE U8 ModemRx4[] = {5, MODEM_AGC_CONTRL_5};
- SEG_CODE U8 ModemRx4_1[] = {7, MODEM_AGC_WINDOW_SIZE_7};
- SEG_CODE U8 ModemRx5[] = {9, MODEM_FSK4_GAIN1_9};
- SEG_CODE U8 ModemRx6[] = {8, MODEM_OOK_PDTC_8};
- SEG_CODE U8 ModemRx7[] = {8, MODEM_RAW_SEARCH_8};
- SEG_CODE U8 ModemRx8[] = {6, MODEM_ANT_DIV_MODE_6};
- SEG_CODE U8 ModemRx9[] = {13, MODEM_CHFLT_RX1_CHFLT_COE13_7_0_13};
- SEG_CODE U8 ModemRx10[] = {13, MODEM_CHFLT_RX1_CHFLT_COE4_7_0_13};
- SEG_CODE U8 ModemRx11[] = {13, MODEM_CHFLT_RX2_CHFLT_COE13_7_0_13};
- SEG_CODE U8 ModemRx12[] = {13, MODEM_CHFLT_RX2_CHFLT_COE4_7_0_13};
- /*------------------------------------------------------------------------*/
- /* LOCAL function prototypes */
- /*------------------------------------------------------------------------*/
- void MCU_Init(void);
- /*------------------------------------------------------------------------*/
- /* MAIN function */
- /*------------------------------------------------------------------------*/
- void main(void)
- {
- SEGMENT_VARIABLE(wDelay, U16, SEG_XDATA);
- SEGMENT_VARIABLE(bButtonNumber, U8, SEG_XDATA);
- BIT fValidPacket;
- //initialize the MCU peripherals
- MCU_Init();
- InitIO();
- // Reset the radio
- EZRP_PWRDN = 1;
- // Wait ~300us (SDN pulse width)
- for(wDelay=0; wDelay<330; wDelay++);
- // Wake up the chip from SDN
- EZRP_PWRDN = 0;
- // Wait for POR (power on reset); ~5ms
- for(wDelay=0; wDelay<5500; wDelay++);
- // Start the radio
- abApi_Write[0] = CMD_POWER_UP; // Use API command to power up the radio IC
- abApi_Write[1] = 0x01; // Write global control registers
- abApi_Write[2] = 0x00; // Write global control registers
- bApi_SendCommand(3,abApi_Write); // Send command to the radio IC
- // Wait for boot
- if (vApi_WaitforCTS()) // Wait for CTS
- {
- while (1) {} // Stop if radio power-up error
- }
- // Read ITs, clear pending ones
- abApi_Write[0] = CMD_GET_INT_STATUS; // Use interrupt status command
- abApi_Write[1] = 0; // Clear PH_CLR_PEND
- abApi_Write[2] = 0; // Clear MODEM_CLR_PEND
- abApi_Write[3] = 0; // Clear CHIP_CLR_PEND
- bApi_SendCommand(4,abApi_Write); // Send command to the radio IC
- bApi_GetResponse(8, abApi_Read ); // Make sure that CTS is ready then get the response
- // Set TRX parameters of the radio IC; data retrieved from the WDS-generated modem_params.h header file
- bApi_SendCommand(ModemTrx1[0],&ModemTrx1[1]); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- bApi_SendCommand(ModemTrx2[0],&ModemTrx2[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemTrx3[0],&ModemTrx3[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemTrx4[0],&ModemTrx4[1]);
- vApi_WaitforCTS();
- // Set Rx parameters of the radio IC
- bApi_SendCommand(ModemRx1[0],&ModemRx1[1]); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- bApi_SendCommand(ModemRx2[0],&ModemRx2[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx3[0],&ModemRx3[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx4[0],&ModemRx4[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx4_1[0],&ModemRx4_1[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx5[0],&ModemRx5[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx6[0],&ModemRx6[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx7[0],&ModemRx7[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx8[0],&ModemRx8[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx9[0],&ModemRx9[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx10[0],&ModemRx10[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx11[0],&ModemRx11[1]);
- vApi_WaitforCTS();
- bApi_SendCommand(ModemRx12[0],&ModemRx12[1]);
- vApi_WaitforCTS();
- // Enable packet received and CRC error interrupt only
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_INT_CTL_GROUP; // Select property group
- abApi_Write[2] = 4; // Number of properties to be written
- abApi_Write[3] = PROP_INT_CTL_ENABLE; // Specify property
- abApi_Write[4] = 0x01; // INT_CTL: PH interrupt enabled
- abApi_Write[5] = 0x18; // INT_CTL_PH: PH PACKET_RX & CRC2_ERR interrupt enabled
- abApi_Write[6] = 0x00; // INT_CTL_MODEM: -
- abApi_Write[7] = 0x00; // INT_CTL_CHIP_EN: -
- bApi_SendCommand(8,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Configure Fast response registers
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_FRR_CTL_GROUP; // Select property group
- abApi_Write[2] = 4; // Number of properties to be written
- abApi_Write[3] = PROP_FRR_CTL_A_MODE; // Specify property (1st)
- abApi_Write[4] = 0x04; // FRR A: PH IT pending
- abApi_Write[5] = 0x06; // FRR B: Modem IT pending
- abApi_Write[6] = 0x0A; // FRR C: Latched RSSI
- abApi_Write[7] = 0x00; // FRR D: disabled
- bApi_SendCommand(8,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- //Set packet content
- //Set preamble length
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_PREAMBLE_GROUP; // Select property group
- abApi_Write[2] = 1; // Number of properties to be written
- abApi_Write[3] = PROP_PREAMBLE_CONFIG_STD_1; // Specify property
- abApi_Write[4] = 20; // 20 bits preamble detection threshold
- bApi_SendCommand(5,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Set preamble pattern
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_PREAMBLE_GROUP; // Select property group
- abApi_Write[2] = 1; // Number of properties to be written
- abApi_Write[3] = PROP_PREAMBLE_CONFIG; // Specify property
- abApi_Write[4] = 0x31; // Use `1010` pattern, length defined in bytes
- bApi_SendCommand(5,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Set sync word
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_SYNC_GROUP; // Select property group
- abApi_Write[2] = 3; // Number of properties to be written
- abApi_Write[3] = PROP_SYNC_CONFIG; // Specify property
- abApi_Write[4] = 0x01; // SYNC_CONFIG: 2 bytes sync word
- abApi_Write[5] = 0xB4; // SYNC_BITS_31_24: 1st sync byte: 0x2D; NOTE: LSB transmitted first!
- abApi_Write[6] = 0x2B; // SYNC_BITS_23_16: 2nd sync byte: 0xD4; NOTE: LSB transmitted first!
- bApi_SendCommand(7,abApi_Write); // Send command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // General packet config (set bit order)
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_PKT_GROUP; // Select property group
- abApi_Write[2] = 1; // Number of properties to be written
- abApi_Write[3] = PROP_PKT_CONFIG1; // Specify property
- abApi_Write[4] = 0x00; // Payload data goes MSB first
- bApi_SendCommand(5,abApi_Write); // Send command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Set RSSI latch to sync word
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_MODEM_GROUP; // Select property group
- abApi_Write[2] = 1; // Number of properties to be written
- abApi_Write[3] = PROP_MODEM_RSSI_CONTROL; // Specify property
- abApi_Write[4] = 0x12; // RSSI average over 4 bits, latch at sync detect
- bApi_SendCommand(5,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Configure the GPIOs
- abApi_Write[0] = CMD_GPIO_PIN_CFG; // Use GPIO pin configuration command
- #ifdef ONE_SMA_WITH_RF_SWITCH
- // If RF switch is used
- // Select Tx state to GPIO2, Rx state to GPIO0
- abApi_Write[1] = 0x21; // Configure GPIO0 as Rx state
- abApi_Write[2] = 0x13; // Configure GPIO1 as Tx data
- abApi_Write[3] = 0x20; // Configure GPIO2 as Tx state
- abApi_Write[4] = 0x10; // Configure GPIO3 as Tx data CLK
- #else
- abApi_Write[1] = 0x10; // Configure GPIO0 as Tx data CLK
- abApi_Write[2] = 0x13; // Configure GPIO1 as Tx data
- abApi_Write[3] = 0x20; // Configure GPIO2 as Tx state
- abApi_Write[4] = 0x21; // Configure GPIO3 as Rx state
- #endif
- bApi_SendCommand(5,abApi_Write); // Send command to the radio IC
- vApi_WaitforCTS();
- // Adjust XTAL clock frequency
- abApi_Write[0] = CMD_SET_PROPERTY; // Use property command
- abApi_Write[1] = PROP_GLOBAL_GROUP; // Select property group
- abApi_Write[2] = 1; // Number of properties to be written
- abApi_Write[3] = PROP_GLOBAL_XO_TUNE; // Specify property
- abApi_Write[4] = CAP_BANK_VALUE; // Set cap bank value to adjust XTAL clock frequency
- bApi_SendCommand(5,abApi_Write); // Send command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Read ITs, clear pending ones
- abApi_Write[0] = CMD_GET_INT_STATUS; // Use interrupt status command
- abApi_Write[1] = 0; // Clear PH_CLR_PEND
- abApi_Write[2] = 0; // Clear MODEM_CLR_PEND
- abApi_Write[3] = 0; // Clear CHIP_CLR_PEND
- bApi_SendCommand(4,abApi_Write); // Send command to the radio IC
- bApi_GetResponse(8,abApi_Read); // Get the response
- // Start Rx
- abApi_Write[0] = CMD_START_RX; // Use start Rx command
- abApi_Write[1] = 0; // Set channel number
- abApi_Write[2] = 0x00; // Start Rx immediately
- abApi_Write[3] = 0x00; // 8 bytes to receive
- abApi_Write[4] = 0x08; // 8 bytes to receive
- abApi_Write[5] = 0x00; // No change if Rx timeout
- abApi_Write[6] = 0x03; // Ready state after Rx
- abApi_Write[7] = 0x03; // Ready state if Rx invalid
- bApi_SendCommand(8,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- // Turn off LEDs
- ClearLed(1);
- ClearLed(2);
- ClearLed(3);
- ClearLed(4);
- while(1)
- {
- if(EZRP_NIRQ == 0)
- {
- // Read PH IT registers to see the cause for the IT
- abApi_Write[0] = CMD_GET_PH_STATUS; // Use packet handler status command
- abApi_Write[1] = 0x00; // Dummy byte for a proper CTS response
- bApi_SendCommand(2,abApi_Write); // Send command to the radio IC
- bApi_GetResponse(1,abApi_Read); // Make sure that CTS is ready then get the response
- if((abApi_Read[0] & 0x10) == 0x10) // Check if packet received
- {// Packet received
- // Get RSSI
- bApi_GetFastResponseRegister(CMD_FAST_RESPONSE_REG_C,1,abApi_Read);
- // Read the FIFO
- bApi_ReadRxDataBuffer(8,abApi_Read);
- fValidPacket = 0;
- // Check the packet content
- if ((abApi_Read[0]=='B') && (abApi_Read[1]=='U') && (abApi_Read[2]=='T') && (abApi_Read[3]=='T') && (abApi_Read[4]=='O') && (abApi_Read[5]=='N'))
- {
- bButtonNumber = abApi_Read[6] & 0x07; // Get button info
- if((bButtonNumber > 0) && (bButtonNumber < 5))
- {
- SetLed(bButtonNumber); // Turn on the appropriate LED
- for(wDelay=0; wDelay<30000; wDelay++); // Wait to show LED
- ClearLed(bButtonNumber); // Turn off the corresponding LED
- fValidPacket = 1;
- }
- }
- // Packet content is not what was expected
- if(fValidPacket == 0)
- {
- SetLed(1); // Blink all LEDs
- SetLed(2);
- SetLed(3);
- SetLed(4);
- for(wDelay=0; wDelay<30000; wDelay++);
- ClearLed(1);
- ClearLed(2);
- ClearLed(3);
- ClearLed(4);
- }
- }
- // Read ITs, clear pending ones
- abApi_Write[0] = CMD_GET_INT_STATUS; // Use interrupt status command
- abApi_Write[1] = 0; // Clear PH_CLR_PEND
- abApi_Write[2] = 0; // Clear MODEM_CLR_PEND
- abApi_Write[3] = 0; // Clear CHIP_CLR_PEND
- bApi_SendCommand(4,abApi_Write); // Send command to the radio IC
- bApi_GetResponse(8,abApi_Read); // Get the response
- // Start Rx
- abApi_Write[0] = CMD_START_RX; // Use start Rx command
- abApi_Write[1] = 0; // Set channel number
- abApi_Write[2] = 0x00; // Start Rx immediately
- abApi_Write[3] = 0x00; // 8 bytes to receive
- abApi_Write[4] = 0x08; // 8 bytes to receive
- abApi_Write[5] = 0x00; // No change if Rx timeout
- abApi_Write[6] = 0x03; // Ready state after Rx
- abApi_Write[7] = 0x03; // Ready if Rx invalid
- bApi_SendCommand(8,abApi_Write); // Send API command to the radio IC
- vApi_WaitforCTS(); // Wait for CTS
- }
- }
- }
si4438 cca 侦听的更多相关文章
- Unity3D 自定义事件(事件侦听与事件触发)
先来看下效果图,图中点击 Cube(EventDispatcher),Sphere(EventListener)以及 Capsule(EventListener)会做出相应的变化,例子中的对象相互之间 ...
- wcf 由 http 更改为 https 返回404,没有终结点在侦听可以接受消息的
首先wcf项目在使用http时是没问题的. WCF有http更改为https之后,返回 没有终结点在侦听可以接受消息 需要修改wcf服务端及客户端 服务端更改代码 <binding maxRec ...
- 用php模拟做服务端侦听端口
参考:http://www.cnblogs.com/thinksasa/archive/2013/02/26/2934206.html http://blog.csdn.net/alongken200 ...
- 关于如何获取/清除 MAXScript 侦听器内的文本
关于如何获取/清除 MAXScript 侦听器内的文本 用来保存记录?还没想到实际用处,先记上. macroRecorder as string listener as stringclearList ...
- WCF:没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的。
没有终结点在侦听可以接受消息的 http://xx.com/WebService.svc. 这通常是由于不正确的地址或者 SOAP 操作导致的.如果存在此情况,请参见 InnerException 以 ...
- WCF: 没有终结点在侦听可以接受消息的 这通常是由于不正确的地址或者 SOAP 操作导致的。
问题: 由于我这里的wcf服务是采用“BasicHttpBinding”的方式,即安全绑定模式,客户端在引用这个服务后所生成的终结点配置(endpoint )就变成了<endpoint ...
- Android Listener侦听的N种写法
Android中,View的Listener方法,在是否使用匿名类匿名对象时,有各种不同的写法. OnClickListener和其他Listener方法一样,都是View类的接口,重载实现后就能使用 ...
- 客服端调用自定义宿主的WCF报错"没有终结点在侦听可以接受消息的http://localhost:8085/mex。这通常是由于不正确的地址或者 SOAP 操作导致的错误"的解决方案。
没有终结点在侦听可以接受消息的http://localhost:8085/mex.这通常是由于不正确的地址或者 SOAP 操作导致的错误. 这个错误是由于没有启动元数据交换终结点(MEX)导致的.在宿 ...
- GSM短信侦听的便宜方案
侦听GSM短信常用的是OsmocomBB + C118方案,主要是用luca/gsmmap分支.使用ccch_scan这个程序可以把通信封装成GSMTAP发给本机,然后用WireShark接收GSMT ...
随机推荐
- Mybatis中的@SelectKey注解
一.创建Maven项目 在pom.xml中,添加mybatis依赖,mysql-jdbc依赖,把编译版本改为1.8 你问,为啥mybatis不会自动依赖mysql-jdbc,需要手动写明?答:因为my ...
- Java优化技巧
过早的优化是万恶之源. 优化了的代码可读性变差,可改性可适应性变差,可维护性变差. 远离过度优化,优化是个无底洞,把主要精力放在代码逻辑上. 优化的代码是活在当下的,是严重依赖硬件的,不利于表达永恒的 ...
- JavaScript(select onchange)的网页跳转的简单实现
方法一: <select onchange="goUrl(this.options[this.selectedIndex])"> <option>==& ...
- plsql连接oralce数据的配置 PLSQL配置怎么连ORACLE plsql连接多个数据库设置 Oracle 服务命名(别名)的配置及原理,plsql连接用
Oracle 服务命名(别名)的配置及原理,plsql连接用 Oracle 服务命名(别名)的配置及原理 连接数据库必须配置服务命名(别名,用于plsql的连接),不管是本地还是远程,服务命名即简单命 ...
- pythonl练习笔记——threading创建进程锁Lock()
1 基本概述 采用threading.Lock()对象创建锁lock,即 lock = threading.Lock() 其相关方法主要有 lock.acquire() # lock the lock ...
- Python学习笔记11:标准库之文件管理(os包,shutil包)
1 os包 os包包含各种各样的函数,以实现操作系统的很多功能.这个包很庞杂.os包的一些命令就是用于文件管理. 我们这里列出最经常使用的: mkdir(path) 创建新文件夹.path为一个字符串 ...
- Ruby的DevKit名词解释
为了加快运行速度,Ruby下好多扩展包都是用C语言写的二进制包,如果我们要安装就要重新编译,DevKit包主要就是将编译用的工具链打包,解决了众多依赖问题,方便了群众. 但是,在实际安装中,可能还会遇 ...
- string.format的用途联想
还有IFormattable,感觉这辈子都用不到.. 设想了一个物品简介界面 分别是Title,分割线,内容. "{0:Red} \n {1:S1} \n 简介 \n {2:Green}&q ...
- [na]tcpdump参数应用参考
详细参数参考,我记得之前有个ppt关于这个写的不错. 说实话,这玩意用的时候直接gg了. 常用应用: 过滤物理口 过滤某个port/ip/mac 过滤协议 显示ip/mac/port不解析等 一 tc ...
- 【Anroid】9.1 ListView相关类及其适配器
分类:C#.Android.VS2015: 创建日期:2016-02-18 一.简介 列表视图(ListView)是Android应用程序中使用最频繁的UI组件,从无处不在短菜单选项列表到冗长的联系人 ...