Skip to main content
Visitor II
April 11, 2006
Question

Any example of uart1 code available - uPSD3300 processor?

  • April 11, 2006
  • 6 replies
  • 1320 views
Posted on April 11, 2006 at 08:34

Any example of uart1 code available - uPSD3300 processor?

    This topic has been closed for replies.

    6 replies

    st12Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    I am attempting to add support for the second uart to an existing program ported from an 8051. I have had no luck getting any output from the second uart. I have Googled furiously and can find no example code for this microcontroller family which successfully operates this second port. If anyone can point me toward a simple example that sends and receives anything from the second uart I'd appreciate it.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    What about the other way round? Post your code (reasonably stripped down, of course) here and we might try to tell you what's wrong...

    Jan Waclawek

    st12Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    I'll work on that.

    As I didn't write the original it may take a while to figure out where all of the configuration is being done. I had been hoping to just see how the configuration registers needed to be set to enable the second uart.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    The following is specifically for uPSD3212, check for possible differences for your chip (I doubt there are any, but check to be sure).

    The init is pretty the same as for UART0, just the bits are in different locations.

    So you first need to have a baudrate generator, use either Timer1 (set it up and run exactly in the same way as if it would be for UART0) or Timer2 - set it up and run exactly as for UART0 except the RCLK and TCLK bits in T2CON, which determine binding of Timer2 as baudrate generator to UART0; set TCLK1 and RCLK1 bits in PCON instead.

    Then set up the serial port itself, placing the appropriate value into SCON2 (9Ah) instead of SCON - note, that this is not a bit addressable SFR, so you need to use mov, anl, orl on the whole byte (also, if you will test it for the ri1/ti1 flags, you cannot simply use jb ri1, you have to load the byte first e.g. into accumulator and test there). The appropriate SMOD1 bit is located in PCON but as bit 6.

    As for serial port you are about finished, you might then want interrupt-driven communication, for which see bit 4 in IEA and IPA (interrupt enable and priority registers for the extended interrupts) and the interrupt vector is at 004Bh.

    It's easy, isn't it? :)

    The main trouble is that the documentation is really not quite clear about it and you need to gather the pieces of informations from various places. Also, the inconsistency in numbering the ports and associated SFRs and pins is at least... ehm... confusing (see my ramblings:

    http://mcu.st.com/mcu/modules.php?mop=modload&name=Splatt_Forums&file=viewtopic&topic=3329&forum=11

    )

    Have fun!

    Jan Waclawek

    st12Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    Thank you for your reply.

    I have come up with the following, which I will be testing soon to see

    if it works. (I need to set up a test download w/o the full application

    in order to test). If there is anything in this init that doesn't look

    proper I'd appreciate a word. (This is on a uPSD3354)

    thanks again

    #include ''regPSD.h''

    #define XTAL 33000000

    #define BAUD 57600

    #ifndef FALSE

    #define FALSE 0

    #endif

    void init_uart1( void )

    {

    TMOD |= 0x20; // Timer 1 mode=8 bit auto_reload

    TH1 = (unsigned char) (256 - (XTAL / (16L * 12L * BAUD)));

    SCON1 = 0xE0; // SM1=1 SM0=1 mode 3 - 11 bits data

    PCON |= 0xCC ; // RCLK1=1, TCLK1=1 - RCV and XMT CLK enable

    // smod1=1 UART1 - baudrate*2

    TR1 = 1; // enable baud rate generator

    RI1 = FALSE; // prepare to receive

    REN1 = 1; // receiver enable

    P1SFS0 |=0x0C; // Set P1.2,P1.3 as UART1 pins

    IEA |= 0x10 ; // ES1=1 Enable Uart1 irq

    }

    int main( void )

    {

    init_uart1();

    ... much code snipped ...

    }

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:50

    I am not much into C, but the following might be an issue:

    Quote:

    PCON |= 0xCC ; // RCLK1=1, TCLK1=1 - RCV and XMT CLK enable

    // smod1=1 UART1 - baudrate*2

    If you set RCLK1 and TCLK1 in PCON, you are about to use Timer2 as baudrate generator for UART1; so you would need to set up Timer2 rather than Timer1.

    Quote:

    RI1 = FALSE; // prepare to receive

    REN1 = 1; // receiver enable

    I don't know how and if your C compiler can cope with these assignments but I doubt - note that SCON1 is NOT bit addressable. But, anyway, you are setting SCON1 above, so why not including these bits into the constant?

    Have you tried to compile this snippet? Later, you might want to post here the (assembly) listing of the compiler, to discuss this further.

    Quote:

    P1SFS0 |=0x0C; // Set P1.2,P1.3 as UART1 pins

    This one might be 33xx specific I didn't check - I hope you did. On the 3212 I am working with there is no need to set P1SFS0 to enable the UART1 pins.

    Quote:

    IEA |= 0x10 ; // ES1=1 Enable Uart1 irq

    Yes, but only if you intend to use interrupt-driven communication; you need also to define the interrupt service routine of course.

    Have fun!

    Jan Waclawek

    [ This message was edited by: wek1 on 11-04-2006 12:06 ]