📄 main.c
字号:
// ITSLcdWriteValue(rdata[0], HAL_LCD_RADIX_HEX, 0);
// counter = ITSRfGetChipVer();
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_TX, TRUE);
// ITSLcdWriteSymbol(HAL_LCD_SYMBOL_RX, FALSE);
// ITSMcuWaitUs(20000);
// preparePacket(counter, tdata, &packetLength);
// ITSMcuWaitUs(40000);
// txSendPacket(tdata, packetLength);
// ITSMcuWaitUs(20000);
}
else
{
ITSMcuWaitUs(20000);
}
}
buttonPushed = FALSE;
// ITSUartWrite("\n\rdata send");
ITSMcuWaitUs(20000);
j=(UART_RX_Buffer[3]-0x30)*10 + (UART_RX_Buffer[4]-0x30);
ITSRfWriteReg(CC1100_SYNC1 , j); // Packet length.
j=0;
j=(UART_RX_Buffer[5]-0x30)*10 + (UART_RX_Buffer[6]-0x30);
ITSRfWriteReg(CC1100_SYNC0 , j); // Packet length.
// Connect TX interrupt to event on GDO0
ITSDigioIntSetEdge(&pinGDO0, HAL_DIGIO_INT_FALLING_EDGE);
ITSDigioIntConnect(&pinGDO0, &txISR);
ITSDigioIntEnable(&pinGDO0);
// Create a dummy packet
preparePacket(15, tdata, &packetLength);
// Send packet
ITSMcuWaitUs(10000);
txSendPacket(tdata, packetLength);
ITSMcuWaitUs(20000);
for(j=0;j<10;j++)
{
UART_RX_Buffer[j]='\0';
}
ITSRfResetChip();
// Display number of packets sent
// ITSLcdWriteValue(0, HAL_LCD_RADIX_HEX, 0);*/
}
/*
while(0)
{
ITSUartWrite("Intrigue Tech Solution welcome you\n\r");
data=ITSRfGetChipVer();
}
*/
return 0;
}
#pragma vector=UART1RX_VECTOR
__interrupt void usart1_rx (void)
{
// while (!(IFG2 & UTXIFG1)); // USART0 TX buffer ready?
// TXBUF1 = RXBUF1; // RXBUF0 to TXBUF0
U1IFG &= ~URXIFG1; // Clear USART1 RX interrupt flag
char RxChar;
RxChar = RXBUF1;
//if((UART_Status & LineReceived) == 0) // ignore if last Buffer has not been processed
//{
switch (RxChar)
{
case 0x00: //ignore NUL
break;
case 0x08: // Backspace
if (UART_RX_Bytes >0)
{
UART_RX_Bytes--; // Dec index if buffer not empty
UART_RX_Buffer[UART_RX_Bytes] = 0; // Erase previous char
}
break;
case 0x0A: //ignore LF
break;
case '#': //Line Received
//UART_Status |= LineReceived;
//LPM3_EXIT; // Exit Low Power Mode 3
LPM0_EXIT;
buttonPushed=TRUE;
UART_RX_Buffer[UART_RX_Bytes] = RxChar;
UART_RX_Bytes=0;
RxChar = 0;
break;
case 0x1B: //<ESC> -> Clear Buffer
UART_RX_Bytes = 0; //Clear RX Buffer
break;
case '-': //'-' for Calibration
case '+': //'+' for Calibration
//? case 0x30: //'0' special single char received
//UART_Status |= LineReceived;
//LPM3_EXIT; // Exit Low Power Mode 3
//break;
default: // Byte received -> move to Buffer
if ((RxChar >= 'a') && (RxChar <= 'z'))
{UART_RX_Buffer[UART_RX_Bytes] = RxChar-0x20;} // Convert to upper-case
else
{UART_RX_Buffer[UART_RX_Bytes] = RxChar;}
if (UART_RX_Bytes < UART_RX_Buffer_Size)
{
UART_RX_Bytes++; // Inc index if buffer not full
}
break;
}
//}
// buttonPushed=1;
}
//----------------------------------------------------------------------------------
// uint8 txSendPacket(uint8* data, uint8 length)
//
// DESCRIPTION:
// Send a packet that is smaller than the size of the FIFO, making it possible
// to write the whole packet at once. Wait for the radio to signal that the packet
// has been transmitted.
//
// ARGUMENTS:
// data - Data to send. First byte contains length byte
// length - Total length of packet to send
//
// RETURNS:
// This function always returns 0.
//----------------------------------------------------------------------------------
static uint8 txSendPacket(uint8* data, uint8 length)
{
uint16 key;
packetSent = FALSE;
// Write data to FIFO
ITSRfWriteFifo(data, length);
// Set radio in transmit mode
ITSRfStrobe(CC1100_STX);
// Wait for packet to be sent
#if 1
key = ITSIntLock();
while(!packetSent)
{
ITSMcuSetLowPowerMode(HAL_MCU_LPM_0);
key = ITSIntLock();
}
ITSIntUnlock(key);
#endif
return(0);
}
//----------------------------------------------------------------------------------
// uint8 rxRecvPacket(uint8* data, uint8* length)
//
// DESCRIPTION:
// Receive a packet that is smaller than the size of the FIFO, i.e. wait for the
// complete packet to be received before reading from the FIFO. This function sets
// the CC1100/CC1100 in RX and waits for the chip to signal that a packet is received.
//
// ARGUMENTS:
// data - Where to write incoming data.
// length - Length of payload.
//
// RETURNS:
// 0 if a packet was received successfully.
// 1 if chip is in overflow state (packet longer than FIFO).
// 2 if the length of the packet is illegal (0 or > 61).
// 3 if the CRC of the packet is not OK.
//----------------------------------------------------------------------------------
uint8 status;
static uint8 rxRecvPacket(uint8* data, uint8* length)
{
uint8 packet_status[2];
uint16 key;
packetReceived = FALSE;
status = RX_OK;
// Set radio in RX mode
ITSRfStrobe(CC1100_SRX);
// Wait for incoming packet
key = ITSIntLock();
while(!packetReceived)
{
ITSMcuSetLowPowerMode(HAL_MCU_LPM_0);
key = ITSIntLock();
if(buttonPushed==1)
{
// U1ME |= UTXE1;
return 1;
}
}
// ITSRfStrobe(CC1100_SPWD);
ITSIntUnlock(key);
ITSUartWrite("\n\r IN CRC CHECK");
// Read first element of packet from the RX FIFO
status = ITSRfReadFifo(length, 1);
if ((status & CC1100_STATUS_STATE_BM) == CC1100_STATE_RX_OVERFLOW)
{
ITSRfStrobe(CC1100_SIDLE);
ITSRfStrobe(CC1100_SFRX);
status = RX_FIFO_OVERFLOW;
}
else if (*length == 0 || *length > 61)
{
ITSRfStrobe(CC1100_SIDLE);
ITSRfStrobe(CC1100_SFRX);
status = RX_LENGTH_VIOLATION;
}
else
{
// Get payload
ITSRfReadFifo(data, *length);
// Get the packet status bytes [RSSI, LQI]
ITSRfReadFifo(packet_status, 2);
// Check CRC
if ((packet_status[1] & CC1100_LQI_CRC_OK_BM) != CC1100_LQI_CRC_OK_BM)
{
// ITSUartWrite("\n\r IN CRC CHECK");
status = RX_CRC_MISMATCH;
}
else
{
// ITSUartWrite("\n\r IN READ DATA");
status = RX_OK;
}
// ITSRfWriteReg(CC1100_PKTCTRL1, 0x08); // Enable append mode
}
return(status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -