/****************************************************************
Programme Tips
@* 1.When coming out of the shutdown state POR will be initiated along with the
internal calibrations.After POR,POWER_UP command is required to initilize the radio.
The SDN pin needs to be held high for at lest 10us before driving low again so that
internal capcitors can discharge.Not holding SDN high for this period of time may cause
the POR to be missed and the device to boot up incorrectly.
******************************************/
#include <stdio.h>
#include "Si4463.h"
#include "Gpio.h"
#include "Spi.h"
//#include "Def.h"
//#include "Ext.h"
#include "STM32_Init.h" // STM32 Initialization
#include "Usart.h"
//#include "radio_config_Si4463_9K6.h"
//#include "radio_config_Si4463_12000.h"
#include "radio_config_Si4463_12k.h"
void radio_comm_ReadData(SPI_TypeDef* SPIx,unsigned char cmd, unsigned char pollCts, unsigned char byteCount, unsigned char* pData);
void radio_comm_WriteData(SPI_TypeDef* SPIx,unsigned char cmd, unsigned char pollCts,unsigned char byteCount, unsigned char * pData);
void radio_comm_SendCmd(SPI_TypeDef* SPIx,unsigned char byteCount, unsigned char* pData);
//#include "radio_config_Si4463_16K_dev10K.h"
//#include "radio_config_Si4463_VAR.h"
//#include "radio_config_Si4463_12K.h"
unsigned char RS485Buf_SysErr[] = {0x01, 0x05, 0x00, 0x00, 0x11, 0xD9};
#if 1
extern unsigned char freq_144[],freq_164[];
unsigned char Radio_Configuration_Data_Array[] = RADIO_CONFIGURATION_DATA_ARRAY;
const tRadioConfiguration RadioConfiguration = RADIO_CONFIGURATION_DATA; //初始化模块宏定义数据
const tRadioConfiguration *pRadioConfiguration = &RadioConfiguration;
//extern unsigned char rx_cmd[FRAME_VOICE_LEN+1];
unsigned char ctsWentHigh = 0;
union si446x_cmd_reply_union Si446xCmd;
unsigned char radioCmd[16];
unsigned char Pro2Cmd[16];
//unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0C, 0x8F, 0x5C, 0x51, 0xEC, 0x20, 0xFA};
//unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0C, 0x8F, 0x5C, 0x51, 0xEC, 0x20, 0xFA}; //.025
//unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0C, 0xCC, 0xCC, 0x51, 0xEC, 0x20, 0xFA}; //.1
//unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0C, 0xCC, 0xCC, 0x51, 0xEC, 0x20, 0xFA};
//unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0C, 0x00, 0x00, 0xCC, 0xCD, 0x20, 0xFA};
//unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0C, 0x00, 0x00, 0xCC, 0xCD, 0x20, 0xFA};
//unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0D, 0x0A, 0x3D, 0xA3, 0xD7, 0x20, 0xFA};
//unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0C, 0xE1, 0x47, 0xA3, 0xD7, 0x20, 0xFA};
//unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0C, 0x00, 0x00, 0xCC, 0xCD, 0x20, 0xFA};
//unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0C, 0x00, 0x00, 0xCC, 0xCD, 0x20, 0xFA};
unsigned char freq_144[] = {0x11, 0x40, 0x08, 0x00, 0x38, 0x0C, 0xE1, 0x47, 0xA3, 0xD7, 0x20, 0xFA};
unsigned char freq_164[] = {0x11, 0x40, 0x08, 0x00, 0x40, 0x0D, 0x0A, 0x3D, 0xA3, 0xD7, 0x20, 0xFA};
#endif
/*====================================================================
* 名 称:Si446x_Gpio_Config(void)
* 功 能:初始化SI4463的IO口
* 入口参数:无
* 出口参数:无
* 说 明:
* 调用方法:Si446x_Gpio_Config();
*===================================================================*/
void Si446x_Gpio_Config(void)
{
RCC->APB2ENR|=1<<0; //开启辅助时钟
RCC->APB2ENR|=1<<2; //使能PORTA时钟
RCC->APB2ENR|=1<<3; //使能PORTB时钟
AFIO->MAPR&=0XF8FFFFFF; //清除MAPR的[26:24]
AFIO->MAPR|=0X02000000;
//GPIOA输入输出设置
GPIOA->CRL&=0XFFF0FF0F;
GPIOA->CRL|=0X00030030; //PA1输出(SDN_RX) PA4输出(SEL_RX)
GPIOA->ODR|=0x12<<1; //PA1 PA4上拉
//GPIOB输入输出设置
GPIOB->CRH&=0XFFF000FF;
GPIOB->CRH|=0X00038300; //PB10 输出(SDN_TX) PB11输入(IRQ_TX) PB12 输出(SEL_TX)
GPIOB->ODR|=7<<10; //PB10 PB11 PB12 上拉
//GPIOB输入输出设置
GPIOB->CRL&=0XFFFFFF0F;
GPIOB->CRL|=0X00000080; //PB1 输入(IRQ_RX)
GPIOB->ODR|=1<<1; //PB1 上拉
}
/*====================================================================
* 名 称:Si446x_Reset(void)
* 功 能:SI4463复位
* 入口参数:无
* 出口参数:无
* 说 明:
* 调用方法:Si446x_Reset();
*===================================================================*/
void Si446x_Reset(SPI_TypeDef* SPIx)
{
if(SPIx==SI4463_RX)
Si4463_SDN_High_Rx;
if(SPIx==SI4463_TX)
Si4463_SDN_High_Tx;
Delay_us(10);
if(SPIx==SI4463_RX)
Si4463_SDN_Low_Rx;
if(SPIx==SI4463_TX)
Si4463_SDN_Low_Tx;
ctsWentHigh = 0;
}
void Si446x_Power_Up(SPI_TypeDef* SPIx,unsigned char BOOT_OPTIONS, unsigned char
XTAL_OPTIONS, uint32_t XO_FREQ)
{
Pro2Cmd[0] = SI446X_CMD_ID_POWER_UP;
Pro2Cmd[1] = BOOT_OPTIONS;
Pro2Cmd[2] = XTAL_OPTIONS;
Pro2Cmd[3] = (unsigned char)(XO_FREQ >> 24);
Pro2Cmd[4] = (unsigned char)(XO_FREQ >> 16);
Pro2Cmd[5] = (unsigned char)(XO_FREQ >> 8);
Pro2Cmd[6] = (unsigned char)(XO_FREQ);
Si446x_SendCmd(SPIx,7,Pro2Cmd);
}
/*====================================================================
* 名 称:Si446x_Configuration_Init
* 功 能:配置SI4463初始参数
* 入口参数:SPIx(SPI1:RX; SPI2:TX)
* 出口参数:配置结果
* 说 明:
* 调用方法:Si446x_Configuration_Init(SPIx, pRadioConfiguration -> Radio_ConfigurationArray);
*===================================================================*/
unsigned char Si446x_Configuration_Init(SPI_TypeDef* SPIx,const unsigned char* pSetPropCmd)
{
unsigned char col,numOfBytes;
/* While cycle as far as the pointer points to a command */
while (*pSetPropCmd != 0x00)
{
numOfBytes = *pSetPropCmd ++;
if (numOfBytes > 16) // Number of command bytes exceeds maximal allowable length
{
printf("Cmd bytes exceeds 16!\n");
return SI446X_COMMAND_ERROR;
}
// printf("si446x configuration init %02d:",numOfBytes);
for (col = 0; col < numOfBytes; col++)
{
Pro2Cmd[col] = *pSetPropCmd;
pSetPropCmd ++;
// printf("0x%02x ",Pro2Cmd[col]);
}
// printf("\r\n");
if (Si446x_SendCmdGetResp(SPIx,numOfBytes, Pro2Cmd, 0, 0) != 0xFF)
{
printf("si4463 cts timeout\n");
return SI446X_CTS_TIMEOUT;
}
if((Si4463_nIRQ_Rx==0) || (Si4463_nIRQ_Tx==0))
{
/* Get and clear all interrupts. An error has occured... */
Si446x_Get_Int_Status(SPIx,0,0,0);
if (Si446xCmd.GET_INT_STATUS.CHIP_PEND & SI446X_CMD_GET_CHIP_STATUS_REP_CHIP_PEND_CMD_ERROR_PEND_MASK)
{
printf("si446x command error!");
return SI446X_COMMAND_ERROR;
}
}
}
return SI446X_SUCCESS;
}
/*====================================================================
* 名 称:Si446x_TxCmd
* 功 能:写SI4463发命令CHANNEL:信道号
* 入口参数:SPIx(SPI1:RX; SPI2:TX)
* 出口参数:配置结果
* 说 明:
* 调用方法:Si446x_TxCmd(SPI2,Channel,3,19);
*===================================================================*/
void Si446x_TxCmd(SPI_TypeDef* SPIx,unsigned char CHANNEL, unsigned char CONDITION, unsigned short TX_LEN)
{
Pro2Cmd[0] = SI446X_CMD_ID_START_TX; //Switches to TX state and starts transmission of a packet.
Pro2Cmd[1] = CHANNEL;
Pro2Cmd[2] = CONDITION;
Pro2Cmd[3] = (unsigned char)(TX_LEN >> 8);
Pro2Cmd[4] = (unsigned char)(TX_LEN);
Pro2Cmd[5] = 0x00;
// Don't repeat the packet,
// ie. transmit the packet only once
Pro2Cmd[6] = 0x00;
Si446x_SendCmd(SPIx,7,Pro2Cmd);
}
/*====================================================================
* 名 称:Si446x_RxCmd
* 功 能:写SI4463收命令CHANNEL:信道号
* 入口参数:SPIx(SPI1:RX; SPI2:TX);
* 出口参数:
* 说 明:
* 调用方法:Si446x_RxCmd(SI4463_RX,channel,0,pkt_len
评论1