LPC1769 Unable to make UART2 work [SOLVED]

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

LPC1769 Unable to make UART2 work [SOLVED]

2,477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kakikou on Wed Jul 22 01:38:03 MST 2015
Hi there,

Since yesterday i'm struggling to make UART2 work on myn 1769.
I tried using the example code in the lpcopen example list.
I didn't forget to set the pins 2.8 and 2.9 in peripherial mode (IOCON_FUNC2 if i'm not mistaken), and even in gpio mode i can't change the pin state (checked with a scope).

But i'm sure that this UART works since i have a binary that ccommunicates via this one, so it's not a physical issue.

I really don't know what to check , or what i did forgot to initialize to make it work.

Thx for your anwsers

Here is the code i used , mainly inspired by the example code
/*
===============================================================================
 Name        : testuart.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===============================================================================
*/

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

#include <cr_section_macros.h>
#define UART_SELECTION LPC_UART2
#define IRQ_SELECTION UART2_IRQn
#define HANDLER_NAME UART2_IRQHandler



/* Transmit and receive ring buffers */
STATIC RINGBUFF_T txring, rxring;

/* Transmit and receive ring buffer sizes */
#define UART_SRB_SIZE 128/* Send */
#define UART_RRB_SIZE 32/* Receive */

/* Transmit and receive buffers */
static uint8_t rxbuff[UART_RRB_SIZE], txbuff[UART_SRB_SIZE];

const char inst1[] = "LPC17xx/40xx UART example using ring buffers\r\n";
const char inst2[] = "Press a key to echo it back or ESC to quit\r\n";

// TODO: insert other include files here

// TODO: insert other definitions and declarations here


/**
 * @briefUART 0 interrupt handler using ring buffers
 * @returnNothing
 */
void HANDLER_NAME(void)
{
/* Want to handle any errors? Do it here. */

/* Use default ring buffer handler. Override this with your own
   code if you need more capability. */
Chip_UART_IRQRBHandler(UART_SELECTION, &rxring, &txring);
}

int main(void) {

uint8_t key;
int bytes;

SystemCoreClockUpdate();
Board_Init();
Board_UART_Init(UART_SELECTION);
Board_LED_Set(0, false);

/* Setup UART for 115.2K8N1 */
Chip_UART_Init(UART_SELECTION);
Chip_UART_SetBaud(UART_SELECTION, 115200);
Chip_UART_ConfigData(UART_SELECTION, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT));
Chip_UART_SetupFIFOS(UART_SELECTION, (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2));
Chip_UART_TXEnable(UART_SELECTION);

/* Before using the ring buffers, initialize them using the ring
   buffer init function */
RingBuffer_Init(&rxring, rxbuff, 1, UART_RRB_SIZE);
RingBuffer_Init(&txring, txbuff, 1, UART_SRB_SIZE);

/* Reset and enable FIFOs, FIFO trigger level 3 (14 chars) */
Chip_UART_SetupFIFOS(UART_SELECTION, (UART_FCR_FIFO_EN | UART_FCR_RX_RS |
UART_FCR_TX_RS | UART_FCR_TRG_LEV3));

/* Enable receive data and line status interrupt */
Chip_UART_IntEnable(UART_SELECTION, (UART_IER_RBRINT | UART_IER_RLSINT));

/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(IRQ_SELECTION, 1);
NVIC_EnableIRQ(IRQ_SELECTION);

/* Send initial messages */
Chip_UART_SendRB(UART_SELECTION, &txring, inst1, sizeof(inst1) - 1);
Chip_UART_SendRB(UART_SELECTION, &txring, inst2, sizeof(inst2) - 1);

/* Poll the receive ring buffer for the ESC (ASCII 27) key */
key = 0;
while (key != 27) {
Chip_UART_SendRB(UART_SELECTION, &txring, "UUUUUUUUUUUUUUUUUUUUUUUUUUUU", 28);

}

/* DeInitialize UART0 peripheral */
NVIC_DisableIRQ(IRQ_SELECTION);
Chip_UART_DeInit(UART_SELECTION);

return 1;
}
Labels (1)
0 Kudos
Reply
4 Replies

2,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kakikou on Wed Jul 22 05:39:49 MST 2015
Oh they weren't set up but anyway problem solved.
My stupidity, i didn'nt notice that p0.10 and P0.11 were on rx2 and tx2  and since the schematics (custom board) are shitty, there was'nt a way to be sure of where the connection was done.

I tried to only use P010 and P011 instead of P2.x  and it works.

SO THANKS A LOT !!!  ;-)
0 Kudos
Reply

2,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jul 22 05:35:06 MST 2015

Quote: kakikou
i'm pretty sure thaht the PCONP is done by the Chip_Clock_EnablePeriphClock().



And debugger is confiming that  :quest:



Quote: kakikou
By saying desactivate them, you mean put them in IOCON_FUNC0 ?



Just check their setup in board_sysinit.c  :O
0 Kudos
Reply

2,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kakikou on Wed Jul 22 05:23:21 MST 2015
i'm pretty sure thaht the PCONP is done by the Chip_Clock_EnablePeriphClock().

I didn't knew aboit the P0 10 and p 0 11.
By saying desactivate them, you mean put them in IOCON_FUNC0 ?
0 Kudos
Reply

2,038 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jul 22 02:53:49 MST 2015
PCUART2 bit in PCONP?

Did you disable default board setup to P0[10]/P0[11]  :quest:

{0,  10,  IOCON_MODE_INACT | IOCON_FUNC1},/* TXD2 */
{0,  11,  IOCON_MODE_INACT | IOCON_FUNC1},/* RXD2 */

0 Kudos
Reply