📄 main.c
字号:
#include "ITS_types.h"
#include "ITS_defs.h"
#include "ITS_board.h"
#include "ITS_spi.h"
#include "ITS_int.h"
#include "ITS_mcu.h"
#include "ITS_uart.h"
#include "ITS_rf.h"
#include "cc1100.h"
#include <stdlib.h>
#include <string.h>
#include "my_rf_settings.h"
#define UART_RX_Buffer_Size 40
unsigned char UART_RX_Buffer[UART_RX_Buffer_Size];
unsigned int UART_RX_Bytes;
unsigned int UART_Status;
//----------------------------------------------------------------------------------
// Constants used in this file
//----------------------------------------------------------------------------------
#define RADIO_MODE_TX 1
#define RADIO_MODE_RX 2
#define RX_OK 0
#define RX_LENGTH_VIOLATION 1
#define RX_CRC_MISMATCH 2
#define RX_FIFO_OVERFLOW 3
#define FIFO_THRESHOLD 0x07
#define FIFO_THRESHOLD_BYTES 32
#define FIFO_SIZE 64
//----------------------------------------------------------------------------------
// Variables used in this file
//----------------------------------------------------------------------------------
static volatile uint8 radioMode;
static volatile uint8 radioModeSet = FALSE;
static volatile uint8 buttonPushed = FALSE;
static volatile uint8 packetSent;
static volatile uint8 packetReceived;
uint8 rdata[64];
uint8 tdata[64];
//----------------------------------------------------------------------------------
// Function declarations
//----------------------------------------------------------------------------------
static uint8 txSendPacket(uint8* data, uint8 length);
static uint8 rxRecvPacket(uint8* data, uint8* length);
void rxInit(void);
static void txISR(void);
static void rxISR(void);
static void myTxButtonISR(void);
static void myRxButtonISR(void);
//----------------------------------------------------------------------------------
// void txISR(void)
//
// DESCRIPTION:
// This function is called (in interrupt context) every time a packet has been
// transmitted.
//----------------------------------------------------------------------------------
static void txISR(void)
{
packetSent = TRUE;
}
//----------------------------------------------------------------------------------
// void rxISR(void)
//
// DESCRIPTION:
// This function is called (in interrupt context) every time a packet has been
// revceived.
//----------------------------------------------------------------------------------
static void rxISR(void)
{
packetReceived = TRUE;
}
//----------------------------------------------------------------------------------
// void myRxButtonISR(void)
//
// DESCRIPTION:
// This function is called when the S1 button is pressed.
// Selects mode of operation the first time it runs.
//----------------------------------------------------------------------------------
static void myRxButtonISR(void)
{
if (!radioModeSet)
{
radioMode = RADIO_MODE_RX;
radioModeSet = TRUE;
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_ANT, TRUE);
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_RX, TRUE);
}
buttonPushed = TRUE;
}
//----------------------------------------------------------------------------------
// void myTxButtonISR(void)
//
// DESCRIPTION:
// This function is called when the S2 button is pressed.
// Selects mode of operation the first time it runs.
//----------------------------------------------------------------------------------
static void myTxButtonISR(void)
{
if (!radioModeSet)
{
radioMode = RADIO_MODE_TX;
radioModeSet = TRUE;
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_ANT, TRUE);
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_TX, TRUE);
}
buttonPushed = TRUE;
// P2IFG &= 0xF7;
}
//----------------------------------------------------------------------------------
// void preparePacket(uint8 id, uint8* data, uint8* length)
//
// DESCRIPTION:
// Set up a dummy packet, where the first byte contains the length of the payload
// and the first byte of the payload contains a packet id.
//----------------------------------------------------------------------------------
static void preparePacket(uint8 id, uint8* data, uint8* length)
{
uint8 i,j;
uint8 payloadLength=3;
// payloadLength++;
// if (payloadLength > 61)
// payloadLength = 1;
// First byte of packet contains the length of the payload
data[0] = payloadLength;
// First byte of payload contains an id
// data[1] = 'V';
// data[2] = '5';
/* data[3] = 30;
data[4] = 40;
data[5] = 50;
data[6] = 60;
data[7] = 70;*/
for(i=0;i<3;i++)
{
data[i+1]=UART_RX_Buffer[i];
payloadLength++;
}
data[0] = payloadLength;
// Fill rest of packet with dummy data*/
for (j = 4; j <= 64; j++)
data[j] = 0;
// Packet length is payload + length byte
*length = payloadLength + 1;
}
char id,ver;
unsigned char temp[30];
int j;
int main( void )
{
// Stop watchdog timer to prevent time out reset
ITSBoardInit();
ITSRfResetChip();
id = ITSRfGetChipId();
ver = ITSRfGetChipVer();
ITSRfStrobe(CC1100_SPWD);
ITSUartWrite("WEL COME.....\n\r");
// Set up interrupts for events on the S1 and S2 buttons
/* ITSDigioIntSetEdge(&pinS1, HAL_DIGIO_INT_RISING_EDGE);
ITSDigioIntConnect(&pinS1, &myRxButtonISR);
ITSDigioIntEnable(&pinS1);*/
/* ITSDigioIntSetEdge(&pinS2, HAL_DIGIO_INT_RISING_EDGE);
ITSDigioIntConnect(&pinS2, &myTxButtonISR);
ITSDigioIntEnable(&pinS2);*/
// Setup chip with register settings from SmartRF Studio
ITSRfConfigCC1100(&myRfConfig, myPaTable, myPaTableLen);
// Additional chip configuration for this example
ITSRfWriteReg(CC1100_MCSM0, 0x18); // Calibration from IDLE to TX/RX
ITSRfWriteReg(CC1100_MCSM1, 0x00); // No CCA, IDLE after TX and RX
ITSRfWriteReg(CC1100_PKTCTRL0, 0x45); // Enable data whitening and CRC
ITSRfWriteReg(CC1100_PKTCTRL1, 0x0C);// Enable append mode
ITSRfWriteReg(CC1100_IOCFG0, 0x06); // Set GDO0 to be packet received signal
// In this example, the packets being sent are smaller than the size of the
// FIFO, thus all larger packets should be discarded. The packet length
// filtering on the receiver side is necessary in order to handle the
// CC1100 RX FIFO overflow errata, described in the CC1100 Errata Note.
// Given a FIFO size of 64, the maximum packet is set such that the FIFO
// has room for the length byte + payload + 2 appended status bytes (giving
// a maximum payload size of 64 - 1 - 2 = 61.
ITSRfWriteReg(CC1100_PKTLEN, 61); // Max payload data length
uint16 counter;
uint8 payloadLength;
uint8 packetLength;
counter = 0;
while(1)
{
while (!buttonPushed)
{
// ITSRfStrobe(CC1100_SRX);
ITSDigioIntSetEdge(&pinGDO0, HAL_DIGIO_INT_FALLING_EDGE);
ITSDigioIntConnect(&pinGDO0, &rxISR);
ITSDigioIntEnable(&pinGDO0);
if (rxRecvPacket(rdata, &payloadLength) == 0)
{
ITSMcuWaitUs(20);
// ITSUartWrite("Data receive");
ITSUartWrite((char *)rdata);
// memset(rdata,'\0',64);
// ITSDigioIntDisable(&pinGDO0);
ITSUartWrite("\n\r");
for(j=0;j<64;j++)
{
rdata[j]='\0';
}
ITSRfResetChip();
ITSRfWriteReg(CC1100_SYNC0 , 0X55); // Packet length.
ITSRfWriteReg(CC1100_SYNC1 , 0X22); // Packet length.
// U1ME &= ~UTXE1;
// ITSDigioIntConnect(&pinGDO0, &txISR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -