📄 halrfrssi.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 EXAMPLE PROGRAM *
* *** + + *** RF+RSSI+ADC test program *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* This program demonstrates the use of the HAL RF+RSSI+ADC+UART functions. *
* *
* Use the CC1010EB switches (1-4) to transmit a standard packet. *
* *
* CC1010EB LEDs: *
* Blue: Transmitting *
* Yellow: Receiving *
* Red: Transmission/reception failed *
* Green: Transmission/reception OK *
* *
* The receiver will not respond unless the incomming radio carrier signal *
* is stronger/above a pre-defined threshold. *
* *
* Connect a standard Hyperterminal to CC1010EB serial port 0 for diagnostic *
* monitoring. Apply the following Hyperterminal settings: *
* 57600 bit/sec, 8 data bit, No parity, 1 stop bit, No flow control *
*****************************************************************************
* Author: TOS/JOL *
*****************************************************************************
* $Log: halRFRSSI.c,v $
* Revision 1.1 2004/01/12 16:41:43 tos
* Initial version in CVS.
*
*
* *
****************************************************************************/
#include <chipcon/reg1010.h>
#include <chipcon/cc1010eb.h>
#include <chipcon/hal.h>
#include <stdio.h>
// Protocol constants
#define PREAMBLE_BYTE_COUNT 7
#define PREAMBLE_BITS_SENSE 16
// Test packet
#define TEST_STRING_LENGTH 10
#define ACK_LENGTH 1
#define ACK_BYTE 0x42
byte testString[TEST_STRING_LENGTH];
byte ackString[ACK_LENGTH];
byte receivedString[TEST_STRING_LENGTH];
extern byte halRFReceivePacket2(byte timeOut, byte* packetData, byte maxLength, char* rssiByte, word clkFreq);
// Define ASCII codes / terminal commands
#define ASCII_LF 0x0A
#define ASCII_CR 0x0D
#define ASCII_NUL 0x00
#define ASCII_ESC 0x1B
// Define RSSI limit for response
#define RSSI_LIM -75
/*****************************************************************************
MAIN PROGRAM
*****************************************************************************/
void main(void) {
int n;
byte result;
char rssi_val;
float temp_val;
int pot_val;
int count = 0;
#ifdef FREQ868
// X-tal frequency: 14.745600 MHz
// RF frequency A: 868.277200 MHz Rx
// RF frequency B: 868.277200 MHz Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 4 dBm
// IF/RSSI: RSSI Enabled
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
0x4B, 0x2F, 0x15, // Modem 0, 1 and 2: Manchester, 2.4 kBaud
//0x43, 0x2F, 0x15, // Modem 0, 1 and 2: NRZ, 2.4 kBaud
//0xA1, 0x2F, 0x29, // Modem 0, 1 and 2: NRZ, 38.4 kBaud
//0xA0, 0x2F, 0x52, // Modem 0, 1 and 2: NRZ, 76.8 kBaud
0x75, 0xA0, 0x00, // Freq A
0x58, 0x32, 0x8D, // Freq B
0x01, 0xAB, // FSEP 1 and 0
0x40, // PLL_RX
0x30, // PLL_TX
0x6C, // CURRENT_RX
0xF3, // CURRENT_TX
0x32, // FREND
0xFF, // PA_POW
0x00, // MATCH
0x00, // PRESCALER
};
#endif
#ifdef FREQ915
// X-tal frequency: 14.745600 MHz
// RF frequency A: 915.027455 MHz Rx
// RF frequency B: 915.027455 MHz Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 4 dBm
// IF/RSSI: RSSI Enabled
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
0x4B, 0x2F, 0x15, // Modem 0, 1 and 2
0xAA, 0x80, 0x00, // Freq A
0x5C, 0xF4, 0x02, // Freq B
0x01, 0xAB, // FSEP 1 and 0
0x58, // PLL_RX
0x30, // PLL_TX
0x6C, // CURRENT_RX
0xF3, // CURRENT_TX
0x32, // FREND
0xFF, // PA_POW
0x00, // MATCH
0x00, // PRESCALER
};
#endif
#ifdef FREQ433
// X-tal frequency: 14.745600 MHz
// RF frequency A: 433.302000 MHz Rx
// RF frequency B: 433.302000 MHz Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 10 dBm
// IF/RSSI: RSSI Enabled
RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
0x4B, 0x2F, 0x0E, // Modem 0, 1 and 2
0x58, 0x00, 0x00, // Freq A
0x41, 0xFC, 0x9C, // Freq B
0x02, 0x80, // FSEP 1 and 0
0x60, // PLL_RX
0x48, // PLL_TX
0x44, // CURRENT_RX
0x81, // CURRENT_TX
0x0A, // FREND
0xFF, // PA_POW
0xC0, // MATCH
0x00, // PRESCALER
};
#endif
// Calibration data
RF_RXTXPAIR_CALDATA xdata RF_CALDATA;
// Setup UART0 with polled I/O
UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);
// Setup+initialise RSSI (including ADC config+powerup)
halRFReadRSSIlevel(RSSI_MODE_INIT);
// Clear screen
printf("%c[2J", ASCII_ESC);
// Place cursor at upper left corner
printf("%c[H", ASCII_ESC);
// Initialize peripherals
WDT_ENABLE(FALSE);
RLED_OE(TRUE);
YLED_OE(TRUE);
GLED_OE(TRUE);
BLED_OE(TRUE);
// Set optimum settings for speed and low power consumption
MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);
// Ready for acknowledge
ackString[0] = ACK_BYTE;
// Calibration
halRFCalib(&RF_SETTINGS, &RF_CALDATA);
// Turn on RF for RX
halRFSetRxTxOff(RF_RX, &RF_SETTINGS, &RF_CALDATA);
while (TRUE) {
if (SW1_PRESSED || SW2_PRESSED || SW3_PRESSED || SW4_PRESSED) { // TX
YLED = LED_OFF;
BLED = LED_ON;
// Build test packet
for (n = 0; n < TEST_STRING_LENGTH; n++) {
testString[n] = n;
}
// Turn on RF, send packet
halRFSetRxTxOff(RF_TX, &RF_SETTINGS, &RF_CALDATA);
halRFSendPacket(PREAMBLE_BYTE_COUNT, &testString[0], TEST_STRING_LENGTH);
// Turn on RF, receive ACK, turn off RF
halRFSetRxTxOff(RF_RX, &RF_SETTINGS, &RF_CALDATA);
result = halRFReceivePacket2(100/10, &receivedString[0], ACK_LENGTH, 0, CC1010EB_CLKFREQ);
// Success/failure indicators
if ((result == ACK_LENGTH) && (receivedString[0] == ACK_BYTE)) {
RLED = LED_OFF;
GLED = LED_ON;
} else {
RLED = LED_ON;
}
// Wait, then turn off LEDs
halWait(40, CC1010EB_CLKFREQ);
GLED = LED_OFF;
RLED = LED_OFF;
} else { // RX
YLED = LED_ON;
BLED = LED_OFF;
// Send acknowledge if radio carrier (RSSI) detected:
if((rssi_val = halRFReadRSSIlevel(RSSI_MODE_RUN)) > RSSI_LIM){
// Turn on RF, receive test string packet, turn off RF
result = halRFReceivePacket2(500/10, &receivedString[0], TEST_STRING_LENGTH, 0, CC1010EB_CLKFREQ);
// Success/failure indicators
if (result == TEST_STRING_LENGTH) {
GLED = LED_ON;
halRFSetRxTxOff(RF_TX, &RF_SETTINGS, &RF_CALDATA);
halRFSendPacket(PREAMBLE_BYTE_COUNT, &ackString[0], ACK_LENGTH);
halRFSetRxTxOff(RF_RX, &RF_SETTINGS, &RF_CALDATA); // Back to RX
};
// Wait, then turn off LEDs
halWait(10, CC1010EB_CLKFREQ);
GLED = LED_OFF;
RLED = LED_OFF;
}
}
// Read the CC1010EM temperature sensor
temp_val = halReadTempSensor();
// Read the CC1010EB potentiometer sensor
pot_val = halReadPotSensor();
// Convert AD value into Celcius
temp_val -= 492;
temp_val /= 8.192;
// Display RSSI + Temperature + Potentiometer:
printf("%c[H", ASCII_ESC);
printf("\nRSSI = %4d dBm, TEMP = %3.2f celsius, POT = %2d, count = %d", (int)rssi_val, (float)temp_val, (int)pot_val, count++);
}
// Power down ADC:
// In this application example this instruction does not have
// any effect, since it is placed outside the infinite loop above.
// However, if the "real" application needs to, for instance,
// enter a power save mode, then it might be important power down
// the ADC to save as much power as possible.
ADC_POWER(FALSE);
} // end of main()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -