This example describes how to make a wireless communication between two CORTEX Boards using ZIGBEE.We have used cortex m4 development board for this experiment
Procedure to Interface Zigbee with Cortex m4
- Power: In the PCONP register, set bit PCUART3
- Configure pins P0.0 and P0.1 as UART3 TX and RX using IOCON_P0_0 and IOCON_P0_1.
- Configure UART3 for 9600 baud, 8 data bits, 1 stop bit (for both CORTEX Board)
Transmitter: - Power: In the PCONP register, Set the PCGPIO bit
- Configure pins P4.8 to P4.15 as GPIO pins using IOCON registers
- Configure SLIDE SWITCH pins P4.8 to P4.15 as input
- Read the Slide switch positions
- Transmit over UART3/ZIGBEE
Receiver: - Power: In the PCONP register, Set the PCGPIO bit
- Configure pins P4.0 to P4.7 as GPIO pins
- Configure LED pins P4.0 to P4.7 as output
- Receive the data from UART3/ZIGBEE and display it in LED
Interface Zigbee with Cortex m4 – C Source code -Transmitter
#include "LPC407x_8x_177x_8x.h"
unsigned char recval=0;
unsigned char UART3_Receive(void);
void UART3_Txmt(unsigned char Chr);
void init_serial(void);
void UART3_puts(unsigned char *string);
void init_switch(void);
void delay_ms(long ms);
int main(void)
{
init_serial();
init_switch();
while(1)
{
//7.Read the Slide switch positions
recval = ((LPC_GPIO4->PIN >> 8) & 0xFF);
//8.Transmit over ZIGBEE
UART3_Txmt(recval);
delay_ms(100);
}
}
void init_serial(void)
{
//1. set bit PCUART3
LPC_SC->PCONP |= (1 << 25); /* enable power to UART3*/
//2. Configure pins P0.0 and P0.1 as UART3 TX and RX
LPC_IOCON->P0_0 = 2; /* Pin P0.0 used as TXD3 */
LPC_IOCON->P0_1 = 2; /* Pin P0.1 used as RXD3 */
//3. Select Clock source and frequency=PCLK ie 30MHz
/* 8 bits, no Parity, 1 Stop bit */
LPC_UART3->LCR = 0x83;
//3. Derive baud rate from the UART clock source, Set DLAB=1 to access baud rate
// Register
// DLM:DLL=PCLK/(16*baud)= 30Mhz/(16*9600)= 195
LPC_UART3->DLL = 195; /* 9600 Baud Rate @ 30.0 MHZ PCLK*/
LPC_UART3->DLM = 0; /* MSB = 0 */
LPC_UART3->LCR = 0x03; /* DLAB = 0*/
}
//Transmit a character
void UART3_Txmt(unsigned char Chr)
{
while((LPC_UART3->LSR & 0x20)==0);
LPC_UART3->THR = Chr;
}
//Receive a character
unsigned char UART3_Receive(void)
{
while((LPC_UART3->LSR & 0x01)==0);
return(LPC_UART3->RBR);
}
//Transmit a string
void UART3_puts(unsigned char *string)
{
while(*string)
UART3_Txmt(*string++);
}
void init_switch(void)
{
//4. Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);
//5. Configure pins P4.8 to P4.15 as GPIO pins
LPC_IOCON->P4_8 = 0;
LPC_IOCON->P4_9 = 0;
LPC_IOCON->P4_10 = 0;
LPC_IOCON->P4_11 = 0;
LPC_IOCON->P4_12 = 0;
LPC_IOCON->P4_13 = 0;
LPC_IOCON->P4_14 = 0;
LPC_IOCON->P4_15 = 0;
//6. SWITCH pins P4.8 to P4.15 as input
LPC_GPIO4->DIR = 0x00FF;
}
void delay_ms(long ms) // delay 1 ms per count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}
Interface Zigbee with Cortex m4 – C Source code -Receiver
#include "LPC407x_8x_177x_8x.h"
unsigned char recval=0;
unsigned char UART3_Receive(void);
void UART3_Txmt(unsigned char Chr);
void init_serial(void);
void UART3_puts(unsigned char *string);
void init_switch(void);
void delay_ms(long ms);
int main(void)
{
init_serial();
init_switch();
while(1)
{
//12.Receive the data from UART3 and display it in LED
recval= UART3_Receive();
LPC_GPIO4->PIN = recval;
}
}
void init_serial(void)
{
//1. set bit PCUART3
LPC_SC->PCONP |= (1 << 25); /* enable power to UART3*/
//2. Configure pins P0.0 and P0.1 as UART3 TX and RX
LPC_IOCON->P0_0 = 2; /* Pin P0.0 used as TXD3 */
LPC_IOCON->P0_1 = 2; /* Pin P0.1 used as RXD3 */
//3. Select Clock source and frequency=PCLK ie 30MHz
/* 8 bits, no Parity, 1 Stop bit */
LPC_UART3->LCR = 0x83;
//3. Derive baud rate from the UART clock source, Set DLAB=1 to access baud rate
// Register
// DLM:DLL=PCLK/(16*baud)= 30Mhz/(16*9600)= 195
LPC_UART3->DLL = 195; /* 9600 Baud Rate @ 30.0 MHZ PCLK*/
LPC_UART3->DLM = 0; /* MSB = 0 */
LPC_UART3->LCR = 0x03; /* DLAB = 0*/
}
//Transmit a character
void UART3_Txmt(unsigned char Chr)
{
while((LPC_UART3->LSR & 0x20)==0);
LPC_UART3->THR = Chr;
}
//Receive a character
unsigned char UART3_Receive(void)
{
while((LPC_UART3->LSR & 0x01)==0);
return(LPC_UART3->RBR);
}
//Transmit a string
void UART3_puts(unsigned char *string)
{
while(*string)
UART3_Txmt(*string++);
}
void init_switch(void)
{
//9. Set the PCGPIO bit
LPC_SC->PCONP |= (1<<15);
//10. Configure pins P4.0 to P4.7 as GPIO pins
LPC_IOCON->P4_0 = 0;
LPC_IOCON->P4_1 = 0;
LPC_IOCON->P4_2 = 0;
LPC_IOCON->P4_3 = 0;
LPC_IOCON->P4_4 = 0;
LPC_IOCON->P4_5 = 0;
LPC_IOCON->P4_6 = 0;
LPC_IOCON->P4_7 = 0;
//11. Configure pins P4.0 to P4.7 as output
LPC_GPIO4->DIR = 0xFF;
}
void delay_ms(long ms) // delay 1 ms per count @ CCLK 120 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 26659; j++ );
}