EmbeddedRelated.com
Forums

Drive UART with CMSIS Library

Started by Mohammad August 30, 2012
Hi
I can drive the UART simply by my code but I want to use CMSIS and work with them. I don't know where to start and learn to write a code with the library?
Actually as I told you I'm trying to drive my UART port but I can't.
Firstly I initialized my UART port and define it and then I change the pins function and send a char. but nothing happen.
here is the code:

UART_CFG_Type UART0CFG;
UART0CFG.Baud_rate00;
UART0CFG.Parity=UART_PARITY_NONE;
UART0CFG.Databits=UART_DATABIT_8;
UART0CFG.Stopbits=UART_STOPBIT_1;

UART_Init (LPC_UART0,&UART0CFG);

PINSEL_CFG_Type UART0Pin;
UART0Pin.Funcnum = 1;
UART0Pin.OpenDrain = 0;
UART0Pin.Pinmode = 0;
UART0Pin.Portnum = 0;
UART0Pin.Pinnum = 2;
PINSEL_ConfigPin(&UART0Pin);
UART0Pin.Pinnum = 3;
PINSEL_ConfigPin(&UART0Pin);

uint8_t menu2 = 'H';
UART_SendByte(LPC_UART0, menu2);

compiler doesn't show any Error or warning and I don't receive any character in my PC ??(BTW I'm working with LPC1768)

Best Regards.

An Engineer's Guide to the LPC2100 Series

I found that a fairly recent version of LPC's library had a bug in the
uart code that set the baud incorrectly by a factor of 16.

the LPC library in nxpUSBLib repository is correct in this regard.

I debugged this by putting the uart into auto-baud mode then reading
the relevant registers

On Fri, Aug 31, 2012 at 12:27 AM, Mohammad wrote:
> Hi
> I can drive the UART simply by my code but I want to use CMSIS and work with them. I don't know where to start and learn to write a code with the library?
> Actually as I told you I'm trying to drive my UART port but I can't.
> Firstly I initialized my UART port and define it and then I change the pins function and send a char. but nothing happen.
> here is the code:
>
> UART_CFG_Type UART0CFG;
> UART0CFG.Baud_rate00;
> UART0CFG.Parity=UART_PARITY_NONE;
> UART0CFG.Databits=UART_DATABIT_8;
> UART0CFG.Stopbits=UART_STOPBIT_1;
>
> UART_Init (LPC_UART0,&UART0CFG);
>
> PINSEL_CFG_Type UART0Pin;
> UART0Pin.Funcnum = 1;
> UART0Pin.OpenDrain = 0;
> UART0Pin.Pinmode = 0;
> UART0Pin.Portnum = 0;
> UART0Pin.Pinnum = 2;
> PINSEL_ConfigPin(&UART0Pin);
> UART0Pin.Pinnum = 3;
> PINSEL_ConfigPin(&UART0Pin);
>
> uint8_t menu2 = 'H';
> UART_SendByte(LPC_UART0, menu2);
>
> compiler doesn't show any Error or warning and I don't receive any character in my PC ??(BTW I'm working with LPC1768)
>
> Best Regards.
Thanks Triffid for your reply.
Does it mean I did right for sending a character however the problem was because of library?
By nxpUSBlib repository do you mean nxpUSBlib v0.95 from LPCware site(my IDE is IAR)?
and is any terminal software for windows, we able to set as auto baud-rate and find the baud-rate?
I'm sorry if my questions are naive, I just started to learn about ARM.
Thanks.

--- In l..., Triffid Hunter wrote:

> the LPC library in nxpUSBLib repository is correct in this regard.
>
> I debugged this by putting the uart into auto-baud mode then reading
> the relevant registers

On Sat, Sep 1, 2012 at 11:46 PM, Mohammad wrote:
> Thanks Triffid for your reply.
> Does it mean I did right for sending a character however the problem was because of library?

possibly. I just know that the library I used first had a bug, and
that later versions have the bug fixed.

> By nxpUSBlib repository do you mean nxpUSBlib v0.95 from LPCware site(my IDE is IAR)?

yes

> and is any terminal software for windows, we able to set as auto baud-rate and find the baud-rate?

sorry, don't know much about windows.

The LPC itself supports auto baud, read the user manual! You can set
it to auto baud, send it some magic characters ("?" from memory) then
read out the various uart registers to find what multipliers and
dividers it's picked.

If you want to find the baud it's using when you set a baudrate, get
out your 'scope and find the bit-time when you send characters.