本帖最后由 lazy 于 2024-11-7 18:45 编辑
闲聊
没错SI4432无线模块就是它。淘宝安信可买的,看到说送天线。等了三天到件以后来就发了三个SI4432无线模块。没有发天线。然后找客服,顺道又买了一个Ai-WB2-32s开发板。又等了三天收到了天线和开发板。
搞了很久的代码,然后发现开发环境和代码都不是很好调试。
索性换了Ai-M61-32S开发板。稍微还熟悉点。
安信可的开发板配安信可模块,才是丰富生态😄
这个资料真的是太少了,SPI教程也缺失ing。完全一脸懵逼的调试。
硬件就三样 开发板、线、模块
哪儿出问题了都不知道,波形有没有,有没有发送数据出去,模块有没有响应肉眼看不出来。
然后为了测试打印了一堆日志,为了看引脚状态。
[F][] RF4432_ReadReg addr: 0x01
[F][] SPI_Write txdata: 0x01
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_0
[F][] SPI_Write RF4432_SDI_1
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read RF4432_SDO_IN 1
[F][] SPI_Read RF4432_SDO_IN 1
[F][] SPI_Read RF4432_SDO_IN 0
[F][] SPI_Read rxdata: 0x06
[F][] ver: 0x06
经过四天的掉头发终于是调通了SI4432模块,下面分享下遇到的问题和当前效果。最终是想做一个串口通讯的语音提示门铃。模块调通了先把功能代码放出来给需要的朋友。后续逐渐完善功能。
问题
1、SI4432 间距很小,焊接一定注意不要连锡。
产生影响,获取数据不准确。
测试方法:万用表打到二极管档位,然后测量相邻两个引脚时候导通。如果导通了就连锡了。(断电操作)
检查模块电压是否正常。
测试方法:万用表打到20V电压档位,黑表笔接GND。分别测试VCC、SDO、SDI、SCLK、nSEL、nIRQ、SDN
默认情况下除SCLK与SDN为0V外,其他接口都是3.3v如果电压差的很多就要检查是否连锡了。
2、SDN 引脚是需要拉低
产生影响,读出来的数据都是ff或者不准确乱跳
3、Ai-M61-32 MISO 引脚初始化不要悬空
产生影响,读数不正确,以为读到数据了,结果发现不带设备读针脚状态也是有值的。
输出高低电平的引脚直接设置GPIO_OUTPUT
读取高低电平的引脚直接设置GPIO_INPUT
4、模块是3.3V供电的,最好不要用5V
产生影响,可能导致永远也读不到数据,就不告诉你为什么。
目标
拿到Device Version:06
其他完整内容看下数据手册吧,内容比较多。
接线方式
Ai-M6x |
SI4432 |
SI4432引脚定义 |
3v3 |
VCC |
3.3v电源 |
IO18 |
SDO |
串行数据输出 |
IO19 |
SDI |
串行数据输入 |
IO13 |
SCLK |
串行时钟输入 |
IO12 |
nSEL |
串行接口选择输入 |
IO31 |
nIRQ |
中断输出引脚 |
IO30 |
SDN |
关闭输入引脚[启用停用设备] |
IO27 |
GPIO0 |
模块发射控制引脚 |
GND |
GND |
接地 |
SI4432无线模块
SI4432无线模块由安信可科技设计开发。该模块采用Silicon Labs最新版本的高集成度的无线ISM收发芯片SI4432。频率范围为410~525MHz,极高的接收灵敏(-117dBm)和发射功率(+20dBm),大大提高了穿透能力和传输范围,在+20dBm输出功率时开阔无障碍的通信距离在1000米以上。用户不需要了解无线电的相关知识,就可以使用本模块轻易的开发出性能稳定可靠的无线相关产品。
BS01 无线模块由安信可科技设计开发,该模块是一款低功耗、小尺寸、低成本的 Sub-1G 射频模块;采用 Silicon Laboratories公司的 Si4463 芯片是高性能的低电流收发器,其覆盖了119MHz至1050MHz的Sub-1GHz频段。还是EZRadioPRO系列的一部分,该系列包含覆盖各种应用的完整发射器、接收器和收发器产品线。所有器件都具有接触的的灵敏度-126dBm,同时实现了极低的活动和休眠电流消耗。
模块特性 开发资料 规格书 硬件资料
接口定义
详细描述
SI4432 采用的是SPI通讯方式,目前使用官方提供的spi类库没有调通。用软模拟的方式实现SPI通信。
SI4432无线模块串行接口时序参考。
代码
si4432.h
#ifndef _SI4432_H_
#define _SI4432_H_
#include "bflb_mtimer.h"
#include "board.h"
#include "bflb_gpio.h"
#include "log.h"
#include <FreeRTOS.h>
#include <queue.h>
#include <timers.h>
#include <task.h>
// 收发模式切换控制端
#define PAC_PIN GPIO_PIN_27
// SDN
#define SDN_PIN GPIO_PIN_30
// nIrq
#define IRQ_PIN GPIO_PIN_31
// 片选
#define SPI_CS_PIN GPIO_PIN_12
// 时钟
#define SPI_CLK_PIN GPIO_PIN_13
// 主机输入从机输出
#define SPI_MISO_PIN GPIO_PIN_18
// 从机输入主机输出
#define SPI_MOSI_PIN GPIO_PIN_19
//-----------------------------------------------------RF4432配置口定义---------------------------------------------
#define RF4432_PAC_1 bflb_gpio_set(gpio, PAC_PIN) //收发模式切换控制端
#define RF4432_PAC_0 bflb_gpio_reset(gpio, PAC_PIN)
//#define RF4432_SDO_1 (P2OUT |= BIT3) //SPI数据输出
//#define RF4432_SDO_0 (P2OUT &= ~BIT3)
#define RF4432_SDO_IN bflb_gpio_read(gpio, SPI_MISO_PIN)
#define RF4432_SDI_1 bflb_gpio_set(gpio, SPI_MOSI_PIN)//SPI数据输入
#define RF4432_SDI_0 bflb_gpio_reset(gpio, SPI_MOSI_PIN)
#define RF4432_SCLK_1 bflb_gpio_set(gpio, SPI_CLK_PIN)//SPI时钟输入端口
#define RF4432_SCLK_0 bflb_gpio_reset(gpio, SPI_CLK_PIN)
#define RF4432_SEL_1 bflb_gpio_set(gpio, SPI_CS_PIN) //SPI片选
#define RF4432_SEL_0 bflb_gpio_reset(gpio, SPI_CS_PIN)
#define RF4432_SDN_1 bflb_gpio_set(gpio, SDN_PIN) //SDN=1时关闭芯片工作 ,SDN=0时芯片正常工作
#define RF4432_SDN_0 bflb_gpio_reset(gpio, SDN_PIN)
//#define RF4432_IRQ_1 (P2OUT |= BIT0) //SI4432工作状态指示端口
//#define RF4432_IRQ_0 (P2OUT &= ~BIT0)
#define RF4432_IRQ_IN bflb_gpio_read(gpio, IRQ_PIN)
//------------------------------------------------------------------------------------------------------------------
//#define RF4432_IO0_1 (P1OUT |= BIT5) //IO-0可以不用
//#define RF4432_IO0_0 (P1OUT &= ~BIT5)
//#define RF4432_IO1_1 (P1OUT |= BIT6) //IO-1可以不用
//#define RF4432_IO1_0 (P1OUT &= ~BIT6)
//#define RF4432_IO2_1 (P1OUT |= BIT4) //IO-2可以不用
//#define RF4432_IO2_0 (P1OUT &= ~BIT4)
//-------------------------------------------射频芯片相关定义--------------------------------
#define RF4432_TxRxBuf_Len 32 //定义RF4432数据包长度
static uint8_t RF4432_TxRxBuf[RF4432_TxRxBuf_Len]=
{
0x01,0x02,0x03,0x4,0x05,0x06,0x07,0x08,
0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,
0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,
};
//---------------------RF4432 配置寄存器地址--------------------//
#define DEVICE_TYPE 0x00 //器件类型码
#define DEVICE_VERSION 0x01 //版本号
#define DEVICE_STATUS 0x02 //器件状态
#define INTERRUPT_STATUS_1 0x03 //中断状态1
#define INTERRUPT_STATUS_2 0x04 //中断状态2
#define INTERRUPT_ENABLE_1 0x05 //中断使能1
#define INTERRUPT_ENABLE_2 0x06 //中断使能2
#define OPERATING_FUNCTION_CONTROL_1 0x07 //工作模式和功能控制1
#define OPERATING_FUNCTION_CONTROL_2 0x08 //工作模式和功能控制2
#define CRYSTAL_OSCILLATOR_LOAD_CAPACITANCE 0x09 //晶振负载电容设置
#define MICROCONTROLLER_OUTPUT_CLOCK 0x0A //微控制器输出时钟
#define GPIO0_CONFIGURATION 0x0B //GPIO0功能设置寄存器见英文文档第105页
#define GPIO1_CONFIGURATION 0x0C
#define GPIO2_CONFIGURATION 0x0D
#define IO_PORT_CONFIGURATION 0x0E //IO端口配置
#define ADC_CONFIGURATION 0x0F //ADC配置
#define ADC_SENSOR_AMPLIFIER_OFFSET 0x10 //ADC传感放大器偏差
#define ADC_VALUE 0x11 //ADC值
#define TEMPERATURE_SENSOR_CONTROL 0x12 //温度传感器校准
#define TEMPERATURE_VALUE_OFFSET 0x13 //温度传感器值偏差
#define WAKE_UP_TIMER_PERIOD_1 0x14 //唤醒定时器时期1
#define WAKE_UP_TIMER_PERIOD_2 0x15 //唤醒定时器时期2
#define WAKE_UP_TIMER_PERIOD_3 0x16 //唤醒定时器时期3
#define WAKE_UP_TIMER_VALUE_1 0x17 //唤醒定时器值1
#define WAKE_UP_TIMER_VALUE_2 0x18 //唤醒定时器值2
#define LOW_DUTY_CYCLE_MODE_DURATION 0x19 //低任务周期模式持续时间
#define LOW_BATTERY_DETECTOR_THRESHOLD 0x1A //低压检测阈值寄存器
#define BATTERY_VOLTAGE_LEVEL 0x1B //电池电压级别
#define IF_FILTER_BANDWIDTH 0x1C //中频滤波器(IF)带宽寄存器
#define AFC_LOOP_GEARSHIFT_OVERRIDE 0x1D //AFC循环变速超速
#define AFC_TIMING_CONTROL 0x1E //AFC定时控制
#define CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1F //时钟恢复变速超速
#define CLOCK_RECOVERY_OVERSAMPLING_RATIO 0x20 //时钟恢复过抽样率
#define CLOCK_RECOVERY_OFFSET_2 0x21 //时钟恢复偏差
#define CLOCK_RECOVERY_OFFSET_1 0x22
#define CLOCK_RECOVERY_OFFSET_0 0x23
#define CLOCK_RECOVERY_TIMING_LOOP_GAIN_1 0x24 //时钟恢复定时循环增益
#define CLOCK_RECOVERY_TIMING_LOOP_GAIN_0 0x25
#define RECEIVED_SIGNAL_STRENGTH_INDICATOR 0x26 //接收信号强度指示器(RSSI)
#define RSSI_THRESHOLD_FOR_CLEAR_CHANNEL_INDICATOR 0x27 //无干扰信道指示器接收信号强度指示(RSSI)
#define ANTENNA_DIVERSITY_REGISTER_1 0x28 //天线分集
#define ANTENNA_DIVERSITY_REGISTER_2 0x29
#define DATA_ACCESS_CONTROL 0x30 //时间存储控制
#define EZMAC_STATUS 0x31 //EzMAC状态
#define HEADER_CONTROL_1 0x32 //Header 起始码设置
#define HEADER_CONTROL_2 0x33
#define PREAMBLE_LENGTH 0x34 //前导码长度
#define PREAMBLE_DETECTION_CONTROL 0x35 //前导码检测设置
#define SYNC_WORD_3 0x36 //同步字节
#define SYNC_WORD_2 0x37
#define SYNC_WORD_1 0x38
#define SYNC_WORD_0 0x39
#define TRANSMIT_HEADER_3 0x3A //发射帧头
#define TRANSMIT_HEADER_2 0x3B
#define TRANSMIT_HEADER_1 0x3C
#define TRANSMIT_HEADER_0 0x3D
#define TRANSMIT_PACKET_LENGTH 0x3E //发送数据包长度,详细请看P125页
#define CHECK_HEADER_3 0x3F //检测帧头
#define CHECK_HEADER_2 0x40
#define CHECK_HEADER_1 0x41
#define CHECK_HEADER_0 0x42
#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_LENGTH 0x4B //接收数据包长度,详细请看P134页
#define ANALOG_TEST_BUS 0x50 //模拟测试总线选择
#define DIGITAL_TEST_BUS_ENSCTEST_ 0x51 //数据测试总线选择
#define TX_RAMP_CONTROL 0x52 //发射斜率控制
#define PLL_TUNE_TIME 0x53 //锁相环(PPL)切换时间
#define CALIBRATION_CONTROL 0x55 //校正控制
#define MODEM_TEST 0x56 //调制控制
#define CHARGEPUMP_TEST 0x57 //充电泵测试
#define CHARGEPUMP_CURRENT_TRIMMING_OVERRIDE 0x58 //充电泵电流微调/超调
#define DIVIDER_CURRENT_TRIMMING 0x59 //电流分压器微调/Delta-Sigma测试
#define VCO_CURRENT_TRIMMING 0x5A //VCO电流微调
#define VCO_CALIBRATION_OVERRIDE 0x5B //VCO校正/超驰
#define SYNTHESIZER_TEST 0x5C //合成器测试
#define BLOCK_ENABLE_OVERRIDE_1 0x5D //模块使能超驰
#define BLOCK_ENABLE_OVERRIDE_2 0x5E
#define BLOCK_ENABLE_OVERRIDE_3 0x5F
#define CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60 //频道滤波器系数地址
#define CHANNEL_FILTER_COEFFICIENT_VALUE 0x61 //频道滤波器系数值
#define CRYSTAL_OSCILLATOR_CONTROL_TEST 0x62 //晶体振荡器/上电复位控制
#define RC_OSCILLATOR_COARSE_CALIBRATION_OVERRIDE 0x63 //RC振荡器粗略校正/超驰
#define RC_OSCILLATOR_FINE_CALIBRATION_OVERRIDE 0x64 //RC震荡器精细校正
#define LDO_CONTROL_OVERRIDE_ENSPOR 0x65 //LDO控制超驰
#define LDO_LEVEL_SETTING 0x66 //保留?LDO等级设置?
#define DELTASIGMA_ADC_TUNING_1 0x67 //Delta-sigma ADC调谐
#define DELTASIGMA_ADC_TUNING_2 0x68
#define AGC_OVERRIDE_1 0x69 //AGC过载
#define AGC_OVERRIDE_2 0x6A
#define GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6B //GFSK FIR 滤波器系数地址
#define GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6C //GFSK FIR 滤波器系数值
#define TX_POWER 0x6D //发射功率设置,详细请见P153
#define TX_DATA_RATE_1 0x6E //数据发送波特率设置寄存器1
#define TX_DATA_RATE_0 0x6F //数据发送波特率设置寄存器0
#define MODULATION_MODE_CONTROL_1 0x70 //调制方式控制,详细请见P155
#define MODULATION_MODE_CONTROL_2 0x71
#define FREQUENCY_DEVIATION 0x72 //频率偏差
#define FREQUENCY_OFFSET_1 0x73 //频率偏移
#define FREQUENCY_OFFSET_2 0x74 //频道控制
#define FREQUENCY_BAND_SELECT 0x75 //频段选择,详细请见P157
#define NOMINAL_CARRIER_FREQUENCY_1 0x76 //基准载波频率
#define NOMINAL_CARRIER_FREQUENCY_0 0x77
#define FREQUENCY_HOPPING_CHANNEL_SELECT 0x79 //跳频频道选择,详细请见P158
#define FREQUENCY_HOPPING_STEP_SIZE 0x7A //跳频频道间隔
#define TX_FIFO_CONTROL_1 0x7C
#define TX_FIFO_CONTROL_2 0x7D
#define RX_FIFO_CONTROL 0x7E
#define FIFO_ACCESS 0x7F //FIFO读写方式设置
//-----------------------------RF4432控制指令---------------------------//
#define RR 0x00
#define WR 0x80
//------------------------------函数申明-----------------------------------//
void si4432_task(void* arg);
uint8_t SPI_Read(void); //SPI单字节读取函数
void SPI_Write(uint8_t txdata); //SPI单字节写入函数
uint8_t RF4432_ReadReg(uint8_t addr); //RF4432寄存器读取函数
void RF4432_WriteReg(uint8_t addr, uint8_t value); //RF4432寄存器写函数
void RF4432_WriteBurestReg(uint8_t addr,uint8_t *p,uint8_t count);
void RF4432_ReadBurestReg(uint8_t addr,uint8_t *p,uint8_t count);
void RF4432_Init(void); //RF4432射频芯片初始化函数
void RF4432_SetRxMode(void); //RF4432设置接收模式函数
uint8_t RF4432_RxPacket(void); //RF4432数据包接收函数
void RF4432_TxPacket(void); //RF4432数据包发送函数
void RF4432_IOSet(void);
uint8_t get_ver(void);
//----------------------------测试用例--------------------------------------//
/*
发送端
void main()
{
RF4432_Init();
while(1)
{
RF4432_TxPacket();
}
}
接收端
void main()
{
RF4432_Init();
RF4432_SetRxMode();
while(1)
{
if(RF4432_RxPacket()) {
}
}
}
*/
#endif // !_SI4432__
si4432.c
#include "si4432.h"
static struct bflb_device_s *gpio;
extern xQueueHandle rf_queue;
uint8_t get_ver()
{
return RF4432_ReadReg(0x01);
}
void si4432_task(void* arg){
char* queue_buff = NULL;
RF4432_Init();
uint8_t ver = get_ver();
LOG_F("ver: 0x%02x \r\n", ver);
while (1) {
queue_buff = pvPortMalloc(32);
memset(queue_buff, 0, 32);
xQueueReceive(rf_queue, queue_buff, portMAX_DELAY);
printf("queue_buff: ");
for (int i = 0; i < sizeof(queue_buff); i++)
{
printf("0x%02x ", queue_buff[i]);
}
printf("\r\n");
RF4432_TxPacket();
}
}
//-------------------------------------------------------SPI单字节读取函数--------------------------------------------------------
uint8_t SPI_Read(void)
{
uint8_t i, rxdata;
rxdata = 0x00;
for (i = 0; i < 8; i++) {
rxdata = rxdata << 1;
RF4432_SCLK_1;
//RF4432_SDO_1;
//P1DIR &= ~BIT3;
if (RF4432_SDO_IN) //读取最高位,保存至最末尾,通过左移位完成整个字节
{
LOG_F("SPI_Read RF4432_SDO_IN 1\r\n");
rxdata |= 0x01;
} else {
LOG_F("SPI_Read RF4432_SDO_IN 0\r\n");
rxdata &= ~0x01;
}
//P1DIR |= BIT3;
bflb_mtimer_delay_us(20);
RF4432_SCLK_0;
bflb_mtimer_delay_us(20);
}
LOG_F("SPI_Read rxdata: 0x%02x\r\n", rxdata);
return rxdata;
}
//---------------------------------------------------------SPI单字节写入函数----------------------------------------------
void SPI_Write(uint8_t txdata)
{
LOG_F("SPI_Write txdata: 0x%02x\r\n", txdata);
uint8_t i;
for (i = 0; i < 8; i++) {
if (txdata & 0x80) //总是发送最高位
{
LOG_F("SPI_Write RF4432_SDI_1\r\n");
RF4432_SDI_1;
} else {
LOG_F("SPI_Write RF4432_SDI_0\r\n");
RF4432_SDI_0;
}
RF4432_SCLK_1;
bflb_mtimer_delay_us(20);
txdata = txdata << 1;
RF4432_SCLK_0;
}
}
//---------------------------------------------------------RF4432寄存器读取函数-----------------------------------------------------------
uint8_t RF4432_ReadReg(uint8_t addr)
{
LOG_F("RF4432_ReadReg addr: 0x%02x\r\n", addr);
uint8_t value;
RF4432_SEL_0;
SPI_Write(addr | RR);
value = SPI_Read();
RF4432_SEL_1;
return value;
}
//---------------------------------------------------------RF4432寄存器写入函数----------------------------------------------------------
void RF4432_WriteReg(uint8_t addr, uint8_t value)
{
LOG_F("RF4432_WriteReg addr: 0x%02x,value : 0x%02x\r\n", addr, value);
RF4432_SEL_0;
SPI_Write(addr | WR);
SPI_Write(value);
RF4432_SEL_1;
}
//---------------------------------------------------------RF4432寄存器写入函数-----------------------------------------------------------
void RF4432_WriteBurestReg(uint8_t addr, uint8_t *p, uint8_t count)
{
uint8_t i;
RF4432_SEL_0;
SPI_Write(addr | WR);
for (i = 0; i < count; i++) {
SPI_Write(p[i]);
}
RF4432_SEL_1;
}
//---------------------------------------------------------RF4432寄存器读取函数------------------------------------------------------------
void RF4432_ReadBurestReg(uint8_t addr, uint8_t *p, uint8_t count)
{
uint8_t i;
RF4432_SEL_0;
SPI_Write(addr | RR);
for (i = 0; i < count; i++) {
p[i] = SPI_Read();
}
RF4432_SEL_1;
}
//----------------------------------------------------------RF4432射频芯片初始化函数------------------------------------------------------
void RF4432_Init(void)
{
gpio = bflb_device_get_by_name("gpio");
/* spi cs */
bflb_gpio_init(gpio, SPI_CS_PIN, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* spi clk */
bflb_gpio_init(gpio, SPI_CLK_PIN, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* spi miso */
bflb_gpio_init(gpio, SPI_MISO_PIN, GPIO_INPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* spi mosi */
bflb_gpio_init(gpio, SPI_MOSI_PIN, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* nirq */
bflb_gpio_init(gpio, IRQ_PIN, GPIO_INPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* sdn */
bflb_gpio_init(gpio, SDN_PIN, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
/* 收发模式切换控制端 */
bflb_gpio_init(gpio, PAC_PIN, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
RF4432_SDN_0; //允许RF4432工作
bflb_mtimer_delay_ms(20);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_1, 0x80); //软件复位,详细请见P101页
bflb_mtimer_delay_ms(10);
RF4432_ReadReg(INTERRUPT_STATUS_1);
RF4432_ReadReg(INTERRUPT_STATUS_2);
RF4432_WriteReg(INTERRUPT_ENABLE_1, 0x00);
RF4432_WriteReg(INTERRUPT_ENABLE_2, 0x01);
//中断使能
RF4432_WriteReg(IF_FILTER_BANDWIDTH, 0x8b);
//IF滤波器带宽 BW = 75.2Khz; Rb = 50Kbps; Fd = 25Khz;
RF4432_WriteReg(CLOCK_RECOVERY_OVERSAMPLING_RATIO, 0x2c);
//时钟恢复过抽样率
RF4432_WriteReg(CLOCK_RECOVERY_OFFSET_2, 0x20);
//时钟恢复偏差2
RF4432_WriteReg(CLOCK_RECOVERY_OFFSET_1, 0x6d);
//时钟恢复偏差1
RF4432_WriteReg(CLOCK_RECOVERY_OFFSET_0, 0x3a);
//时钟恢复偏差0
RF4432_WriteReg(CLOCK_RECOVERY_TIMING_LOOP_GAIN_1, 0x00);
//时钟恢复定时增益1
RF4432_WriteReg(CLOCK_RECOVERY_TIMING_LOOP_GAIN_0, 0x18);
//时钟恢复定时增益0
RF4432_WriteReg(RSSI_THRESHOLD_FOR_CLEAR_CHANNEL_INDICATOR, 0xf0);
//无干扰信指示器接收信号强度指示(RSSI)
RF4432_WriteReg(DATA_ACCESS_CONTROL, 0x88);
//数据存储控制
RF4432_WriteReg(HEADER_CONTROL_1, 0x8c);
//帧头控制1
RF4432_WriteReg(HEADER_CONTROL_2, 0x0a);
//帧头控制2
RF4432_WriteReg(PREAMBLE_LENGTH, 0x08);
//前导码长度
RF4432_WriteReg(TRANSMIT_PACKET_LENGTH, RF4432_TxRxBuf_Len);
//发送数据包长度设置
RF4432_WriteReg(RECEIVED_PACKET_LENGTH, RF4432_TxRxBuf_Len);
//接收数据包长度设置
RF4432_WriteReg(HEADER_ENABLE_3, 0x00);
//帧头使能3
RF4432_WriteReg(HEADER_ENABLE_2, 0x00);
//帧头使能2
RF4432_WriteReg(HEADER_ENABLE_1, 0x00);
//帧头使能1
RF4432_WriteReg(HEADER_ENABLE_0, 0x00);
//帧头使能0
RF4432_WriteReg(AGC_OVERRIDE_2, 0x0b);
//AGC过载2
RF4432_WriteReg(TX_POWER, 0x07);
//发射功率
RF4432_WriteReg(TX_DATA_RATE_1, 0x0c);
//发射数据波特率1 TX_DR=10^3*txdr[15:0]/2^16 kbit/s
RF4432_WriteReg(TX_DATA_RATE_0, 0xcc);
//发射数据波特率0
RF4432_WriteReg(MODULATION_MODE_CONTROL_1, 0x02);
//调制模式控制1
RF4432_WriteReg(MODULATION_MODE_CONTROL_2, 0x26);
//调制模式控制2(设置为FIFO模式 FSK reg71H)
RF4432_WriteReg(FREQUENCY_DEVIATION, 0x40);
//频率偏差 25KHz f=fd[7:0]*625Hz
RF4432_WriteReg(FREQUENCY_BAND_SELECT, 0x53);
//频段选择 reg75H
RF4432_WriteReg(NOMINAL_CARRIER_FREQUENCY_1, 0x4b);
RF4432_WriteReg(NOMINAL_CARRIER_FREQUENCY_0, 0x00);
//标称载波频率(通信频率433MHZ reg76H)
RF4432_WriteReg(TX_FIFO_CONTROL_1, 0x3F);
RF4432_WriteReg(TX_FIFO_CONTROL_2, 0x00);
//TX_FIFO控制
RF4432_WriteReg(RX_FIFO_CONTROL, 0x3F);
//RX_FIFO控制
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) | 0x01);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) & 0xFE);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) | 0x02);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) & 0xFD);
//工作模式和功能控制
}
//---------------------------------------------------------RF4432设置接收模式函数---------------------------------------------------------------
void RF4432_SetRxMode(void)
{
RF4432_PAC_0;
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) | 0x02);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) & 0xFD);
RF4432_ReadReg(INTERRUPT_STATUS_1);
RF4432_ReadReg(INTERRUPT_STATUS_2);
RF4432_WriteReg(INTERRUPT_ENABLE_1, 0x02);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_1, 0x05); //接收
}
//---------------------------------------------------------RF4432数据包接收函数---------------------------------------------------------------
unsigned char RF4432_RxPacket(void)
{
//RF4432_IRQ_1;
//P1DIR &= ~BIT0;
if (!RF4432_IRQ_IN) {
if (RF4432_ReadReg(INTERRUPT_STATUS_1) & 0x02) {
return 1;
}
}
return 0;
}
//------------------------------RF4432数据包发送函数----------------------------------------
void RF4432_TxPacket(void)
{
RF4432_PAC_1;
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) | 0x01);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_2, RF4432_ReadReg(OPERATING_FUNCTION_CONTROL_2) & 0xFE);
RF4432_WriteBurestReg(FIFO_ACCESS, RF4432_TxRxBuf, RF4432_TxRxBuf_Len);
RF4432_ReadReg(INTERRUPT_STATUS_1);
RF4432_ReadReg(INTERRUPT_STATUS_2);
RF4432_WriteReg(INTERRUPT_ENABLE_1, 0x04);
RF4432_WriteReg(OPERATING_FUNCTION_CONTROL_1, 0x09); //发射
while (1) {
//RF4432_IRQ_1;
//delay_us(10);
//P1IN = BIT0;
//P2DIR &= ~BIT0;
if (!RF4432_IRQ_IN) {
if (RF4432_ReadReg(INTERRUPT_STATUS_1) & 0x04) //详细请看P95页
{
break;
}
}
//P2DIR |= BIT0;
}
}
void RF4432_IOSet()
{
// P1DIR |= 0xF6;
//P6DIR |= 0x03;
}
代码借鉴单片机程序修改目前数据收发正常。
结果
源码放评论区了