10 years, 3 months ago.

LPC812-MAX two UART

I have a problem when testing onboard UART LPC812-MAX, if set two different data rate with two active UART, both controllers is set to the last selected speed. This is most likely a bug in the mbed library? Thanks for any idea ...

example

#include "mbed.h"

Serial pc(USBTX, USBRX);     // serial tx, rx via on-board virtual COM USB port (SJ1, SJ4 = 1-2)

Serial rs(P0_4, P0_0);       // hw serial out tx=PIO0_4, in rx=PIO0_0             

int main()
 
 {  pc.baud(115200);         // USB data rate 115200 Baud

    rs.baud(2400);           // hw serial data rate 2400 Baud

    wait_ms(100);            // serial clock stable

    pc.puts("\r\nStart LPC812-MAX.\r\n");  // >>>> FAULT - BAUD RATE IS 2400! <<<<

    rs.puts("\r\nStart hw serial.\r\n");

    while(1) { }            
 } 

1 Answer

10 years, 3 months ago.

Hi Pavel,

I'm assuming you've already switched around the resistors to enable the USB virtual COM port function (if not, check out Getting Started or How to change the resistors).

That wouldn't solve the bigger problem, however. The major roadblock is LPC800's shared fractional rate divider for its two USART ports (e.g. only one base clock drives all the USARTS).

From the LPC800 datasheet:

Quote:

The Baud Rate Generator block divides the incoming clock to create a 16x baud rate clock in the standard asynchronous operating mode. The BRG clock input source is the shared Fractional Rate Generator that runs from the common USART peripheral clock U_PCLK). ... In asynchronous mode: Configure the baud rate divider BRGVAL in the USARTn BRG register. The baud rate divider divides the common USART peripheral clock by a factor of 16 multiplied by the baud rate value to provide the baud rate = U_PCLK/16 x BRGVAL.

Depending on how the mbed libraries handle setting up multiple baud rates, you might be able to fix this by changing the order in which you set the baud rates. If the base clock is not compatible for each of the baud rates, then it will not work.

Here's a more detailed version... /media/uploads/Fuzball/screenshot.png

If you absolutely need to use those baud rates, then you might have to bit-bash one of them...

Hope that helps :)

Accepted Answer

Thank you for the quick reply. It is a device for the 433MHz ISM band, the serial port is fixed at 2400. Channel with 115200 use it just for semihosting DEBUG purposes, and I can go down quietly (but minimal 9600). What other speed would you recommend for DEBUG, so I can keep 2400Bd?

posted by Pavel Šimík 22 Jan 2014

It was enough to carefully read your answer. Using two UART together: data rates must be in integer ratio; in my case, for 2400Bd set the second channel (DEBUG) to 38400Bd. Everything works, thanks again.

posted by Pavel Šimík 22 Jan 2014

Hi!

I have a similar problem with my LPC812-MAX. My required speed for rs(P0_4, P0_0) is 38400. If I set pc-speed to 115200 (which is exactly 3 times 38400), my communication to rs doesn't work reliable! Only pc-speed also 38400 works fine!

So which combinations work for the two UARTS with the mbed-Serial-library?

Charly

posted by Karl Zweimüller 22 Jan 2014

Sorry - correction: data rates ratio must be in numerical order multiples of two (2, 4, 8 ...)

posted by Pavel Šimík 22 Jan 2014

Glad it worked and good job with finding out the valid baud rates !

@Charly - I think the combinations Pavel listed are valid, but there is the possibility of error when using certain baud rates. In most cases you won't actually receive incorrect data since the chip usually samples each bit three times, but if you're receiving only a few incorrect bytes then it might be worth troubleshooting with the baud rate accuracy in mind...

This is a nice example from the LPC1768 user manual (p316):

Quote:

Example 2: PCLK = 12 MHz, BR = 115200 According to the provided algorithm DLest = PCLK/(16 x BR) = 12 MHz / (16 x 115200) = 6.51. This DLest is not an integer number and the next step is to estimate the FR parameter. Using an initial estimate of FRest = 1.5 a new DLest = 4 is calculated and FRest is recalculated as FRest = 1.628. Since FRest = 1.628 is within the specified range of 1.1 and 1.9, DIVADDVAL and MULVAL values can be obtained from the attached look-up table. The closest value for FRest = 1.628 in the look-up Table 286 is FR = 1.625. It is equivalent to DIVADDVAL = 5 and MULVAL = 8. Based on these findings, the suggested UART setup would be: DLM = 0, DLL = 4, DIVADDVAL = 5, and MULVAL = 8. According to Equation 4 the UART rate is 115384. This rate has a relative error of 0.16% from the originally specified 115200.

If you're experiencing unreliable serial data and have the option, it's best to try turning on some form of parity.

posted by Krissi Yan 23 Jan 2014