lpcopen with lpc1114 and UART

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

lpcopen with lpc1114 and UART

2,091 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 13:54:21 MST 2014
I am using the nxp_lpcxpresso_11c24_periph_uart example code as a reference.

I basically created a blank lpcopen project in lpcxpresso, using the lpc_chip_11cxx_lib, and no board lib.

I then copied the source from the uart example, and changed the 2 lines for the Init_UART_PinMux.

Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_6, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* RXD */
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_7, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* TXD */


Below is the entire code.

Everything complies fine, and I can run the example... but the problem is that the output I read in coolterm is scrambled. I have checked my terminal's settings, and verified many times its configured the same as the example code (baud rate 115200, stop bits 1, data bits 8, and no parity). The output I am seeing looks as if there is an issue with the baud rate (its similar to what you would see if you selected the wrong baud rate in your terminal).

I am using a lpc1114fn28, with no external crystal.. its just a lpc1114fn28 on a breadboard with a debugger and a uart connected.

Any ideas would be greatly appreciated.




/*
 * @brief UART interrupt example with ring buffers
 *
 * @note
 * Copyright(C) NXP Semiconductors, 2012
 * All rights reserved.
 *
 * @par
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * LPC products.  This software is supplied "AS IS" without any warranties of
 * any kind, and NXP Semiconductors and its licensor disclaim any and
 * all warranties, express or implied, including all implied warranties of
 * merchantability, fitness for a particular purpose and non-infringement of
 * intellectual property rights.  NXP Semiconductors assumes no responsibility
 * or liability for the use of the software, conveys no license or rights under any
 * patent, copyright, mask work right, or any other intellectual property rights in
 * or to any products. NXP Semiconductors reserves the right to make changes
 * in the software without notification. NXP Semiconductors also makes no
 * representation or warranty that such application will be suitable for the
 * specified use without further testing or modification.
 *
 * @par
 * Permission to use, copy, modify, and distribute this software and its
 * documentation is hereby granted, under NXP Semiconductors' and its
 * licensor's relevant copyrights in the software, without fee, provided that it
 * is used in conjunction with NXP Semiconductors microcontrollers.  This
 * copyright, permission, and disclaimer notice must appear in all copies of
 * this code.
 */

#include "chip.h"
//#include "board.h"
#include "string.h"

/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/

/* 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[] = "LPC11xx UART example using ring buffers\r\n";
const char inst2[] = "Press a key to echo it back or ESC to quit\r\n";

/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/

/*****************************************************************************
 * Private functions
 ****************************************************************************/

static void Init_UART_PinMux(void)
{
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_6, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* RXD */
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIO1_7, (IOCON_FUNC1 | IOCON_MODE_INACT)); /* TXD */
}

/*****************************************************************************
 * Public functions
 ****************************************************************************/

/**
 * @briefUART interrupt handler using ring buffers
 * @returnNothing
 */
void UART_IRQHandler(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(LPC_USART, &rxring, &txring);
}

const uint32_t OscRateIn = 0;
const uint32_t ExtRateIn = 0;

/**
 * @briefMain UART program body
 * @returnAlways returns 1
 */
int main(void)
{
uint8_t key;
int bytes;

SystemCoreClockUpdate();
Init_UART_PinMux();

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

/* 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);

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

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

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

/* Poll the receive ring buffer for the ESC (ASCII 27) key */
key = 0;
while (key != 27) {
bytes = Chip_UART_ReadRB(LPC_USART, &rxring, &key, 1);
if (bytes > 0) {
/* Wrap value back around */
if (Chip_UART_SendRB(LPC_USART, &txring, (const uint8_t *) &key, 1) != 1) {
}
}
}

/* DeInitialize UART0 peripheral */
NVIC_DisableIRQ(UART0_IRQn);
Chip_UART_DeInit(LPC_USART);

return 1;
}
Labels (1)
0 Kudos
12 Replies

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hgc_8421 on Sat Aug 01 10:54:12 MST 2015
Dear,
if you are not using crystal then you must configure your clock in the file sysint_11xx.c in the function Chip_SystemInit().
main clock source must IRC.
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 11 15:46:01 MST 2014
Looks like a RS232 to USB converter  :O

That's not working. You need a (3.3V) TTL  to USB converter  :)

Something like:

http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 15:27:45 MST 2014
I have the RX, TX, and Ground hooked up to a USA-19HS - Keyspan High-Speed USB to Serial Adapter http://www.tripplite.com/products/series/sid/849

I'm going to do some research and see if this will work with 3.3v, thanks for the suggestion.

[img]https://lh4.googleusercontent.com/-Uo4kR8BEoFg/U0hqjRQSE9I/AAAAAAAACqk/M5sJOV9Bp0Q/w1406-h109-no/Scr...
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 11 15:21:33 MST 2014
Sorry, this picture is to small to recognize something...

Anyway, if your baudrate is correct, it's time to check your hardware:

Which UART converter are you using? Is it a 3.3V version?
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 15:09:48 MST 2014
so it looks like everything is working correctly. I must have some kind of wiring issue.. thanks for all the help!

0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 11 14:53:01 MST 2014
There are cheap DSO versions with Serial Decoding:

Something like:

http://www.picotech.com/picoscope6-serial-decoding.html

Very useful tools...

Or LabTool:

http://www.embeddedartists.com/products/app/labtool.php

Anyway, another option is to add a crystal. IIRC this sample is working (at least with LPC11C24)...
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 14:45:31 MST 2014
didn't know I could do that, but google says its pretty easy  :)

I don't have a scope, but I assume a logic analyzer will do just fine (Saleae Logic USB Logic Analyzer)  ??.
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 11 14:38:46 MST 2014

Quote: kingsob
I also tried 9600 with no luck.  :(



Did you measure the real baudrate?
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 14:32:11 MST 2014
I also tried 9600 with no luck.  :(
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 11 14:30:38 MST 2014

Quote: kingsob
...with no external crystal...

Any ideas would be greatly appreciated.



Try a slower baudrate (38400). IRC isn't very accurate...
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingsob on Fri Apr 11 14:30:20 MST 2014
I'm not sure which example you are referring to... this is the example I was testing with, I just slightly modified it.

http://www.lpcware.com/system/files/lpcopen_v2_00a_lpcxpresso_nxp_lpcxpresso_11c24.zip
0 Kudos

1,585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by embd02161991 on Fri Apr 11 14:17:09 MST 2014
Hi,

Can you try the UART example from LPCOpen and check if it works with your board ?

Thanks,

NXP Technical Support
0 Kudos