LPC1769 to LPC1769 UART COMMUNICATION

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 to LPC1769 UART COMMUNICATION

2,700 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Fri Jun 14 04:52:50 MST 2013
Hi all,

I'm trying to use a LPC1769 to communicate with another using UART.

I'm using UART2  (TXD2,RXD2)P0.10,P0.11 respectively. I just connected directly from the LPC1 (RXD2) to the LPC2 (TXD2) and LPC1(TXD2) to the LPC2 (RXD2).

I connected a push button to P2.12 of LPC1 and tried to send a data via UART to LPC2 to on a LED on P2.12. However it does not seem to work. Can someone help me? Sorry I'm new to LPC1769.

LPC 1 :

#include <stdio.h>
#include "lpc_types.h"
#include "lpc17xx_clkpwr.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_uart.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_nvic.h"
#include<string.h>

void Init_GPIO(void)
{
        PINSEL_CFG_Type PinCfg2A;
        PinCfg2A.Funcnum = 0;
        PinCfg2A.OpenDrain=0;
        PinCfg2A.Pinmode=0;
        PinCfg2A.Portnum = 2;
        PinCfg2A.Pinnum = 12;
        PINSEL_ConfigPin (&PinCfg2A);   //pushbutton
}

/*------------------------------*/
/*---------Pinsel UART2---------*/
void pinsel_uart2(void)
{
        PINSEL_CFG_Type PinCfg;
        PinCfg.Funcnum = 1;
        PinCfg.OpenDrain=0;
        PinCfg.Portnum = 0;
        PinCfg.Pinnum = 10;
        PINSEL_ConfigPin (&PinCfg);   //transmitter
        PinCfg.Pinnum = 11;
        PINSEL_ConfigPin (&PinCfg);   //receiver
}
/*---------Pinsel UART2---------*/
/*------------------------------*/
/*------------------------------------------*/
/*---------Initialise UART---------*/
void Init_UART(void)
{
        UART_CFG_Type uartCfg;
        uartCfg.Baud_rate = 115200;
        uartCfg.Databits = UART_DATABIT_8;
        uartCfg.Parity = UART_PARITY_NONE;
        uartCfg.Stopbits = UART_STOPBIT_1;
        //Pin select for uart2
        pinsel_uart2();
        //Supply power & setup working par.s for uart2
        UART_Init(LPC_UART2, &uartCfg);
}
/*-----------------*/
/*------------------------------------------*/

int main(void)
{
SystemInit();
Init_GPIO();
Init_UART();//Initialise UART
int btn=1;
uint8_t Buffer[] = "1";
pinsel_uart2();
GPIO_SetDir(2, 1<<12, 0);//Configure Pin 2.12 as input pin
GPIO_SetDir(0, 1<<10, 1);//Output from UART P0.10
GPIO_SetDir(0, 1<<11, 0);//Input from UART P0.11
while(1)
{
btn = ((GPIO_ReadValue(2) >> 12) & 0x01);//btn to ground
if(btn==0)
{
UART_Send(LPC_UART2,(uint8_t *)Buffer,strlen(Buffer),NONE_BLOCKING );
}
}
}


LPC 2:



#include <stdio.h>
#include "lpc_types.h"
#include "lpc17xx_clkpwr.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_uart.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_nvic.h"
#include<string.h>

void Init_GPIO(void)
{
        PINSEL_CFG_Type PinCfg2A;
        PinCfg2A.Funcnum = 0;
        PinCfg2A.OpenDrain=0;
        PinCfg2A.Pinmode=0;
        PinCfg2A.Portnum = 2;
        PinCfg2A.Pinnum = 12;
        PINSEL_ConfigPin (&PinCfg2A);   //pushbutton
}

/*------------------------------*/
/*---------Pinsel UART2---------*/
void pinsel_uart2(void)
{
        PINSEL_CFG_Type PinCfg;
        PinCfg.Funcnum = 1;
        PinCfg.OpenDrain=0;
        PinCfg.Portnum = 0;
        PinCfg.Pinnum = 10;
        PINSEL_ConfigPin (&PinCfg);   //transmitter
        PinCfg.Pinnum = 11;
        PINSEL_ConfigPin (&PinCfg);   //receiver
}
/*---------Pinsel UART2---------*/
/*------------------------------*/
/*------------------------------------------*/
/*---------Initialise UART---------*/
void Init_UART(void)
{
        UART_CFG_Type uartCfg;
        uartCfg.Baud_rate = 115200;
        uartCfg.Databits = UART_DATABIT_8;
        uartCfg.Parity = UART_PARITY_NONE;
        uartCfg.Stopbits = UART_STOPBIT_1;
        //Pin select for uart2
        pinsel_uart2();
        //Supply power & setup working par.s for uart2
        UART_Init(LPC_UART2, &uartCfg);
}
/*-----------------*/
/*------------------------------------------*/

