Skip to main content
pbt1668
Associate II
May 26, 2006 3:18 PM UTC
Question

On topic UART # 2 on uPSD 3254

Posted on May 26, 2006 at 17:18

On topic UART # 2 on uPSD 3254

This topic has been closed for replies.

5 replies

pbt1668
pbt1668Author
Associate II
May 17, 2011 9:50 AM UTC
Posted on May 17, 2011 at 11:50

Hi All,

I been banging away at this all day, help me out here while I still have some hair left.

I have read that you would like the code posted so some comment can be made on it.

OK, just remember that you asked.

The routine sticks at C2_LP, it never sees the TI in SCON2 for the second UART

IICSDA is a diag pin (P3.1) that I use to track stuck routines.

The transmit routine uses “RSDAT�? as a charter buffer in the ram to load the sbuf2.

**********************************************************

C2_OUT: mov A,IEA

clr Acc.4 ;Clear the second UART Interrupt enable

mov IEA,A

mov SBUF2,RSDAT

C2_LP: mov A,SCON2

cpl IICSDA

jnb Acc.1,C2_LP

clr Acc.1

mov SCON2,A

mov A,IEA

setb Acc.4 ;Enable the Interrupt enable

mov IEA,A

ret

And the setup routine for all the timers, and “stuff�?

Just remember you asked !

;******************************************************************

;* Timers 0 thru 2 set up

;* Timer 0 ....... tclk

;* Timer 1 ....... RS232 Port 0

;* Timer 2 ....... UART1

;******************************************************************

S_INT: clr TR1

mov TMOD,00100001B ;Timer 1 is set to 8 bit auto reload mode

;Timer 0 used as 16 bit Tic clock

;Reload the tic value on interrupt

mov th1,BaudLoad ; Set reload value

setb tr1 ; start timer for UART 0.

;******************************************************************

;* TCON *

;* bit0 IT0 External Interrupt 0 type H/L state *

;* bit1 IE0 External Interrupt 0 flag *

;* bit2 IT1 External Interrupt 0 type H/L state *

;* bit3 IE1 External Interrupt 0 flag *

;* bit4 TR0 Timer 0 run flag *

;* bit5 TF0 Timer 0 overflow flag *

;* bit6 TR1 Timer 1 run flag *

;* bit7 TF1 Timer 1 overflow flag *

;******************************************************************

mov TCON,01010000B ;Start both timers

;******************************************************************

;* Timer 0 setup and run *

;******************************************************************

mov tl0,ticl ; Set reload value

mov th0,tich ; Set reload value

setb tr0 ; start timer 0.

setb et0 ; set the interrupt enable

;******************************************************************

;* Second UART setup and run *

;******************************************************************

;* PCON *

;* bit0 IDL Active Idle Mode high enable *

;* bit1 PD Power Down high enabled *

;* bit2 TCLK1 Transmit clock flag UART2 *

;* bit3 RCLK1 Receive clock flag UART2 *

;* bit4 ADSFINT Enable ADC Interrupt *

;* bit5 LVREN LVR Disable bit active high *

;* bit6 SMOD1 Double baud rate UART2 *

;* bit7 SMOD Double baud rate UART1 *

;******************************************************************

;* SCON / SCON2 *

;* bit0 RI Receive Interrupt Flag *

;* bit1 TI Transmit Interrupt Flag *

;* bit2 RB8 8th bit received *

;* bit3 TB8 8th bit transmitted *

;* bit4 REN Enable Serial reception, *

;* bit5 SM2 Multi uP addressing enabled *

;* bit6 SM1 UART type used with SM0 *

;* bit7 SM0 UART type used with SM1 *

;******************************************************************

;* SM1 & SM0 S/B ''10'', in binary *

;* SM2 low to disable the multi processor function *

;* REN set to enable port *

;* ignore the 8th bit flags *

;* TI / RI are reset by the IRQ handler *

;******************************************************************

;* Second Interrupt Enable IEA *

;* IEA *

;* bit0 EUSB Enable USB Bus *

;* bit1 EI2C Enable IIC Bus *

;* bit2 NU Not Used *

;* bit3 NU Not Used *

;* bit4 ES2 Enable 2nd Serial reception *

;* bit5 NU Not Used *

;* bit6 NU Not Used *

;* bit7 EDDC Enable DDC Interrupt *

;******************************************************************

MOV SCON, 050h ; Timer 1 : Mode 1 (vari baud) ; and set receive enable

MOV SCON2, 050h ; Timer 2 : Mode 1 (vari baud) ; and set receive enable

SETB TR1 ; Start timer 1

;mov SCON,01010000B ;TI set indicates transmitter ready.

;mov SCON2,01010000B ;TI set indicates transmitter ready.

;mov A,PCON

;setb Acc.2

;setb Acc.3

;mov PCON,A ;Set the uart to run from timer 2

mov PCON,00001100B ;Set the uart to run from timer 2

;mov PCON,00000000B ;Set the uart to run from timer 2

mov TL2,SECUART ; Set reload value

mov TH2,SECUART ; Set reload value

mov RCAP2L,SECUART

mov RCAP2H,SECUART ;Load the 16 bit counter with reload value

mov IEA,00010000B ;Set the 2nd uart interrupt enable

;mov T2CON,00000100b

;mov T2CON,00110100b

mov T2CON,030h

ret

wek2
Associate II
May 17, 2011 9:50 AM UTC
Posted on May 17, 2011 at 11:50

It's a pity you don't remember where did you read about it...

By the way, I am using Timer2 for UART1 and Timer1 for UART0 and both are working... Maybe there is a difference in the chips? Mine is uPSD3212C

Jan Waclawek

pbt1668
pbt1668Author
Associate II
May 17, 2011 9:50 AM UTC
Posted on May 17, 2011 at 11:50

It winds up to be that you can’t use timer 2 with uart 1, when you have both uart1 and uart0 on separate timers.

In other words, when using two uarts, at separate baud rates, timer 1 must go to uart 1, and timer2 must go to uart 0.

I found this answer in one of the st documents, but I now forget which.

Good to see the forums are still alive.

Many thanks all.

wek2
Associate II
May 17, 2011 9:50 AM UTC
Posted on May 17, 2011 at 11:50

You set Timer2 as baudrate generator for UART2. Do you start Timer2 anywhere (either rewriting T2CON or as setb TR2)?

Jan Waclawek

pbt1668
pbt1668Author
Associate II
May 17, 2011 9:50 AM UTC
Posted on May 17, 2011 at 11:50

Quote:

On 22-05-2006 at 11:15, Anonymous wrote:

It's a pity you don't remember where did you read about it...

By the way, I am using Timer2 for UART1 and Timer1 for UART0 and both are working... Maybe there is a difference in the chips? Mine is uPSD3212C

Jan Waclawek

There is a difference in the chips, I got the 3254a in an 80 pin package.

The notice was in one of ST's quality reports, so I switched timers, and everything worked.