LPC938 Baudrate generator

Started by SR April 7, 2009
Hi

I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.

EA = 0;
TR1 = 0; /* stop timer 1 */
ET1 = 0; /* disable timer 1 interrupt */

TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));

PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */

TMOD &= ~0xF0; /* clear timer 1 mode bits */
TMOD |= 0x20; /* put timer 1 into MODE 2 */
SCON = 0x50;

TR1 = 1; /* start timer 1 */
INT_ENABLE;
EA = 1;

Samuel

Hi Samuel;

What is your system clock? If the internal oscillator cannot make ikt, try xtal or external clock.

Feng
--- In l..., "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>

Hi,

if you are using the internal RC oscillator, try this:

void init()
{
BRGCON = 0x00;
BRGR0 = 0xF0;
BRGR1 = 0x02;
BRGCON = 0x03;
PCON &=0xC0;
SCON = 0x50;
SSTAT = 0x40;
P1M1 = 0x00;
P1M2 = 0x01;
P1M2 = 0x001;
TI = 1;
RI = 0;

}

Best Regards
Bernhard

--- In l..., "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>

clock is internal clock of 7.363MHz. I tired this code. Didn't work either.

________________________________
From: lpc9xxbeginner
To: l...
Sent: Tuesday, April 7, 2009 11:23:52 PM
Subject: [lpc900_users] Re: LPC938 Baudrate generator

Hi,

if you are using the internal RC oscillator, try this:

void init()
{
BRGCON = 0x00;
BRGR0 = 0xF0;
BRGR1 = 0x02;
BRGCON = 0x03;
PCON &=0xC0;
SCON = 0x50;
SSTAT = 0x40;
P1M1 = 0x00;
P1M2 = 0x01;
P1M2 = 0x001;
TI = 1;
RI = 0;

}

Best Regards
Bernhard

--- In l..., "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>



Yahoo! Groups Links
ya, I am trying not to use an xtal clock cos alot of the code is written and when I do the maths TH1 should be 0xFD to be transmitting at 9600 but its not. Maybe there is some register I miss'd out or value in something else I got wrong? Internal clock is 7.363MHz

Samuel

________________________________
From: finn_li
To: l...
Sent: Tuesday, April 7, 2009 11:09:48 PM
Subject: [lpc900_users] Re: LPC938 Baudrate generator

Hi Samuel;

What is your system clock? If the internal oscillator cannot make ikt, try xtal or external clock.

Feng
--- In l..., "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>



Yahoo! Groups Links
Dear Sameul,

Why dont you try the codes with code architect for NXP uC?

Sincerely,

Dhans
Mob:+91-98867-30835

________________________________
From: Samuel
To: l...
Sent: Tuesday, 7 April, 2009 10:24:39 PM
Subject: Re: [lpc900_users] Re: LPC938 Baudrate generator
ya, I am trying not to use an xtal clock cos alot of the code is written and when I do the maths TH1 should be 0xFD to be transmitting at 9600 but its not. Maybe there is some register I miss'd out or value in something else I got wrong? Internal clock is 7.363MHz

Samuel

________________________________
From: finn_li
To: lpc900_users@ yahoogroups. com
Sent: Tuesday, April 7, 2009 11:09:48 PM
Subject: [lpc900_users] Re: LPC938 Baudrate generator

Hi Samuel;

What is your system clock? If the internal oscillator cannot make ikt, try xtal or external clock.

Feng
--- In lpc900_users@ yahoogroups. com, "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>

------------ --------- --------- ------

Yahoo! Groups Links

Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/
This is very old problem
This was the problem which has made my visit to China :).

Use 0.1uF between VCC and GND. (near to VCC pin of LPC938)

Also check your baurdrate in simulator..

Regards
Doshi Harshal
POTENT
F-27, VRAJWADI COMPLEX,
Nr. UTKARSH SCHOOL,
Gadapura,
VADODARA
GUJARAT 390015, INDIA
PH: 09429071421
www.potent.co.in
On Tue, Apr 7, 2009 at 10:24 PM, Samuel wrote:

> ya, I am trying not to use an xtal clock cos alot of the code is
> written and when I do the maths TH1 should be 0xFD to be transmitting at
> 9600 but its not. Maybe there is some register I miss'd out or value in
> something else I got wrong? Internal clock is 7.363MHz
>
> Samuel
>
> ------------------------------
> *From:* finn_li
> *To:* l...
> *Sent:* Tuesday, April 7, 2009 11:09:48 PM
> *Subject:* [lpc900_users] Re: LPC938 Baudrate generator
>
> Hi Samuel;
>
> What is your system clock? If the internal oscillator cannot make ikt, try
> xtal or external clock.
>
> Feng
> --- In l..., "SR" wrote:
> >
> > Hi
> >
> > I am using LPC938, I am trying to get the UART's baudrate to 9600 but
> nothing seems to work..I the following code and all I see on hyperterm is
> just various ASCII characters.
> >
> > EA = 0;
> > TR1 = 0; /* stop timer 1 */
> > ET1 = 0; /* disable timer 1 interrupt */
> >
> > TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L *
> baudrate)));
> >
> > PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
> >
> > TMOD &= ~0xF0; /* clear timer 1 mode bits */
> > TMOD |= 0x20; /* put timer 1 into MODE 2 */
> > SCON = 0x50;
> >
> > TR1 = 1; /* start timer 1 */
> >
> >
> > INT_ENABLE;
> >
> >
> > EA = 1;
> >
> > Samuel
> >
>
>
> Yahoo! Groups Links
>
>

--
Hi Samuel

You may have got it going by now but here is some info.
I used an LPC925 which I believe is similar as far as the UART is concerned. I set the txd pin to be quasi-bi (push/pull would probably work as well) I think you may have an error in your th1 reload value. I calculate 232 or E8h for SMOD1=1 and 244 or F4h for SDOD1=0. I used the 925 user's manual for this, its got lots of info.

Here's an initialisation I've used (in assembler) successfully up to 230.4k baud.

anl p1m1,#11111110b ; p1.0 (TXD) quasi bi
mov scon,#50h ; set up serial port in mode 1
orl pcon,#80h ; set smod for max baud rate
mov tmod,#20h ; timer 1 mode 2 (8 bit auto reload)
mov th1,#232 ; reload value for 9600 with 7.373 MHz clk
setb tr1 ; start timer 1 running

I hope this is of some help.

Regards Jon

--- In l..., "SR" wrote:
>
> Hi
>
> I am using LPC938, I am trying to get the UART's baudrate to 9600 but nothing seems to work..I the following code and all I see on hyperterm is just various ASCII characters.
>
> EA = 0;
> TR1 = 0; /* stop timer 1 */
> ET1 = 0; /* disable timer 1 interrupt */
>
> TH1 = 0xFC; //(unsigned char) (256 - (clock / (16L * 12L * baudrate)));
>
> PCON |= 0x80; /* 0x80=SMOD: set serial baudrate doubler */
>
> TMOD &= ~0xF0; /* clear timer 1 mode bits */
> TMOD |= 0x20; /* put timer 1 into MODE 2 */
> SCON = 0x50;
>
> TR1 = 1; /* start timer 1 */
> INT_ENABLE;
> EA = 1;
>
> Samuel
>