int main(void)
{
SystemInit();
Init_GPIO();
Init_UART();//Initialise UART
uint8_t Buffer;
pinsel_uart2();
GPIO_SetDir(2, 1<<12, 0);//Configure Pin 2.12 as input pin
GPIO_SetDir(0, 1<<10, 1);//Output from UART P0.10
GPIO_SetDir(0, 1<<11, 0);//Input from UART P0.11
while(1)
{
GPIO_ClearValue(2, 1<<12);
UART_Receive(LPC_UART2, &Buffer, 1, NONE_BLOCKING);//Check first char
if (Buffer=='1')
{
GPIO_SetValue(2, 1<<12);
}
}
}



Can someone help me? I'm currently doing it for a project and i dont have much time left.

Thank you!!!
0 Kudos
Reply
11 Replies

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Mon Jun 17 05:27:02 MST 2013
Hi,

using a RS232 to usb connection, i used tera terminal to test the transmission of data.And it did not seem to work. The connection for LPC to RS 232 i used is the RX,TXD and gnd (pins 2,3,5) pins, which is connected to the MAX233 and to the lpc.
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Sun Jun 16 10:46:40 MST 2013
Have you tested each LPC separately?
1) Take the first one and connect it to a standard serial port of a PC. You need a voltage level converter such as MAX3232 for that. Or a USB-UART bridge if you want to connect to a USB port.
2) Use a PC application such as hyperterminal (in windows) and check the data transmission and reception. Then repeat the test for the second LPC in a similar way.
3) If they do work like you expected, then it is time to connect both LPCs in the following manner.

LPC1-----               LPC2

  Tx       ---------      Rx
  Rx        ---------      Tx
Gnd     -------    Gnd

and it should work. :)
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Sat Jun 15 21:45:51 MST 2013

Quote: vasanth
Check your physical connection first. Ensure that the two microcontrollers have a common ground which means GND pin of LPC1 must be in connection with GND pin of LPC2.



i've checked the connections over and over again. everything seems to be fine. Is it the correct way to connect the LPC 1 RXD2 to TXD2 of LPC 2 and vice versa?
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Sat Jun 15 21:13:11 MST 2013
Check your physical connection first. Ensure that the two microcontrollers have a common ground which means GND pin of LPC1 must be in connection with GND pin of LPC2.
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Sat Jun 15 03:55:24 MST 2013
Hi, thanks for the quick reply. I'm still facing the same problem despite adding a delay. Below is my updated code:

LPC 1:
#include <stdio.h>
#include "lpc_types.h"
#include "lpc17xx_clkpwr.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_uart.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_nvic.h"
#include<string.h>

void Init_GPIO(void)
{
        PINSEL_CFG_Type PinCfg2A;
        PinCfg2A.Funcnum = 0;
        PinCfg2A.OpenDrain=0;
        PinCfg2A.Pinmode=0;
        PinCfg2A.Portnum = 2;
        PinCfg2A.Pinnum = 12;
        PINSEL_ConfigPin (&PinCfg2A);   //pushbutton
}

/*------------------------------*/
/*---------Pinsel UART2---------*/
void pinsel_uart2(void)
{
        PINSEL_CFG_Type PinCfg;
        PinCfg.Funcnum = 1;
        PinCfg.OpenDrain=0;
        PinCfg.Portnum = 0;
        PinCfg.Pinnum = 10;
        PINSEL_ConfigPin (&PinCfg);   //transmitter
        PinCfg.Pinnum = 11;
        PINSEL_ConfigPin (&PinCfg);   //receiver
}
/*---------Pinsel UART2---------*/
/*------------------------------*/
/*------------------------------------------*/
/*---------Initialise UART---------*/
void Init_UART(void)
{
        UART_CFG_Type uartCfg;
        uartCfg.Baud_rate = 115200;
        uartCfg.Databits = UART_DATABIT_8;
        uartCfg.Parity = UART_PARITY_NONE;
        uartCfg.Stopbits = UART_STOPBIT_1;
        //Pin select for uart2
        pinsel_uart2();
        //Supply power & setup working par.s for uart2
        UART_Init(LPC_UART2, &uartCfg);
}
/*-----------------*/
/*------------------------------------------*/

