uart RBR register

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

uart RBR register

3,083 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CroesJeroen on Thu Aug 09 11:42:59 MST 2012
Hello guys,

this is my first post on the forum!

I'm facing an issue with the uart peripheral. I want to send data from my C# program to the LPC1227. I can measure the chars on the RXD pin of the µC and it is correct (also the baudrate, also for sending from µC).

When I debug and have a look at the char that has been received, I never get the correct value. When I send a 1, RBR is 0x11, a 2-> RBR=0x12, a 8 -> RBR=0x18.

When I look at the value on RXD pin, when I would send a 1, it's 0x31. This is valid for ascii ( 0x32 for a 2, and so on).

Someone has an idea why I don't get the correct value in the RBR register. Once again the baudrate is set correctly in putty/teraterm and in the LPC (measured it by sending a char from the LPC to the PC).

This is the code I'm using :

void SetUART(void){
//PCLK=12MHz, BR = 115200bps
LPC_SYSCON->SYSAHBCLKCTRL|=UART0_Clock;
LPC_SYSCON->SYSAHBCLKCTRL|=GPIO2_Clock;
LPC_SYSCON->UART0CLKDIV|=1; // Divide by 1 when not initialised = 0, disabled

LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
LPC_UART0->LCR|=DLAB; // enable divisor latch to access the divisors
LPC_UART0->FDR=0x85; //Fractional Divider Register
LPC_UART0->DLM=0; // Divisor Latch MSB
LPC_UART0->DLL=4; //Divisor Latch LSB

LPC_IOCON->PIO2_1|=0x4;// RXD0
LPC_IOCON->PIO2_2|=0x4;// TXD0

LPC_UART0->LCR&= ~DLAB; // Disable divisors to enable interrupts
LPC_UART0->IER = IER_RBR ;/*Receive Data Available interrupt */

NVIC_EnableIRQ(UART0_IRQn);


}

void UART0_IRQHandler(void)
{
GPIOSetValue( PORT0, 4, 1 ); // set high
uint32_t dummy = LPC_UART0->RBR; // clear interrupt flag
}


So I read Dummy when debugging and it doesn't display the right value.

I would be thrilled if someone could help me out on this one!

Kind regards
0 Kudos
Reply
8 Replies

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Mon Aug 13 05:01:48 MST 2012
Ah yes, operator precedence in a macro, that's an old gotcha. In this case ~ has precedence over << so your code was effectively

LPC_UART0->LCR&= (~1) << 7

The moral of the story is to always force precedence by placing ()s appropriately even if you think they aren't needed. And always around compound statements in a macro.
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CroesJeroen on Mon Aug 13 04:43:50 MST 2012
Hi guys,

got it, it should be :
#define DLAB(1<<7) // divisor latch enable

and not :

#define DLAB1<<7 // divisor latch enable

LPC_UART0->LCR&= ~DLAB; // Disable divisors to enable interrupts

would reset all bits. 5 bit was enabled

thanks for the support
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CroesJeroen on Sat Aug 11 12:02:49 MST 2012

Quote: gbm
I would rather suspect wrong divisor value. The effect you observe looks like receiver clock being slower than transmitter.



Hi,

thats strange because I set teraterm to 115200 bps and there is a example in the datasheet for 12MHz en 115200 bps ( my specs), I used the same values. Also is the time of a bit correctly.

kind regards
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Sat Aug 11 11:17:36 MST 2012
I would rather suspect wrong divisor value. The effect you observe looks like receiver clock being slower than transmitter.
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CroesJeroen on Sat Aug 11 05:31:47 MST 2012
Hi ToBeFrank,

thanks for the respons.

I oversaw that remark! But you really thinks thats why the data in RBR is faulty?

Kind regards
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ToBeFrank on Fri Aug 10 21:21:45 MST 2012
This is what the user manual says (the emphasis is actually in the manual):


Quote:
Remark: The UART0 pins must be configured in the corresponding IOCON registers before the UART0 clocks are enabled.

0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CroesJeroen on Fri Aug 10 17:04:33 MST 2012
Hello graynomad,

to make it even more clear, I used teraterm. I typed in a 5, saw 0x35 on the oscilloscope and get 0x15 in RBR.

Type a 2, osci=0x32,RBR=0x12.
Type a 9, osci=0x39,RBR=0x19.

Thats indeed what you are asking, and I confirm.

Indeed it's like ORing with 0x10.

If I type in some chars like a,b,c, or d, the RBR register doesnt make sense, getting values like 0x01, 0x05 and stuff like that. Just values that do not correspondent with the normal ascii values I should get.

I'll try to attach it once again to the scope monday and have a look once again.

Kind regards
0 Kudos
Reply

2,704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Fri Aug 10 15:59:25 MST 2012
Are you saying that you have 3 different values?

Send 0x01
measure 0x31 at the pin (what with?)
read 0x11 from RDR

The 0x31 sounds like your C# program is not sending binary, I'd look at that code. But the 0x11 doesn't make sense. Even if your baud rate was off I doubt you'd get a consistent ORing of 0x10 like that.
0 Kudos
Reply