要把外部中断先关掉,在初始化之后再打开。在gpio.c里面注释掉:
上拉,下跳沿检测
/*Configure GPIO pins : PB0 PB1 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(EXTI0_IRQn);
HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
//HAL_NVIC_EnableIRQ(EXTI1_IRQn);
接收端主函数:
CC1101Reset(&hspi1);
CC1101WORInit(&hspi1);
CC1101Init(&hspi1);
CC1101WriteCmd( CC1101_SRX ,&hspi1);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
while (1)
{
if (rx[0] %2 == 1)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
}
else {HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);}
}
发送端主函数:
CC1101Reset(&hspi1);
CC1101WORInit(&hspi1);
CC1101Init(&hspi1);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
tx[0] = tx[0]+1;
CC1101SendPacket(tx , sizeof(tx), BROADCAST, &hspi1);
if (flag==0){
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
flag=1;
}
else {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
flag=0;
}
}
cc1101.c:
#include "cc1101.h"
#include "spi.h"
uint8_t Rx_Flag;
static const uint8_t CC1101InitData[30][2]=
{
/* {CC1101_IOCFG0, 0x06},
{CC1101_FIFOTHR, 0x47},
{CC1101_PKTCTRL0, 0x05},
{CC1101_CHANNR, 0x00},
{CC1101_FSCTRL1, 0x08},
{CC1101_FREQ2, 0x10},//433.92
{CC1101_FREQ1, 0xB0},
{CC1101_FREQ0, 0x3f},
// {CC1101_FREQ2, 0x10},//433.862
// {CC1101_FREQ1, 0xAf},
// {CC1101_FREQ0, 0xdf},
{CC1101_MDMCFG4, 0x5B},
{CC1101_MDMCFG3, 0xF8},
{CC1101_MDMCFG2, 0x03},
{CC1101_DEVIATN, 0x47},
{CC1101_MCSM0, 0x18},
{CC1101_FOCCFG, 0x1D},
{CC1101_WORCTRL, 0xFB},
{CC1101_FSCAL3, 0xEA},
{CC1101_FSCAL2, 0x2A},
{CC1101_FSCAL1, 0x00},
{CC1101_FSCAL0, 0x11},
{CC1101_TEST2, 0x81},
{CC1101_TEST1, 0x35},
{CC1101_MCSM1, 0x3B},*/
//2-FSK
{CC1101_MCSM1, 0x3c},
{CC1101_IOCFG2, 0x06},
{CC1101_IOCFG0, 0x06},
{CC1101_FIFOTHR, 0x47},
{CC1101_PKTCTRL0, 0x05},
{CC1101_CHANNR, 0x01},
{CC1101_FSCTRL1, 0x06},
{CC1101_FREQ2, 0x10}, //433.92
{CC1101_FREQ1, 0xB0},
{CC1101_FREQ0, 0x3f},
{CC1101_MDMCFG4, 0xF6},
{CC1101_MDMCFG3, 0x43}, //2.00224kBaud 58.035714khz
{CC1101_MDMCFG2, 0x03},
{CC1101_MDMCFG1, 0x20},
{CC1101_MDMCFG0, 0x00},
{CC1101_DEVIATN, 0x15}, //0x15:5.157471khz 0x34:19khz, 0x77:380.85khz,0x64:152khz,0x71:228.5khz
{CC1101_MCSM0, 0x18},
{CC1101_FOCCFG, 0x16},
{CC1101_WORCTRL, 0xFB},
{CC1101_FSCAL3, 0xE9},
{CC1101_FSCAL2, 0x2A},
{CC1101_FSCAL1, 0x00},
{CC1101_FSCAL0, 0x1F},
{CC1101_TEST2, 0x81},
{CC1101_TEST1, 0x35},
{CC1101_TEST0, 0x09},
};
uint8_t PaTabel[] = { 0xc0, 0xC8, 0x84, 0x60, 0x68, 0x34, 0x1D, 0x0E};//433M?table
//uint8_t PaTabel[] = { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/*read a byte from the specified register*/
uint8_t CC1101ReadStatus( uint8_t addr , SPI_HandleTypeDef *hspi);
/*Read some bytes from the rigisters continously*/
void CC1101ReadMultiReg( uint8_t addr, uint8_t *buff, uint8_t size , SPI_HandleTypeDef *hspi);
/*Write a byte to the specified register*/
void CC1101WriteReg( uint8_t addr, uint8_t value , SPI_HandleTypeDef *hspi);
/*Flush the TX buffer of CC1101*/
void CC1101ClrTXBuff( SPI_HandleTypeDef *hspi );
/*Flush the RX buffer of CC1101*/
void CC1101ClrRXBuff( SPI_HandleTypeDef *hspi );
/*Get received count of CC1101*/
uint8_t CC1101GetRXCnt( SPI_HandleTypeDef *hspi );
/*Reset the CC1101 device*/
void CC1101Reset( SPI_HandleTypeDef *hspi );
/*Write some bytes to the specified register*/
void CC1101WriteMultiReg( uint8_t addr, uint8_t *buff, uint8_t size , SPI_HandleTypeDef *hspi);
void CC1101WriteCmd( uint8_t command , SPI_HandleTypeDef *hspi);
/*
================================================================================
Function : CC1101WORInit( )
Initialize the WOR function of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101WORInit(SPI_HandleTypeDef *hspi )
{
CC1101WriteReg(CC1101_MCSM0,0x18,hspi);
CC1101WriteReg(CC1101_WORCTRL,0x78,hspi); //Wake On Radio Control
CC1101WriteReg(CC1101_MCSM2,0x00,hspi);
CC1101WriteReg(CC1101_WOREVT1,0x8C,hspi);
CC1101WriteReg(CC1101_WOREVT0,0xA0,hspi);
CC1101WriteCmd( CC1101_SWORRST ,hspi);
}
/*
================================================================================
Function : CC1101ReadReg( )
read a byte from the specified register
INPUT : addr, The address of the register
OUTPUT : the byte read from the rigister
================================================================================
*/
uint8_t CC1101ReadReg( uint8_t addr , SPI_HandleTypeDef *hspi)
{
uint8_t input[1];
uint8_t output[1];
output[0] = addr | READ_SINGLE; //¶Á¼Ä´æÆ÷ÃüÁî
CSN_reset;
while (MISO);
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
HAL_SPI_Receive(hspi, input, 1, 2000);
CSN_set;
return input[0];
}
/*
================================================================================
Function : CC1101ReadMultiReg( )
Read some bytes from the rigisters continously
INPUT : addr, The address of the register
buff, The buffer stores the data
size, How many bytes should be read
OUTPUT : None
================================================================================
*/
void CC1101ReadMultiReg( uint8_t addr, uint8_t *buff, uint8_t size , SPI_HandleTypeDef *hspi)
{
uint8_t i, j;
uint8_t input[1];
uint8_t output[1];
output[0] = addr | READ_BURST; //дÈëÒª¶ÁµÄÅäÖüĴæÆ÷µØÖ·ºÍ¶ÁÃüÁî
CSN_reset; //CSN = 0;
while (MISO);
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
for( i = 0; i < size; i ++ )
{
output[0] = buff[i];
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
buff[i] = input[0];
}
CSN_set;//CSN = 1;
}
/*
================================================================================
Function : CC1101ReadStatus( )
Read a status register
INPUT : addr, The address of the register
OUTPUT : the value read from the status register
================================================================================
*/
uint8_t CC1101ReadStatus( uint8_t addr , SPI_HandleTypeDef *hspi)
{
uint8_t input[1];
uint8_t output[1];
output[0] = addr | READ_BURST; //дÈëÒª¶ÁµÄ״̬¼Ä´æÆ÷µÄµØַͬʱдÈë¶ÁÃüÁî
CSN_reset;
while (MISO);
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
HAL_SPI_Receive(hspi, input, 1, 2000);
CSN_set;
return input[0];
}
/*
================================================================================
Function : CC1101SetTRMode( )
Set the device as TX mode or RX mode
INPUT : mode selection
OUTPUT : None
================================================================================
*/
void CC1101SetTRMode( TRMODE mode , SPI_HandleTypeDef *hspi)
{
if( mode == TX_MODE )
{
CC1101WriteReg(CC1101_IOCFG0,0x46,hspi);
CC1101WriteCmd( CC1101_STX ,hspi);
}
else if( mode == RX_MODE )
{
CC1101WriteReg(CC1101_IOCFG0,0x46,hspi);
CC1101WriteCmd( CC1101_SRX ,hspi);
}
}
/*
================================================================================
Function : CC1101WriteReg( )
Write a byte to the specified register
INPUT : addr, The address of the register
value, the byte you want to write
OUTPUT : None
================================================================================
*/
void CC1101WriteReg( uint8_t addr, uint8_t value , SPI_HandleTypeDef *hspi)
{
uint8_t input[1];
uint8_t output[1];
CSN_reset;
while (MISO);
output[0] = addr;
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000); //дµØÖ·
output[0] = value;
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000); //дÈëÅäÖÃ
CSN_set;
}
/*
================================================================================
Function : CC1101WriteMultiReg( )
Write some bytes to the specified register
INPUT : addr, The address of the register
buff, a buffer stores the values
size, How many byte should be written
OUTPUT : None
================================================================================
*/
void CC1101WriteMultiReg( uint8_t addr, uint8_t *buff, uint8_t size , SPI_HandleTypeDef *hspi)
{
uint8_t i, output[1], input[1];
output[0] = addr | WRITE_BURST;
CSN_reset; //CSN = 0;
while (MISO);
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
for( i = 0; i < size; i ++ )
{
output[0] = buff[i];
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000);
}
CSN_set;//CSN = 1;
}
/*
================================================================================
Function : CC1101WriteCmd( )
Write a command byte to the device
INPUT : command, the byte you want to write
OUTPUT : None
================================================================================
*/
void CC1101WriteCmd( uint8_t command , SPI_HandleTypeDef *hspi)
{
uint8_t input[1];
uint8_t output[1];
CSN_reset; //CSN = 0;
while (MISO);
output[0] = command;
HAL_SPI_TransmitReceive(hspi, output, input, 1, 2000); дÈëÃüÁî
CSN_set;//CSN = 1;
}
/*
================================================================================
Function : CC1101Reset( )
Reset the CC1101 device
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101Reset( SPI_HandleTypeDef *hspi )
{
uint8_t x;
CSN_set;//CSN = 1;
CSN_reset; //CSN = 0;
CSN_set;//CSN = 1;
for( x = 0; x < 100; x ++ );
CC1101WriteCmd( CC1101_SRES ,hspi);
}
/*
================================================================================
Function : CC1101SetIdle( )
Set the CC1101 into IDLE mode
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101SetIdle( SPI_HandleTypeDef *hspi )
{
CC1101WriteCmd(CC1101_SIDLE,hspi);
}
/*
================================================================================
Function : CC1101ClrTXBuff( )
Flush the TX buffer of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101ClrTXBuff( SPI_HandleTypeDef *hspi )
{
CC1101SetIdle(hspi);//MUST BE IDLE MODE
CC1101WriteCmd( CC1101_SFTX ,hspi);
}
/*
================================================================================
Function : CC1101ClrRXBuff( )
Flush the RX buffer of CC1101
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101ClrRXBuff( SPI_HandleTypeDef *hspi )
{
CC1101SetIdle(hspi);//MUST BE IDLE MODE
CC1101WriteCmd( CC1101_SFRX ,hspi);
}
/*
================================================================================
Function : CC1101SendPacket( )
Send a packet
INPUT : txbuffer, The buffer stores data to be sent
size, How many bytes should be sent
mode, Broadcast or address check packet
OUTPUT : None
================================================================================
*/
void CC1101SendPacket( uint8_t *txbuffer, uint8_t size, TX_DATA_MODE mode ,SPI_HandleTypeDef *hspi)
{
uint8_t address;
if( mode == BROADCAST ) { address = 0; }
else if( mode == ADDRESS_CHECK ) { address = CC1101ReadReg( CC1101_ADDR ,hspi); }
CC1101ClrTXBuff( hspi);
if( ( CC1101ReadReg( CC1101_PKTCTRL1 ,hspi) & ~0x03 ) != 0 )
{
CC1101WriteReg( CC1101_TXFIFO, size + 1 ,hspi);
CC1101WriteReg( CC1101_TXFIFO, address ,hspi);
}
else
{
CC1101WriteReg( CC1101_TXFIFO, size ,hspi);
}
CC1101WriteMultiReg( CC1101_TXFIFO, txbuffer, size ,hspi);
CC1101SetTRMode( TX_MODE ,hspi);
while( GDO0 != 0 );
while( GDO0 == 0 );
CC1101ClrTXBuff( hspi);
}
/*
================================================================================
Function : CC1101GetRXCnt( )
Get received count of CC1101
INPUT : None
OUTPUT : How many bytes hae been received
================================================================================
*/
uint8_t CC1101GetRXCnt( SPI_HandleTypeDef *hspi )
{
return ( CC1101ReadStatus( CC1101_RXBYTES ,hspi) & BYTES_IN_RXFIFO );
}
/*
================================================================================
Function : CC1101SetAddress( )
Set the address and address mode of the CC1101
INPUT : address, The address byte
AddressMode, the address check mode
OUTPUT : None
================================================================================
*/
void CC1101SetAddress( uint8_t address, ADDR_MODE AddressMode,SPI_HandleTypeDef *hspi)
{
uint8_t btmp = CC1101ReadReg( CC1101_PKTCTRL1 ,hspi) & ~0x03;
CC1101WriteReg(CC1101_ADDR, address,hspi);
if ( AddressMode == BROAD_ALL ) {}
else if( AddressMode == BROAD_NO ) { btmp |= 0x01; }
else if( AddressMode == BROAD_0 ) { btmp |= 0x02; }
else if( AddressMode == BROAD_0AND255 ) { btmp |= 0x03; }
}
/*
================================================================================
Function : CC1101SetSYNC( )
Set the SYNC bytes of the CC1101
INPUT : sync, 16bit sync
OUTPUT : None
================================================================================
*/
void CC1101SetSYNC( uint16_t sync ,SPI_HandleTypeDef *hspi)
{
CC1101WriteReg(CC1101_SYNC1, 0xFF & ( sync>>8 ) ,hspi);
CC1101WriteReg(CC1101_SYNC0, 0xFF & sync ,hspi);
}
/*
================================================================================
Function : CC1101RecPacket( )
Receive a packet
INPUT : rxBuffer, A buffer store the received data
OUTPUT : 1:received count, 0:no data
================================================================================
*/
uint8_t CC1101RecPacket( uint8_t *rxBuffer ,SPI_HandleTypeDef *hspi)
{
uint8_t status[2];
uint8_t pktLen;
uint16_t x;
if ( CC1101GetRXCnt( hspi) != 0 )
{
pktLen = CC1101ReadReg(CC1101_RXFIFO,hspi); // Read length byte
if( ( CC1101ReadReg( CC1101_PKTCTRL1 ,hspi) & ~0x03 ) != 0 )
{
x = CC1101ReadReg(CC1101_RXFIFO,hspi);
}
if( pktLen == 0 ) { return 0; }
else { pktLen --; }
CC1101ReadMultiReg(CC1101_RXFIFO, rxBuffer, pktLen,hspi); // Pull data
CC1101ReadMultiReg(CC1101_RXFIFO, status, 2,hspi); // Read status bytes
CC1101ClrRXBuff(hspi );
if( status[1] & CRC_OK ) { return pktLen; }
else { return 0; }
}
else { return 0; } // Error
}
/*
================================================================================
Function : CC1101Init( )
Initialize the CC1101, User can modify it
INPUT : None
OUTPUT : None
================================================================================
*/
void CC1101Init( SPI_HandleTypeDef *hspi )
{
volatile uint8_t i, j;
CC1101Reset(hspi );
for( i = 0; i < 24; i++ )
{
CC1101WriteReg( CC1101InitData[i][0], CC1101InitData[i][1] ,hspi);
}
CC1101SetAddress( 0x05, BROAD_0AND255 ,hspi);
CC1101SetSYNC( 0x8799 ,hspi);
CC1101WriteReg(CC1101_MDMCFG1, 0x72,hspi); //Modem Configuration
CC1101WriteMultiReg(CC1101_PATABLE, PaTabel, 8 ,hspi);
//CC1101WriteReg(CC1101_FREND0,0x40);
i = CC1101ReadStatus( CC1101_PARTNUM ,hspi);//for test, must be 0x80
i = CC1101ReadStatus( CC1101_VERSION ,hspi);//for test, refer to the datasheet
CC1101WriteReg(CC1101_TEST1,0xaa,hspi);
i=CC1101ReadStatus(CC1101_TEST1,hspi);
i=0;
}
cc1101.h:
#ifndef __CC1101_H
#define __CC1101_H
#include "main.h"
#include "gpio.h"
//#include "delay.h"
/* define ********************************************************************/
//#define CSN PAout(4)
#define CSN_set HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET) // оƬѡÔñ Serial configuration interface, chip
#define CSN_reset HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET) // оƬѡÔñ Serial configuration interface, chip select (MCU output)
#define GDO0 HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1) // cc1101µÄͨÓÃÊä³ö Digital output pin for general use (MCU input)
#define MISO HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6) // cc1101µÄÊý¾ÝÊä³ö Serial configuration interface,data output (MCU input)
typedef enum {false,true}bool;
/* **********************************************************************/
typedef enum { TX_MODE, RX_MODE }TRMODE;
typedef enum { BROAD_ALL, BROAD_NO, BROAD_0, BROAD_0AND255 }ADDR_MODE;
typedef enum { BROADCAST, ADDRESS_CHECK} TX_DATA_MODE;
extern uint8_t Rx_Flag;
/* ?? **********************************************************************/
/*read a byte from the specified register*/
uint8_t CC1101ReadReg( uint8_t addr , SPI_HandleTypeDef *hspi);
/*Read a status register*/
uint8_t CC1101ReadStatus( uint8_t addr , SPI_HandleTypeDef *hspi);
/*Set the device as TX mode or RX mode*/
void CC1101SetTRMode( TRMODE mode , SPI_HandleTypeDef *hspi);
/*Write a command byte to the device*/
void CC1101WriteCmd( uint8_t command , SPI_HandleTypeDef *hspi);
/*Set the CC1101 into IDLE mode*/
void CC1101SetIdle( SPI_HandleTypeDef *hspi );
/*Send a packet*/
void CC1101SendPacket( uint8_t *txbuffer, uint8_t size, TX_DATA_MODE mode ,SPI_HandleTypeDef *hspi);
/*Set the address and address mode of the CC1101*/
void CC1101SetAddress( uint8_t address, ADDR_MODE AddressMode,SPI_HandleTypeDef *hspi);
/*Set the SYNC bytes of the CC1101*/
void CC1101SetSYNC( uint16_t sync ,SPI_HandleTypeDef *hspi);
/*Receive a packet*/
uint8_t CC1101RecPacket( uint8_t *rxBuffer ,SPI_HandleTypeDef *hspi);
/*Initialize the WOR function of CC1101*/
void CC1101WORInit(SPI_HandleTypeDef *hspi );
/*Initialize the CC1101, User can modify it*/
void CC1101Init( SPI_HandleTypeDef *hspi );
void CC1101Reset( SPI_HandleTypeDef *hspi );
//*****************************************************************************************
// CC1100 STROBE, CONTROL AND STATUS REGSITER
#define CC1101_IOCFG2 0x00 // GDO2 output pin configuration
#define CC1101_IOCFG1 0x01 // GDO1 output pin configuration
#define CC1101_IOCFG0 0x02 // GDO0 output pin configuration
#define CC1101_FIFOTHR 0x03 // RX FIFO and TX FIFO thresholds
#define CC1101_SYNC1 0x04 // Sync word, high u8
#define CC1101_SYNC0 0x05 // Sync word, low u8
#define CC1101_PKTLEN 0x06 // Packet length
#define CC1101_PKTCTRL1 0x07 // Packet automation control
#define CC1101_PKTCTRL0 0x08 // Packet automation control
#define CC1101_ADDR 0x09 // Device address
#define CC1101_CHANNR 0x0A // Channel number
#define CC1101_FSCTRL1 0x0B // Frequency synthesizer control
#define CC1101_FSCTRL0 0x0C // Frequency synthesizer control
#define CC1101_FREQ2 0x0D // Frequency control word, high u8
#define CC1101_FREQ1 0x0E // Frequency control word, middle u8
#define CC1101_FREQ0 0x0F // Frequency control word, low u8
#define CC1101_MDMCFG4 0x10 // Modem configuration
#define CC1101_MDMCFG3 0x11 // Modem configuration
#define CC1101_MDMCFG2 0x12 // Modem configuration
#define CC1101_MDMCFG1 0x13 // Modem configuration
#define CC1101_MDMCFG0 0x14 // Modem configuration
#define CC1101_DEVIATN 0x15 // Modem deviation setting
#define CC1101_MCSM2 0x16 // Main Radio Control State Machine configuration
#define CC1101_MCSM1 0x17 // Main Radio Control State Machine configuration
#define CC1101_MCSM0 0x18 // Main Radio Control State Machine configuration
#define CC1101_FOCCFG 0x19 // Frequency Offset Compensation configuration
#define CC1101_BSCFG 0x1A // Bit Synchronization configuration
#define CC1101_AGCCTRL2 0x1B // AGC control
#define CC1101_AGCCTRL1 0x1C // AGC control
#define CC1101_AGCCTRL0 0x1D // AGC control
#define CC1101_WOREVT1 0x1E // High u8 Event 0 timeout
#define CC1101_WOREVT0 0x1F // Low u8 Event 0 timeout
#define CC1101_WORCTRL 0x20 // Wake On Radio control
#define CC1101_FREND1 0x21 // Front end RX configuration
#define CC1101_FREND0 0x22 // Front end TX configuration
#define CC1101_FSCAL3 0x23 // Frequency synthesizer calibration
#define CC1101_FSCAL2 0x24 // Frequency synthesizer calibration
#define CC1101_FSCAL1 0x25 // Frequency synthesizer calibration
#define CC1101_FSCAL0 0x26 // Frequency synthesizer calibration
#define CC1101_RCCTRL1 0x27 // RC oscillator configuration
#define CC1101_RCCTRL0 0x28 // RC oscillator configuration
#define CC1101_FSTEST 0x29 // Frequency synthesizer calibration control
#define CC1101_PTEST 0x2A // Production test
#define CC1101_AGCTEST 0x2B // AGC test
#define CC1101_TEST2 0x2C // Various test settings
#define CC1101_TEST1 0x2D // Various test settings
#define CC1101_TEST0 0x2E // Various test settings
// Strobe commands
#define CC1101_SRES 0x30 // Reset chip.
#define CC1101_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1).
// If in RX/TX: Go to a wait state where only the synthesizer is
// running (for quick RX / TX turnaround).
#define CC1101_SXOFF 0x32 // Turn off crystal oscillator.
#define CC1101_SCAL 0x33 // Calibrate frequency synthesizer and turn it off
// (enables quick start).
#define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and
// MCSM0.FS_AUTOCAL=1.
#define CC1101_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if
// MCSM0.FS_AUTOCAL=1. If in RX state and CCA is enabled:
// Only go to TX if channel is clear.
#define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit
// Wake-On-Radio mode if applicable.
#define CC1101_SAFC 0x37 // Perform AFC adjustment of the frequency synthesizer
#define CC1101_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio)
#define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high.
#define CC1101_SFRX 0x3A // Flush the RX FIFO buffer.
#define CC1101_SFTX 0x3B // Flush the TX FIFO buffer.
#define CC1101_SWORRST 0x3C // Reset real time clock.
#define CC1101_SNOP 0x3D // No operation. May be used to pad strobe commands to two
// u8s for simpler software.
#define CC1101_PARTNUM 0x30
#define CC1101_VERSION 0x31
#define CC1101_FREQEST 0x32
#define CC1101_LQI 0x33
#define CC1101_RSSI 0x34
#define CC1101_MARCSTATE 0x35
#define CC1101_WORTIME1 0x36
#define CC1101_WORTIME0 0x37
#define CC1101_PKTSTATUS 0x38
#define CC1101_VCO_VC_DAC 0x39
#define CC1101_TXBYTES 0x3A
#define CC1101_RXBYTES 0x3B
#define CC1101_PATABLE 0x3E
#define CC1101_TXFIFO 0x3F
#define CC1101_RXFIFO 0x3F
#define WRITE_BURST 0x40 //????
#define READ_SINGLE 0x80 //?
#define READ_BURST 0xC0 //???
#define BYTES_IN_RXFIFO 0x7F //???????????
#define CRC_OK 0x80 //CRC???????
#endif
参考文档: