最近我一直在用stm32与si4432结合完成通信功能,用的是STM32的硬件SPI,调试了几天,终于发现能进行基本的收发功能,但很激动,但是总有一些数据在发送后,接收端的数据并不能完全一致,举例子来说明发送端发送0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 九个数据,但是在接收端收到的是 0x60 0x62 0x63 0x64 0x65 0x66 0x66 0x68 0x69 ,个别数据会减一,总是找不出原因来,哪位大侠可以指点一下,原因是spi通信问题还是SI4432初始化问题呢?一直找不出!我现在付出我的初始化代码:
void Si4432_init(void)
{
unsigned char a=0;
/*******************************************************
新增加的软件复位
*******************************************************/
SPI_RW_Reg(WRITEREG + 0x07,0x80); //向0X07地址 写入0X80 软件复位
while ( NIRQ == 1);
a=SPI_RW_Reg(READREG + 0x03, 0x00); //清RF模块中断
//USART_SendData(USART1,a);
// delay_ms(10);
a=SPI_RW_Reg(READREG + 0x04, 0x00);
// USART_SendData(USART1,a);
// delay_ms(10);
SPI_RW_Reg(WRITEREG + 0x06, 0x80); //使能同步字侦测
SPI_RW_Reg(WRITEREG + 0x07, 0x01); //进入 Ready 模式
SPI_RW_Reg(WRITEREG + 0x09, 0x7f); //负载电容= 12P
SPI_RW_Reg(WRITEREG + 0x0a, 0x05); //关闭低频输出
SPI_RW_Reg(WRITEREG + 0x0b, 0xea); //GPIO 0 当做普通输出口 配置成了直接数字输出
SPI_RW_Reg(WRITEREG + 0x0c, 0xea); //GPIO 1 当做普通输出口
SPI_RW_Reg(WRITEREG + 0x0d, 0xf4); //GPIO 2 输出收到的数据
SPI_RW_Reg(WRITEREG + 0x70, 0x2c); //会使能曼切斯特反演.
SPI_RW_Reg(WRITEREG + 0x1d, 0x40); //使能 afc
// 1.2K bps setting
SPI_RW_Reg(WRITEREG + 0x1c, 0x16); //滤波器带宽 发射16个Nibble的Preamble
SPI_RW_Reg(WRITEREG + 0x20, 0x83); //时钟恢复过抽样率
SPI_RW_Reg(WRITEREG + 0x21, 0xc0); //
SPI_RW_Reg(WRITEREG + 0x22, 0x13); //
SPI_RW_Reg(WRITEREG + 0x23, 0xa9); //
SPI_RW_Reg(WRITEREG + 0x24, 0x00); //
SPI_RW_Reg(WRITEREG + 0x25, 0x04); //
SPI_RW_Reg(WRITEREG + 0x2a, 0x14);
/***************发射波特率的选择*******************/
SPI_RW_Reg(WRITEREG + 0x6e, 0x09);
SPI_RW_Reg(WRITEREG + 0x6f, 0xd5);
//1.2K bps setting end
SPI_RW_Reg(WRITEREG + 0x30, 0x8c); //使能PH+ FIFO模式,高位在前面,使能CRC校验
SPI_RW_Reg(WRITEREG + 0x32, 0xff); //byte0, 1,2,3 作为头码
SPI_RW_Reg(WRITEREG + 0x33, 0x42); //byte 0,1,2,3 是头码,同步字3,2 是同步字
SPI_RW_Reg(WRITEREG + 0x34, 16); //发射16个Nibble的Preamble
SPI_RW_Reg(WRITEREG + 0x35, 0x20); //需要检测4个nibble的Preamble
SPI_RW_Reg(WRITEREG + 0x36, 0x2d); //同步字为 0x2dd4
SPI_RW_Reg(WRITEREG + 0x37, 0xd4);
SPI_RW_Reg(WRITEREG + 0x38, 0x00);
SPI_RW_Reg(WRITEREG + 0x39, 0x00);
SPI_RW_Reg(WRITEREG + 0x3a, 's'); //发射的头码为: “swwx"
SPI_RW_Reg(WRITEREG + 0x3b, 'w');
SPI_RW_Reg(WRITEREG + 0x3c, 'w');
SPI_RW_Reg(WRITEREG + 0x3d, 'x');
SPI_RW_Reg(WRITEREG + 0x3e, 10); //总共发射10个字节的数据
SPI_RW_Reg(WRITEREG + 0x3f, 's'); //需要校验的头码为:”swwx"
SPI_RW_Reg(WRITEREG + 0x40, 'w');
SPI_RW_Reg(WRITEREG + 0x41, 'w');
SPI_RW_Reg(WRITEREG + 0x42, 'x');
SPI_RW_Reg(WRITEREG + 0x43, 0xff); //头码1,2,3,4 的所有位都需要校验
SPI_RW_Reg(WRITEREG + 0x44, 0xff); //
SPI_RW_Reg(WRITEREG + 0x45, 0xff); //
SPI_RW_Reg(WRITEREG + 0x46, 0xff); //
SPI_RW_Reg(WRITEREG + 0x6d, 0x07); //发射功率设置 0x00:+0dBM 0x01:+3dBM 0x02:+6dBM 0x03:+9dBM 0x04:+11dBM 0x05:+14dBM 0x06:+17dBM 0x07:20dBM
SPI_RW_Reg(WRITEREG + 0x79, 0x0); //不需要跳频
SPI_RW_Reg(WRITEREG + 0x7a, 0x0); //不需要跳频
SPI_RW_Reg(WRITEREG + 0x71, 0x22); //发射不需要CLK,FiFo,FSK模式
SPI_RW_Reg(WRITEREG + 0x72, 0x30); //频偏为 30KHz
SPI_RW_Reg(WRITEREG + 0x73, 0x0); //没有频率偏差
SPI_RW_Reg(WRITEREG + 0x74, 0x0); //没有频率偏差
SPI_RW_Reg(WRITEREG + 0x75, 0x53); //频率设置 434
SPI_RW_Reg(WRITEREG + 0x76, 0x64); //
SPI_RW_Reg(WRITEREG + 0x77, 0x00);
TX0_RX0; // 天线开关不在发射,接收状态
}
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |