#include "CC1101.h"
//uchar PaTabel[8] = {0x04 ,0x04 ,0x04 ,0x04 ,0x04 ,0x04 ,0x04 ,0x04}; //-30dBm 功率最小
//uchar PaTabel[8] = {0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60 ,0x60}; //0dBm
uchar PaTabel[8] = {0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0}; //10dBm 功率最大
void CC1101_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // 使能端口时钟
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //时钟速度为50M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //时钟速度为50M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6; //非常重要,否则收不到!!
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //时钟速度为50M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // 使能端口时钟
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //时钟速度为50M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
// RF_SETTINGS is a data structure which contains all relevant CCxxx0 registers
typedef struct S_RF_SETTINGS
{
unsigned char FSCTRL2; //
unsigned char FSCTRL1; // Frequency synthesizer control.频率合成器控制。
unsigned char FSCTRL0; // Frequency synthesizer control.
unsigned char FREQ2; // Frequency control word, high INT8U.
unsigned char FREQ1; // Frequency control word, middle INT8U.
unsigned char FREQ0; // Frequency control word, low INT8U.
unsigned char MDMCFG4; // Modem configuration.
unsigned char MDMCFG3; // Modem configuration.
unsigned char MDMCFG2; // Modem configuration.
unsigned char MDMCFG1; // Modem configuration.
unsigned char MDMCFG0; // Modem configuration.
unsigned char CHANNR; // Channel number.
unsigned char DEVIATN; // Modem deviation setting (when FSK modulation is enabled).
unsigned char FREND1; // Front end RX configuration.
unsigned char FREND0; // Front end RX configuration.
unsigned char MCSM0; // Main Radio Control State Machine configuration.
unsigned char FOCCFG; // Frequency Offset Compensation Configuration.
unsigned char BSCFG; // Bit synchronization Configuration.
unsigned char AGCCTRL2; // AGC control.
unsigned char AGCCTRL1; // AGC control.
unsigned char AGCCTRL0; // AGC control.
unsigned char FSCAL3; // Frequency synthesizer calibration.
unsigned char FSCAL2; // Frequency synthesizer calibration.
unsigned char FSCAL1; // Frequency synthesizer calibration.
unsigned char FSCAL0; // Frequency synthesizer calibration.
unsigned char FSTEST; // Frequency synthesizer calibration control
unsigned char TEST2; // Various test settings.
unsigned char TEST1; // Various test settings.
unsigned char TEST0; // Various test settings.
unsigned char IOCFG2; // GDO2 output pin configuration
unsigned char IOCFG0; // GDO0 output pin configuration
unsigned char PKTCTRL1; // Packet automation control.
unsigned char PKTCTRL0; // Packet automation control.
unsigned char ADDR; // Device address.
unsigned char PKTLEN; // Packet length.
} RF_SETTINGS;
//FREQ2、FREQ1、FREQ0决定频率,例如315MHz,
//设定: FREQ2=0x0C,FREQ1=0x1D,FREQ0=0x89,
// 433MH FREQ2=0x0C,FREQ1=0x1D,FREQ0=0x89,
// 868MH FREQ2=0x21,FREQ1=0x62,FREQ0=0x5B,
//433Mhz 2.4kBaud 10dBm
const RF_SETTINGS rfSettings =
{
0x00,
0x06, // FSCTRL1 Frequency synthesizer control.
0x00, // FSCTRL0 Frequency synthesizer control.
0x10, // FREQ2 Frequency control word, high byte.
0xB1, // FREQ1 Frequency control word, middle byte.
0x3B, // FREQ0 Frequency control word, low byte.
0xF5, // MDMCFG4 Modem configuration.
0x83, // MDMCFG3 Modem configuration.
0x13, // MDMCFG2 Modem configuration.
0x22, // MDMCFG1 Modem configuration.
0xF8, // MDMCFG0 Modem configuration.
0x00, // CHANNR Channel number.
0x15, // DEVIATN Modem deviation setting (when FSK modulation is enabled).
0x56, // FREND1 Front end RX configuration.
0x10, // FREND0 Front end RX configuration.
0x18, // MCSM0 Main Radio Control State Machine configuration.
0x16, // FOCCFG Frequency Offset Compensation Configuration.
0x6C, // BSCFG Bit synchronization Configuration.
0x03, // AGCCTRL2 AGC control.
0x40, // AGCCTRL1 AGC control.
0x91, // AGCCTRL0 AGC control.
0xE9, // FSCAL3 Frequency synthesizer calibration.
0x2A, // FSCAL2 Frequency synthesizer calibration.
0x00, // FSCAL1 Frequency synthesizer calibration.
0x1F, // FSCAL0 Frequency synthesizer calibration.
0x59, // FSTEST Frequency synthesizer calibration.
0x81, // TEST2 Various test settings.
0x35, // TEST1 Various test settings.
0x09, // TEST0 Various test settings.
0x29, // IOCFG2 GDO2 output pin configuration.
0x06, // IOCFG0D GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
0x04, // PKTCTRL1 Packet automation control.
0x05, // PKTCTRL0 Packet automation control.
0x00, // ADDR Device address.
0xFF // PKTLEN Packet length.最大
};
// RF settings for CC1101
//433MHz Datarate:250k
//const RF_SETTINGS rfSettings =
//{
// 0x00,
// 0x0C, //FSCTRL1
// 0x00, //FSCTRL0
// 0x10, //FREQ2
// 0xB1, //FREQ1
// 0x3B, //FREQ0
// 0x2D, //MDMCFG4
// 0x3B, //MDMCFG3
// 0x13, //MDMCFG2
// 0x22, //MDMCFG1
// 0xF8, //MDMCFG0
//
// 0x00, //CHANNR
// 0x62, //DEVIATN
// 0xB6, //FREND1
// 0x10, //FREND0
// 0x18, //MCSM0
// 0x1D, //FOCCFG
// 0x1C, //BSCFG
// 0xC7, //AGCCTRL2
// 0x00, //AGCCTRL1
// 0xB0, //AGCCTRL0
// 0xEA, //FSCAL3
// 0x2A, //FSCAL2
// 0x00, //FSCAL1
// 0x1F, //FSCAL0
// 0x59, //FSTEST
// 0x88, //TEST2
// 0x31, //TEST1
// 0x09, //TEST0
// 0x29, //IOCFG2
// 0x06, //IOCFG0
// 0x04, //PKTCTRL1
// 0x05, //PKTCTRL0
// 0x00, //ADDR
// 0xFF //PKTLEN
//};
/*
// RF output power = 0 dBm
// RX filterbandwidth = 540.000000 kHz
// Deviation = 0.000000
// Datarate = 250.000000 kbps
// Modulation = (7) MSK
// Manchester enable = (0) Manchester disabled
// RF Frequency = 433.000000 MHz
// Channel spacing = 199.951172 kHz
// Channel number = 0
// Optimization = Sensitivity
// Sync mode = (3) 30/32 sync word bits detected
// Format of RX/TX data = (0) Normal mode, use FIFOs for RX and TX
// CRC operation = (1) CRC calculation in TX and CRC check in RX enabled
// Forward Error Correction = (0) FEC disabled
// Length configuration = (1) Variable length packets, packet length configured by the first received byte after sync word.
// Packetlength = 255
// Preamble count = (2) 4 bytes
// Append status = 1
// Address check = (11) No address check
// FIFO autoflush = 0
// Device address = 0
// GDO0 signal selection = ( 6)
// GDO2 signal selection = (11) Serial Clock
const RF_SETTINGS rfSettings = {
0x00,
0x08, // FSCTRL1 Frequency synthesizer control.
0x00, // FSCTRL0 Frequency synthesizer control.
0x10, // FREQ2 Frequency control word, high byte.
0xA7, /
评论0