1、unsigned char Data_Len;typedef enum _RF_ENUM RF_OK = 0x00, /function response parameters RF_ERROR_TIMING0x01, RF_ERROR_PARAMETER = 0x02, RF_PACKET_RECEIVED= 0x03, RF_NO_PACKET=0x04, RF_CRC_ERROR = 0x05, RF_ENUM;/-RF4432 配置寄存器地址-#define DEVICE_TYPE 0x00#define EVICE_VERSION0x01/版本号#define DEVICE_STAT
2、US0x02/设备状态#define INTERRUPT_STATUS_10x03#define INTERRUPT_STATUS_20x04#define INTERRUPT_ENABLE_1 0x05#define INTERRUPT_ENABLE_2 0x06#define OPERATING_FUNCTION_CONTROL_10x07 /工作模式和功能控制1#define OPERATING_FUNCTION_CONTROL_2 0x08 /工作模式和功能控制2#define CRYSTAL_OSCILLATOR_LOAD_CAPACITANCE0x09 /晶振负载电容设置#defi
3、ne MICROCONTROLLER_OUTPUT_CLOCK 0x0A#define GPIO0_CONFIGURATION 0x0B /GPIO0功能设置寄存器见英文文档第105页#define GPIO1_CONFIGURATION0x0C#define GPIO2_CONFIGURATION 0x0D#define IO_PORT_CONFIGURATION 0x0E#define ADC_CONFIGURATION0x0F#define ADC_SENSOR_AMPLIFIER_OFFSET0x10#define ADC_VALUE 0x11#define TEMPERATURE_S
4、ENSOR_CONTROL0x12 /温度传感器校准#define TEMPERATURE_VALUE_OFFSET 0x13#define WAKE_UP_TIMER_PERIOD_10x14#define WAKE_UP_TIMER_PERIOD_20x15#define WAKE_UP_TIMER_PERIOD_30x16#define WAKE_UP_TIMER_VALUE_1 0x17#define WAKE_UP_TIMER_VALUE_2 0x18#define LOW_DUTY_CYCLE_MODE_DURATION 0x19#define LOW_BATTERY_DETECT
5、OR_THRESHOLD0x1A /低压检测阈值寄存器#define BATTERY_VOLTAGE_LEVEL0x1B#define IF_FILTER_BANDWIDTH 0x1C /中频滤波器带宽寄存器#define AFC_LOOP_GEARSHIFT_OVERRIDE 0x1D#define AFC_TIMING_CONTROL0x1E#define CLOCK_RECOVERY_GEARSHIFT_OVERRIDE0x1F#define CLOCK_RECOVERY_OVERSAMPLING_RATIO 0x20#define CLOCK_RECOVERY_OFFSET_2 0x2
6、1#define CLOCK_RECOVERY_OFFSET_10x22#define CLOCK_RECOVERY_OFFSET_0 0x23#define CLOCK_RECOVERY_TIMING_LOOP_GAIN_10x24#define CLOCK_RECOVERY_TIMING_LOOP_GAIN_0 0x25#define RECEIVED_SIGNAL_STRENGTH_INDICATOR 0x26#define RSSI_THRESHOLD_FOR_CLEAR_CHANNEL_INDICATOR 0x27#define ANTENNA_DIVERSITY_REGISTER_
7、1 0x28#define ANTENNA_DIVERSITY_REGISTER_2 0x29#define DATA_ACCESS_CONTROL 0x30#define EZMAC_STATUS 0x31#define HEADER_CONTROL_1 0x32 /Header 起始码设置#define HEADER_CONTROL_2 0x33#define PREAMBLE_LENGTH0x34 /前导码长度#define PREAMBLE_DETECTION_CONTROL0x35 /前导码检测设置#define SYNC_WORD_3 0x36 /同步字节#define SYNC_
8、WORD_2 0x37#define SYNC_WORD_10x38#define SYNC_WORD_0 0x39#define TRANSMIT_HEADER_3 0x3A#define TRANSMIT_HEADER_2 0x3B#define TRANSMIT_HEADER_1 0x3C#define TRANSMIT_HEADER_00x3D#define TRANSMIT_PACKET_LENGTH0x3E /发送数据包长度,详细请看P125页#define CHECK_HEADER_30x3F#define CHECK_HEADER_20x40#define CHECK_HEAD
9、ER_1 0x41#define CHECK_HEADER_00x42#define HEADER_ENABLE_3 0x43#define HEADER_ENABLE_2 0x44#define HEADER_ENABLE_1 0x45#define HEADER_ENABLE_0 0x46#define RECEIVED_HEADER_3 0x47#define RECEIVED_HEADER_2 0x48#define RECEIVED_HEADER_1 0x49#define RECEIVED_HEADER_0 0x4A#define RECEIVED_PACKET_LENGTH0x4
10、B /接收数据包长度,详细请看P134页#define ANALOG_TEST_BUS0x50#define DIGITAL_TEST_BUS_ENSCTEST_ 0x51#define TX_RAMP_CONTROL0x52#define PLL_TUNE_TIME0x53 /锁相环切换时间#define CALIBRATION_CONTROL0x55#define MODEM_TEST0x56#define CHARGEPUMP_TEST0x57#define CHARGEPUMP_CURRENT_TRIMMING_OVERRIDE0x58#define DIVIDER_CURRENT_T
11、RIMMING0x59#define VCO_CURRENT_TRIMMING0x5A#define VCO_CALIBRATION_OVERRIDE 0x5B#define SYNTHESIZER_TEST0x5C#define BLOCK_ENABLE_OVERRIDE_10x5D#define BLOCK_ENABLE_OVERRIDE_20x5E#define BLOCK_ENABLE_OVERRIDE_30x5F#define CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60#define CHANNEL_FILTER_COEFFICIENT_VALUE
12、 0x61#define CRYSTAL_OSCILLATOR_CONTROL_TEST0x62#define RC_OSCILLATOR_COARSE_CALIBRATION_OVERRIDE 0x63#define RC_OSCILLATOR_FINE_CALIBRATION_OVERRIDE0x64#define LDO_CONTROL_OVERRIDE_ENSPOR0x65#define LDO_LEVEL_SETTING0x66#define DELTASIGMA_ADC_TUNING_10x67#define DELTASIGMA_ADC_TUNING_20x68#define A
13、GC_OVERRIDE_10x69#define AGC_OVERRIDE_20x6A#define GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6B#define GFSK_FIR_FILTER_COEFFICIENT_VALUE0x6C#define TX_POWER0x6D/发射功率设置,详细请见P153#define TX_DATA_RATE_1 0x6E /数据发送波特率设置寄存器1#define TX_DATA_RATE_0 0x6F /数据发送波特率设置寄存器0#define MODULATION_MODE_CONTROL_10x70 /调制方式控
14、制,详细请见P155#define MODULATION_MODE_CONTROL_2 0x71#define FREQUENCY_DEVIATION0x72#define FREQUENCY_OFFSET_10x73#define FREQUENCY_OFFSET_20x74#define FREQUENCY_BAND_SELECT 0x75 /频段选择,详细请见P157#define NOMINAL_CARRIER_FREQUENCY_10x76 /基准载波频率#define NOMINAL_CARRIER_FREQUENCY_00x77#define FREQUENCY_HOPPING_
15、CHANNEL_SELECT 0x79 /跳频频道选择,详细请见P158#define FREQUENCY_HOPPING_STEP_SIZE 0x7A /跳频频道间隔#define TX_FIFO_CONTROL_10x7C#define TX_FIFO_CONTROL_2 0x7D#define RX_FIFO_CONTROL 0x7E#define FIFO_ACCESS 0x7F/FIFO读写方式设置,/-RF4432控制指令-#define RR 0x00#define WR 0x80/-延时-void delay_10us(char n) int i; while(n-) for(
16、i=0;i5;i+);void delay_ms(int num) int x,y; for(y=0;ynum;y+) for(x = 0;x 500;x) x+; /-SPI单字节读取函数-unsigned char SPI_Read(void) unsigned char i,rxdata; rxdata = 0x00; for (i = 0;i 8;i+) rxdata = rxdata1; RF4432_SCLK=1; RF4432_SDO=1; if (RF4432_SDO=1) /读取最高位,保存至最末尾,通过左移位完成整个字节 rxdata |= 0x01; else rxdat
17、a &= 0x01; delay_10us(2); RF4432_SCLK=0;return rxdata;/-SPI单字节写入函数-void SPI_Write(unsigned char txdata) unsigned char i; if (txdata&0x80) /总是发送最高位RF4432_SDI=1;RF4432_SDI=0; txdata = txdata/-RF4432寄存器读取函数-voidRF4432_ReadReg(unsigned charaddr, unsigned char *RegisterData) RF4432_SEL=0; SPI_Write(addr|
18、RR); *RegisterData = SPI_Read(); RF4432_SEL=1;/-RF4432寄存器写入函数-RF4432_WriteReg(unsigned charaddr, unsigned char value) SPI_Write(addr|WR); SPI_Write(value);/-RF4432寄存器读取函数-void RF4432_ReadBurestReg(unsigned charaddr,unsigned char*p,unsigned charcount) for(i=0;count; pi = SPI_Read();/-RF4432射频芯片初始化函数-void RF4432_Init(void)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1