资源简介
si4432驱动源码,发送、接收调试成功,下载就可使用。
代码片段和文件信息
#include “si4432.h“
sbit SPI_SDO =P0^1;
sbit SPI_SDI =P0^0;
sbit SPI_NIRQ =P2^4;
sbit SPI_SDN =P2^5;
sbit SPI_SCLK =P2^6;
sbit SPI_NSEL =P2^7;
//端口配置
void SI4432_GPIO_Config(void)
{
P0CR=P0CR&0xFE;
P0CR=P0CR|0x02;
P2CR=P2CR&0xEF;
P2CR=P2CR|0x20;
P2CR=P2CR|0x40;
P2CR=P2CR|0x80;
}
//发送一字节
void SPI_SendByte(uint8_t ucByte)
{
uint8_t i;
for(i=0;i<8;i++)
{
SPI_SCLK=0;
if((ucByte&0x80)==0x80)
{
SPI_SDO=1;
}
else
{
SPI_SDO=0;
}
SPI_SCLK=1;
ucByte=ucByte<<1;
}
}
//接收一字节
uint8_t SPI_ReceByte(void)
{
uint8_t i;
uint8_t ucReturn;
for(i=0;i<8;i++)
{
ucReturn=ucReturn<<1;
SPI_SCLK=0;
if(SPI_SDI==1)
{
ucReturn=ucReturn|0x01;
}
SPI_SCLK=1;
}
return ucReturn;
}
//写寄存器
void SI4432_WriteReg(uint8_t ucAddruint8_t ucData)
{
SPI_NSEL=0;
SPI_SendByte(SI4432_WRITE_ORDER|ucAddr);
SPI_SendByte(ucData);
SPI_NSEL=1;
}
//读寄存器
uint8_t SI4432_ReadReg(uint8_t ucAddr)
{
uint8_t ucReturn;
SPI_NSEL=0;
SPI_SendByte(SI4432_READ_ORDER|ucAddr);
ucReturn=SPI_ReceByte();
SPI_NSEL=1;
return ucReturn;
}
//突发写
void SI4432_BurestWrite(uint8_t ucAddruint8_t ucLenuint8_t *PucStr)
{
uint8_t i;
SPI_NSEL=0;
SPI_SendByte(SI4432_WRITE_ORDER|ucAddr);
for(i=0;i {
SPI_SendByte(*PucStr);
PucStr++;
}
SPI_NSEL=1;
}
//突发读
void SI4432_BurestRead(uint8_t ucAddruint8_t ucLenuint8_t *PucStr)
{
uint8_t i;
SPI_NSEL=0;
SPI_SendByte(SI4432_READ_ORDER|ucAddr);
for(i=0;i {
*PucStr=SPI_ReceByte();
PucStr++;
}
SPI_NSEL=1;
}
//空闲模式
void SI4432_IdleMode(void)
{
SI4432_WriteReg(0x070x01);
SI4432_WriteReg(0x050x00);
SI4432_WriteReg(0x060x00);
SI4432_ReadReg(0x03);
SI4432_ReadReg(0x04);
}
//接收模式
void SI4432_ReceMode(void)
{
SI4432_IdleMode();
SI4432_WriteReg(0x0e0x02);
SI4432_WriteReg(0x080x02);
SI4432_WriteReg(0x080x00);
SI4432_WriteReg(0x050x02);
SI4432_WriteReg(0x070x05);
}
//初始化芯片
void SI4432_Config(void)
{
SI4432_GPIO_Config();
SPI_SDN=1;
COM_DelayMs(5);
SPI_SDN=0;
COM_DelayMs(100);
SI4432_IdleMode(); //进入空闲模式
SI4432_WriteReg(0x090x7f); //晶体震荡负载电容 负载电容= 12P
SI4432_WriteReg(0x0a0x05); //微控制器输出时钟,关闭低频输出
SI4432_WriteReg(0x0b0xea); //GPIO0 配置 GPIO 0 当做普通输出口
SI4432_WriteReg(0x0c0xea); //GPIO1 配置 GPIO 1 当做普通输出口
SI4432_WriteReg(0x0d0xf4); //GPIO2 配置 GPIO 2 输出收到的数据
SI4432_WriteReg(0x700x2c);
SI4432_WriteReg(0x1d0x40); //使能 afc循环变速超驰
// 1.2K bps setting
SI4432_WriteReg(0x1c0x16); //IF滤波器带宽 发射16个Nibble的Preamble
SI4432_WriteReg(0x200x83); //时钟恢复过抽样率
SI4432_WriteReg(0x210xc0); //时钟恢复偏差2
SI4432_WriteReg(0x220x13); //时钟恢复偏差1
SI4432_WriteReg(0x230xa9); //时钟恢复偏差0
SI4432_WriteReg(0x240x00); //时钟恢复定时环增益1
SI4432_WriteReg(0x250x04); //时钟恢复定时环增益0
SI4432_WriteReg(0x2a0x14);
SI4432_Wr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-03-19 10:17 si4432源码\
文件 7079 2015-02-11 15:34 si4432源码\si4432.c
文件 567 2015-02-10 16:37 si4432源码\si4432.h
评论
共有 条评论