Using uart (LPC1114/301), data not displaying in terminal window - Page 1
Forum section: electronics / general

author: marvic
author_rank: Newbie
timestamp: August 07, 2014, 09:26:44 am
content: Hi,I am using LPC mx-1114/301 board. Small piece of code written to send and receive the data to and from Hyper terminal.Output, not showing typed data on terminal window. Any problem in source code? Can be appreciated to sort me out this. Here the code,#include"lpc11xx_syscon.h"#include"lpc11xx_gpio.h"#include "lpc11xx_uart.h"#include "LPC11xx.h"#define SystemCoreClock 12000000UL#define RDR 0x01#define THRE 0x20int main(void){unsigned char data;uint32_t baudrate = (uint32_t)115200 ;uint32_t DL;LPC_IOCON->PIO1_6 = 0x01;LPC_IOCON->PIO1_7 = 0x01;LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);LPC_SYSCON->UARTCLKDIV = 0x01; //UART clockDL = (SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV) / (16 * baudrate * LPC_SYSCON->UARTCLKDIV);LPC_UART->LCR = 0x83; //0x10000011;LPC_UART->DLM = 0x01; //DL / 256;LPC_UART->DLL = 0x86; // DL % 256;LPC_UART->LCR = 0x03; //0x00000011;LPC_UART->FCR = 0x07; //0x00000111;while(1){while (!(LPC_UART->LSR & RDR));data = LPC_UART->RBR;while (!(LPC_UART->LSR & THRE));LPC_UART->THR = data;}}Thanks,

author: nctnico
author_rank: Super Contributor
timestamp: August 07, 2014, 10:19:29 am
content: I wouldn't use 2 loops. Just receive in one loop and write the data to the transmit for loopback. You can't send faster than you receive!You need to change the I/O pin settings:LPC_IOCON->PIO1_7=(3<<6) | 1;LPC_IOCON->PIO1_6=(3<<6) | 1;It helps to output a character after initialising the UART. That way you can check the terminal and/or use an oscilloscope to check whether the baudrate is properly set.

author: marvic
author_rank: Newbie
timestamp: August 07, 2014, 02:13:17 pm
content: Hi nctnico,Thanks for replay, even after changing it's not working.I am using CooCox, any changes required?Even this code from CooCox, with API is not working.#include"lpc11xx_syscon.h"#include"lpc11xx_gpio.h"#include "lpc11xx_uart.h"#include "LPC11xx.h"void UartPrintExp();int main(void){UartPrintExp();while(1){}}void UartPrintExp(){UART_CFG_Type cfg;UART_FIFO_CFG_Type UARTFIFOConfigStruct;// Assign UART PinsUART_PinsInit();cfg.Baud_rate = 115200;cfg.Parity = UART_PARITY_NONE; //9;cfg.Databits = UART_DATABIT_8;cfg.Stopbits = UART_STOPBIT_1;UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);UART_Init(LPC_UART, &cfg);UART_FIFOConfig(LPC_UART, &UARTFIFOConfigStruct);// Enable TransmitUART_TxCmd(LPC_UART,ENABLE);UART_Send(LPC_UART, (uint8_t *)"Hello, World!", sizeof("Hello, World!") - 1, NONE_BLOCKING);}Thanks.

author: nctnico
author_rank: Super Contributor
timestamp: August 07, 2014, 02:55:50 pm
content: If this is the entire project then I'm missing the clock setup. Do you have an oscilloscope to check the transmit signal? Juding from the code the UART should work but without the clock setup the baudrate will be completely wrong.

author: marvic
author_rank: Newbie
timestamp: August 08, 2014, 05:10:00 am
content: I don't have oscilloscope. Can give me the exact clock setup.

author: Jeroen3
author_rank: Super Contributor
timestamp: August 08, 2014, 06:32:27 am
content: Use the debugger to read SystemCoreClock. If this makes sense, the startup.s called the clock configuration routine. If this makes no sense, you are running on internal clock defaults.

author: marvic
author_rank: Newbie
timestamp: August 08, 2014, 12:59:23 pm
content: LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);LPC_SYSCON->UARTCLKDIV = 0x01; //UART clockbreak point kept here, but startup_lpc11xx.c is not called during debug.Is this internal clock?How to solve this?