int main(void)
{
SystemInit();
Init_GPIO();
Init_UART();//Initialise UART
int btn=1;
uint8_t Buffer[] = "1";
GPIO_SetDir(2, 1<<12, 0);//Configure Pin 2.12 as input pin
GPIO_SetDir(0, 1<<10, 1);//Output from UART P0.10
GPIO_SetDir(0, 1<<11, 0);//Input from UART P0.11
while(1)
{
//printf("%s\n\r",Buffer);
btn = ((GPIO_ReadValue(2) >> 12) & 0x01);//btn to ground
if(btn==0)
{
UART_Send(LPC_UART2,(uint8_t *)Buffer,strlen(Buffer),NONE_BLOCKING );
}
}
}



LPC 2:




#include <stdio.h>
#include "lpc_types.h"
#include "lpc17xx_clkpwr.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_uart.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_nvic.h"
#include<string.h>

void Init_GPIO(void)
{
        PINSEL_CFG_Type PinCfg2A;
        PinCfg2A.Funcnum = 0;
        PinCfg2A.OpenDrain=0;
        PinCfg2A.Pinmode=0;
        PinCfg2A.Portnum = 2;
        PinCfg2A.Pinnum = 12;
        PINSEL_ConfigPin (&PinCfg2A);   //pushbutton
}

/*------------------------------*/
/*---------Pinsel UART2---------*/
void pinsel_uart2(void)
{
        PINSEL_CFG_Type PinCfg;
        PinCfg.Funcnum = 1;
        PinCfg.OpenDrain=0;
        PinCfg.Portnum = 0;
        PinCfg.Pinnum = 10;
        PINSEL_ConfigPin (&PinCfg);   //transmitter
        PinCfg.Pinnum = 11;
        PINSEL_ConfigPin (&PinCfg);   //receiver
}
/*---------Pinsel UART2---------*/
/*------------------------------*/
/*------------------------------------------*/
/*---------Initialise UART---------*/
void Init_UART(void)
{
        UART_CFG_Type uartCfg;
        uartCfg.Baud_rate = 115200;
        uartCfg.Databits = UART_DATABIT_8;
        uartCfg.Parity = UART_PARITY_NONE;
        uartCfg.Stopbits = UART_STOPBIT_1;
        //Pin select for uart2
        pinsel_uart2();
        //Supply power & setup working par.s for uart2
        UART_Init(LPC_UART2, &uartCfg);
}
/*-----------------*/
/*------------------------------------------*/

int main(void)
{
SystemInit();
Init_GPIO();
Init_UART();//Initialise UART
uint8_t Buffer;
GPIO_SetDir(2, 1<<12, 1);//Configure Pin 2.12 as output pin
GPIO_SetDir(0, 1<<10, 1);//Output from UART P0.10
GPIO_SetDir(0, 1<<11, 0);//Input from UART P0.11
while(1)
{
GPIO_ClearValue(2, 1<<12);
UART_Receive(LPC_UART2, &Buffer, 1, NONE_BLOCKING);//Check first char
if (Buffer=="1" )
{
GPIO_SetValue(2, 1<<12);
Timer0_Wait(1000);
}
}
}
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Fri Jun 14 23:30:42 MST 2013
    while(1)
    {
        GPIO_ClearValue(2, 1<<12);
        UART_Receive(LPC_UART2, &Buffer, 1, NONE_BLOCKING);    //Check first char
        if (Buffer=='1')
        {
             GPIO_SetValue(2, 1<<12);
             delay_1sec();   // add something like this
        }
    }
Provide some delay like above to make the LED light visible. Otherwise you might be clearing the LED immediately after setting it. Oops.:eek:
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Fri Jun 14 23:23:01 MST 2013
while(1)
{
        GPIO_ClearValue(2, 1<<12);
        UART_Receive(LPC_UART2, &Buffer, 1, NONE_BLOCKING);//Check first char
        if (Buffer=='1')
        {
             GPIO_SetValue(2, 1<<12);
             [COLOR = RED]
             delay_1sec();
             [/COLOR]
        }
}


Add some delay like above to make the LED light visible. Otherwise you might be clearing the LED immediately after setting it.
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Fri Jun 14 20:17:22 MST 2013
I've checked my UART_send and it seems that data is sent, i've tried printing Buffer to see the data to configure the UART_receive at LPC2.
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Fri Jun 14 19:12:34 MST 2013

Quote: vasanth
Why are you configuring LED as input pin? :mad:




whoops there was a typo, i've changed it but it still does not seem to work. Thanks for pointing it out :)
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vasanth on Fri Jun 14 07:51:29 MST 2013

Quote:

GPIO_SetDir(2, 1<<12, 0);//Configure Pin 2.12 as input pin


Why are you configuring LED as input pin? :mad:
0 Kudos
Reply

2,417 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by handthepig on Fri Jun 14 07:08:11 MST 2013
Someone please help?  :'(
0 Kudos
Reply