Implementing UART Communication in BasicRF Point-to-Point Networks
Hardware Reqiurements
- Two development boards
- Two antennas
- USB-to-serial converter
- Debugger
- Jumper wires
- USB cables
- Power cables
Code Implementation (rf_config.c)
#include "hal_defs.h"
#include "hal_cc8051.h"
#include "hal_int.h"
#include "hal_mcu.h"
#include "hal_board.h"
#include "hal_led.h"
#include "hal_rf.h"
#include "basic_rf.h"
#include "hal_uart.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
// Network configuration
#define RF_FREQUENCY 20 // Channel 11-26
#define NETWORK_ID 0x1A2C // PAN identifier
#define DEVICE_A 1
#if DEVICE_A
#define LOCAL_ADDRESS 0x105C
#define DEST_ADDRESS 0x2F1B
#else
#define LOCAL_ADDRESS 0x2F1B
#define DEST_ADDRESS 0x105C
#endif
// GPIO definitions
#define LED1 P1_3
#define LED2 P1_1
#define LED3 P1_0
#define LED4 P1_4
static basicRfCfg_t rfConfig;
uint8_t receivedData;
uint8_t transmitData;
uint8_t dataReadyFlag;
void initializeRfModule() {
rfConfig.panId = NETWORK_ID;
rfConfig.channel = RF_FREQUENCY;
rfConfig.myAddr = LOCAL_ADDRESS;
rfConfig.ackRequest = TRUE;
while(basicRfInit(&rfConfig) == FAILED);
basicRfReceiveOn();
}
void configureGpio() {
P1DIR |= 0x1B;
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
}
void sendUartByte(uint8_t data) {
U0DBUF = data;
while(UTX0IF == 0);
UTX0IF = 0;
}
void sendUartString(uint8_t *str) {
while(*str != '\0') {
sendUartByte(*str++);
}
}
#pragma vector = URX0_VECTOR
__interrupt void uartRxIsr() {
transmitData = U0DBUF;
dataReadyFlag = 1;
}
void main() {
halBoardInit();
initializeRfModule();
configureGpio();
#if DEVICE_A
halUartInit(9600);
sendUartString("System Ready\n");
#endif
while(1) {
#if DEVICE_A
if(dataReadyFlag) {
dataReadyFlag = 0;
basicRfSendPacket(DEST_ADDRESS, &transmitData, 1);
}
#endif
if(basicRfPacketIsReady()) {
basicRfReceive(&receivedData, 1, NULL);
switch(receivedData) {
case 0xD3: LED1 = ~LED1; break;
case 0xD4: LED2 = ~LED2; break;
case 0xD5: LED3 = ~LED3; break;
case 0xD6: LED4 = ~LED4; break;
}
}
}
}
Setup Instructions
-
For Device A:
- Connect debugger
- Flash firmware with
DEVICE_Adefined as 1
-
For Device B:
- Connect debugger
- Flash firmware with
DEVICE_Acommented out
-
Configure serial terminal:
- Select correct COM port
- Set baud rate to 9600
- Send commands (D3, D4, D5, D6) to control LEDs individually
Notes
- Current implementation supports single-command LED control
- Commands are case-sensitive
- Ensure proper antenna placement for reliable RF communication