author: Jeroen3
author_rank: Super Contributor
timestamp: August 08, 2014, 09:33:29 pm
content: Those two lines enable clock distribution to the UART peripheral. They have nothing to do with the configuration of "system clock".Main clock is defined by MAINCLKSEL for source selection, and SYSAHBCLKDIV for division.Refer to the user manual chapter 3.5.Disable "run to main" so you start in the reset vector, then step through code with the debugger.

author: nctnico
author_rank: Super Contributor
timestamp: August 08, 2014, 09:52:18 pm
content: Another option is to see if you can get an example going which blinks a led. Then at least you know your code is running at all.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 08, 2014, 10:32:55 pm
content: Quote from: marvic on August 08, 2014, 05:10:00 amGet one. Even the cheapest, crappiest scope is orders of magnitude better than none, and will pay for itself in saved time very quickly.

author: marvic
author_rank: Newbie
timestamp: August 09, 2014, 05:42:56 am
content: thanks for replay,nctnico, Led And buzzer working fine. But not UART..Can any one give me working example.

author: marvic
author_rank: Newbie
timestamp: August 09, 2014, 06:03:06 am
content: Jeroen3, thanks for replay,DL = (SystemCoreClock * LPC_SYSCON->SYSAHBCLKDIV) / (16 * baudrate * LPC_SYSCON->UARTCLKDIV);Is this correct?

author: nctnico
author_rank: Super Contributor
timestamp: August 09, 2014, 08:24:07 am
content: You have to figurure out whether or not the clock is initialised correctly. I don't know what CooCox does by default but I think you need to call a function which sets the clock frequency. There is a global variable called SystemCoreClock which contains the CPU frequency. This is set by a function which sets the PLLs. Since the maximum frequency varies between controllers (some are limited to 32MHz while others can run at 100MHz or more) I'd guess you have to set the desired clock frequence yourself. But it may be that CooCox does this somewhere under the hood.By default an LPC1114 runs at 12MHz. I'd suggest to try a much lower baudrate; 9200 for example. At 12MHz 115200 baud has a huge error without the additional fractional baudrate adjustment.

author: Rick60
author_rank: Contributor
timestamp: August 09, 2014, 11:34:12 am
content: Quote from: marvic on August 08, 2014, 12:59:23 pmI am using a Mbed lpc11u24 card same family of chips looking at user manual and Keil Ide ,they have a call from the there startup_LPC11Uxx.s to a function SystemInit() in there system_LPC11Uxx.c file , which sets up the pll etc you need to see if coocox has call like this or you may need to add it ( the lack of breakpoint makes me feel it missing )but there is also another call which is done after main in keilint main (void) {SystemCoreClockUpdate(); -<-- maybe you need to call coocox version.............Keil also has an uart library which does all the fine adjust for baudrate , you may want to try downloading keil ( its free for limited eval ) and includes a uart setup example project you could borrow the uartinit code from be warned they use the interrupt by default , took me hours to workout that all my data was being sent into a buffer , so polling never workedhope this helps

author: Jeroen3
author_rank: Super Contributor
timestamp: August 09, 2014, 05:59:33 pm
content: The function "SystemCoreClockUpdate();" derives the Cortex M0 frequency from the registers and a already defined value for xtal. It is stored in SystemCoreClock, in hz.Even then, UART_PCLK (for the baudrate) is derived from the output of MAINCLKSEL, not SYSAHBCLKDIV. The AHB clock is only for access to the registers.Somewhere in the startup assembler "SystemInit" or something similiar is called. This is where you need to be.Could also be in a routine called _main or _entry.Find the application entry point, you're using gcc (with CoIDE) so I cannot help you with that.http://www.nxp.com/documents/user_manual/UM10398.pdf

author: marvic
author_rank: Newbie
timestamp: August 11, 2014, 06:08:40 am
content: Ricks thanks for replay,#define SystemCoreClock 12000000 manually i defined,Also, I tried with Keil but not working, But Led and buzzer working fine with Coocox and keil.Jeroen thanks,I tried with all these options, still not working. I am following same user manual.Can any one give me work example.

author: Jeroen3
author_rank: Super Contributor
timestamp: August 11, 2014, 06:51:47 am
content: Manually defining 12 MHz does not configure the chip to run 12 MHz.Find examples here:http://www.lpcware.com/node/11538/58