UART looks good on Oscope but not on...

Help
2007-05-25
2013-03-12
  • Stephen Blair
    Stephen Blair
    2007-05-25

    The following program outputs a nice ____     _   _   _   _____ on my o-scope but I get nothing when I
                                             |___| |_| |_| |_|
    connect Windows HyperTerminal to it.  I'm running a 40 MHz uPSD3354D at 19200, 8, N, 1.  I'm using an ST3232 as an RS-232 level shifterand all appears to be well there.  On the MCU side I'm getting highs of 2.8V and lows of 0V.  On the RS-232 side I'm getting +3V highs and -2V lows.  Are the RS-232 voltages high enough?

    Here's my code:

    // UART0.c
    //
    #define PSD_CSIOP    0x7F00
    #include <uPSD33XX.h>

    void timer0_isr (void) interrupt TIMER0_INTERRUPT using 1;
    void timer0_init (void);
    unsigned int timer0_count (void);
    void timer0_delay (unsigned int count);

    void InitSerial(void);
    unsigned char RxdSerial( unsigned char *c );
    unsigned char TxdSerial( unsigned char c );

    static unsigned int idata timer0_tick;
    static unsigned int idata timer0_value;
    static unsigned char uart_data;

    #define FREQ_OSC    40000

    main()
    {
        timer0_init();             // Initialize timer 0
        InitSerial();

        PSD_PMMR0|=0x08;           // Disable PSD Module Turbo Mode to save power                                   
        PSD_PMMR2|=0x3C;           // Set PSD Module PLD input blocking bits to save power

        P3SFS |= 0x03;             // Set P3.0 and P3.1 active

        while (1)
        {
            TxdSerial(0xAA);
            timer0_delay(6);       // Delay 6mS, byte should be 5.2mS
        }
    }

    void InitSerial(void)
    {
        RCAP2L = 0xBF;              // 40 MHz at 19200 Baud
        RCAP2H = 0xFF;
        T2CON  = 0x34;              // Enable RCLK & TCLK for baud clock enable
                                    // And turn on Timer 2
        SCON0  = 0x40;              /* SCON: mode 1, 8-bit UART, enable rcvr      */
       
        RI     = 0;
        REN    = 1;

        EA     = 1;                 /* Enable interrupts                          */
        ES0    = 1;                 /* Enable UART0 interrupts                    */
    }

    unsigned char RxdSerial( unsigned char *c )
    {
    *c='\0';
    while(!(RI));
    RI = 0;
    *c = SBUF0;
    return *c;
    }

    unsigned char TxdSerial( unsigned char c )
    {
    SBUF0=c;
    while(!(TI));
    TI = 0;
    return c;
    }

    void uart0_isr (void) interrupt UART0_INTERRUPT using 1
    {
        // Not yet
    }

    void timer2_isr (void) interrupt TIMER2_INTERRUPT using 1
    {
        // Shouldn't have to?
    }

    void timer0_isr (void) interrupt TIMER0_INTERRUPT using 1
    {
        TR0 = 0;                      /* stop timer 0 */
        TL0 = (timer0_value & 0x00FF);
        TH0 = (timer0_value >> 8);
        TR0 = 1;                      /* start timer 0 */
        timer0_tick++;                // Increment global var timer_tick (number of 10ms ticks)
    }

    void timer0_init (void)
    {
        EA = 0;                 /* disable interrupts */
        timer0_tick = 0;
        TR0 = 0;                /* stop timer 0 */
        TMOD &= 0xF0;           /* clear timer 0 mode bits - bottom 4 bits */
        TMOD |= 0x01;           /* put timer 0 into 16-bit no prescale */

        // Calculate timer rollover based on FREQ_OSC to be 10ms periods (100hz)
        timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);
        TL0 = (timer0_value & 0x00FF);
        TH0 = (timer0_value >> 8);

        ET0 = 1;                /* enable timer 0 interrupt */
        TR0 = 1;                /* start timer 0 */
        EA = 1;                 /* enable interrupts */
    }

    unsigned int timer0_count (void)
    {
        unsigned int t;

        EA = 0;               // disable interrupts to read a non-changing value
        t = timer0_tick;
        EA = 1;               // enable interrupts
        return(t);
    }

    void timer0_delay (unsigned int count)
    {
        unsigned int start_count;

        start_count = timer0_count();                     /* get the start count */

        while ((timer0_count() - start_count) <= count)   /* wait for count "ticks" */
        {
            PCON |= 0x01;    // Idle MCU to wait for timer tick
        }
    }

     
    • Patryk
      Patryk
      2007-05-25

      According to ST3232's datasheet RS232 voltages are at +-5V range. +3V/-2V may not work on some systems. Did you checked Vcc of ST3232? On the MCU side 2.8V seems to be too low (if Vcc is 3.3V and ST3232 is connected directly to MCU without any resistors nor pull-downs on MCU).

       
    • Stephen Blair
      Stephen Blair
      2007-05-26

      Looks completely different on the voltmeter.  MCU to ST3232 reads 3.3V.  Output of ST3232 (pin 14) reads -8V.  Now I'm really puzzled.  Any ideas?

      Best Regards,
      Stephen Blair

       
      • Make sure that the flow control in HyperTerminal is set to 'none':

        Properties -> Conect to -> Configure... -> Flow Control: -> none

        Jesus

         
      • Patryk
        Patryk
        2007-05-28

        -8V is OK (datasheet mantions only low limit at 5V, typical 5.4V), but you have written before that it was -2V (?). What is Vcc of MCU and ST3232? 3.3V? Check with scope if it stays at 3V during transmission. If Vcc is 3.3V and no resistors, 2.8V is suspected (is it on both RX and TX of MCU?).

        Check your schematic with that on page 7 in datasheet (4. Application). Did you use 100nF capacitors? Check RS port of your PC with a loop - short TX and RX pins (#2, #3), use HyperTerminal and see if characters are echoed (check if local echo is turned off in it's settings). Attach RS cable to PC port, short RX and TX pins on it's end and repeat echo test. Connect your board with PC, put TX pin of MCU in Hi-Z state (hold reset for example), then short TX and RX pins of MCU and repeat echo test.

         
    • Stephen Blair
      Stephen Blair
      2007-05-26

      Flow control is on none.  There are no pull ups or downs resistors installed.  I've tried two differrent ST3232's.  I've tried Indigo Terminal Emulator from shadeBlue.  I connected my modem to the serial port on the PC and it works fine, so it's not the serial port on the PC.

      I'm getting desperate.

      Stephen Blair

       
    • Stephen Blair
      Stephen Blair
      2007-05-28

      Used 100nf caps all the way around the ST3232.  Shorted pins 2 & 3 and did get echo in Hyperterminal.  When I put MCU TX pin in hi-z state by pressing reset then apply power while short pins 2 & 3 are shorted I get no echo.

       
      • Patryk
        Patryk
        2007-05-29

        To be 110% sure: when you get echo, turn on 'Local echo' in Hyperterminal and see if your echo is doubled.

         
    • Stephen Blair
      Stephen Blair
      2007-05-28

      A little testing showed that both TxD and RxD are not in Hi-Z state while holding down reset.  They both read +3.3V.  All PORT B pins appear to be in Hi-Z.  That is they read 0V.

       
      • Patryk
        Patryk
        2007-05-29

        RxD (P3.0) and TxD (P3.1) are MCU pins, they got internal weak pull-up (~150kOhm), you can check it by connecting 1kOhm resistor to GND - voltage should drop below 100mV. PORT B is PSD port, it may behave differently.

         
    • Patryk
      Patryk
      2007-05-29

      OK, time to do some order in mess. I assume MCU is powered with +5V (PSD) and +3.3V (MCU), ST3232 with +3.3V. Your board is equipped with RS232 FEMALE connector, and you got MALE/FEMALE RS232 cable.

      MCU             ST3232              ST3232               connector   cable       PC
      RxD (P3.0)  <-  R1OUT (pin #12)     R1IN  (pin #13)  <-  pin #3       <-     <-  pin #3 TX
      TxD (P3.1)  ->  T1IN  (pin #11)     T1OUT (pin #14)  ->  pin #2       ->     ->  pin #2 RX

                      R2OUT (pin #9 )     R2IN  (pin #8 )  <-  pin #7       <-     <-  pin #7 CTS

      I suspect assembly errors around ST3232, or it is damaged. If you checked board against shorts, broken traces and bad solder, apply procedure below to check ST3232.

      1. Detach RS232 cable, put MCU in reset.
      2. Check 5V and 3.3V on MCU and 3.3V on ST3232.
      3. Check 3.3V RxD/TxD/R1OUT/T1IN/R2OUT.
      4. Check ST3232 pins: V+ (pin #2) > +5V and V- (pin #6) < -5V.
      5. Check ST3232 pin: T1OUT (pin #14) equal to V- (pin #6).
      6. Short TxD (P3.1) to GND.
      7. Check again 5V and 3.3V on MCU and 3.3V on ST3232.
      8. Check ST3232 pin: T1OUT (pin #14) equal to V+ (pin #6).
      9. Remove short TxD (P3.1) to GND.
      10. Connect RS cable to PC only, assure COM is not open by any application.
      11. Check cable pins in plug not attached to board yet: pin #3 and #7 around -10..-12V, pin #2 0V.
      12. Open COM with Hyperterminal, check pin #7 around +10..+12V.
      13. Short pin #2 and #3, do loop test (echo with Hyperterminal).
      14. Assure COM is not open by any application.
      15. Connect RS cable to board.
      16. Check again 5V and 3.3V on MCU and 3.3V on ST3232.
      17. Check 3.3V TxD/T1IN.
      18. Check T1OUT (pin #14) < -5V.
      19. Check R1IN/R2IN (pin #13/#8) < -5V.
      20. Open COM with Hyperterminal.
      21. Do checks 16..18 above.
      22. Check R1IN (pin #13) < -5V, R2IN (pin #8) > +5V.
      23. Check R1OUT (pin #12) +3.3V, R2OUT (pin #9) 0V.
      24. Short TxD and RxD, do loop test (echo with Hyperterminal), check it with scope (R1IN/R1OUT/RxD/TxD/T1IN/T1OUT path).
      25. Congratulations, your hardware seems to work :-)

       
    • Stephen Blair
      Stephen Blair
      2007-05-29

      Everything checked out until I got to step 24.  I commented out the part of the MCU program that outputs characters to allow loopback without interference and reloaded the MCU with effectively an empty while loop.  I shorted out TxD and RxD (at the ST3232 - same as MCU by ohm meter) and got no loopback in Hyperterminal.  T1IN = +3V, R1OUT = +3V, R1IN = 0V, T1OUT = -8V.  I get the same on the scope except that T1OUT shows serial activity swinging from -8V to -3V.

       
      • Patryk
        Patryk
        2007-05-30

        According to checkpoint 1, you should put MCU in reset and keep it there. That's the easiest way. If you prefer to change code, you should also disable code that enables UART. When UART is enabled, TxD becomes push-pull output, so there is contention with R1OUT/RxD when you short TxD with RxD. This can affect loop test.

        "T1IN = +3V, R1OUT = +3V, R1IN = 0V, T1OUT = -8V"
        From wich checkpoint are that measures? I believe that 3 and 5. What are checkpoint 4 measures?

        "T1OUT shows serial activity swinging from -8V to -3V."
        And V+ (pin #2) of ST3232 is ok (> +5V)?! If there is no schematic/assembly errors, you should replace ST3232.

        "I assume MCU is powered with +5V (PSD) and +3.3V (MCU), ST3232 with +3.3V. Your board is equipped with RS232 FEMALE connector, and you got MALE/FEMALE RS232 cable.
        MCU ST3232 ST3232 connector cable PC
        RxD (P3.0) <- R1OUT (pin #12) R1IN (pin #13) <- pin #3 <- <- pin #3 TX
        TxD (P3.1) -> T1IN (pin #11) T1OUT (pin #14) -> pin #2 -> -> pin #2 RX

        R2OUT (pin #9 ) R2IN (pin #8 ) <- pin #7 <- <- pin #7 CTS
        "
        Could you confirm my assumptions?

         
    • Stephen Blair
      Stephen Blair
      2007-05-29

      Upon closer examination of the scope trace, each byte is only somewhere between 400 and 600uS long.  I calc'd a 19200 byte should be about 5.2mS.

       
      • Patryk
        Patryk
        2007-05-30

        1 bit at 19200 takes 1/19200 = 0.052ms. 10 bits (1 start + 8 data + 1 stop) takes 0.52ms, so what you see is OK. I suppose this is output from PC seen in "checkpoint" 13 or 24 during loop test.

         
    • Stephen Blair
      Stephen Blair
      2007-05-31

      Everything checks out fine except:

      Step 8 - Typo - V+ is actually pin #2 (check step 4).
      Step 19 - R1IN (pin #13) = 0V.  However pin 2 on RS port = 0V.

      My mistake on the T1OUT swing.  It scopes out from -2V to +3V.

      The MCU PSD is +5V and the MCU is +3.3V.  The ST3232 is +3.3V.  The board does have a female RS232 connector and there is a male to female cable to the PC.  RxD and TxD and associated pins listed in your last post are correct.

      I'm not using R2OUT (pin #9).  Where would CTS be coming from on the MCU or ST3232?

       
      • Patryk
        Patryk
        2007-06-01

        "Step 8 - Typo"
        Agree, it's typo. What voltage is at V+/V- at checkpoint 4?

        "Step 19 - R1IN (pin #13) = 0V. However pin 2 on RS port = 0V.
        My mistake on the T1OUT swing. It scopes out from -2V to +3V."
        T1OUT should be connected to pin 2 on RS, so it cannot swing if it sticks at 0V - seems to be some wiring/cabling issue. Check connections once again: ST3232 pin numbering (pin #1 is left-down when you see strings on package normally, not upside down), RS connector pin numbering (small numbers on plastic part, check out mirror issues when looking at pins soldered to board, it's best to check with ohmmeter: needle or piece of wire into connector, then touch needle and ST3232 pin with ohmmeter, also check for shorts with GND, with VCC and with other pins of connector), RS cable (straight-thru, pin 1 to pin 1, pin 9 to pin 9).

        "I'm not using R2OUT (pin #9). Where would CTS be coming from on the MCU or ST3232?"
        As in third line of my "schematic":
        R2OUT (pin #9 ) R2IN (pin #8 ) <- pin #7 <- <- pin #7 CTS (ERROR: this should be RTS)
        RTS is PC output, it's easier to place in desired steady state (-12V or +12V) RTS pin than TX pin, so it's convenient to test voltage levels before and after ST3232.
        You probably need not to use RTS, but it's useful for such tests as you do now. It may be needed later for flow control, so it's a good idea to wire it and connect R2OUT to an unused MCU GPIO pin. The same applies to CTS, but in other direction.
        MCU pin -> T2IN (pin #10) T2OUT (pin #7) -> pin #8 -> -> pin #8 CTS

         
    • Stephen Blair
      Stephen Blair
      2007-06-01

      "What voltage is at V+/V- at checkpoint 4?"
      V+ = +5.9V and V- = -5.5V

      "Step 19 - R1IN (pin #13) = 0V. However pin 2 on RS port = 0V. 
      My mistake on the T1OUT swing. It scopes out from -2V to +3V."

      Actually T1OUT (ST3232 pin #14) is connected to RS232 pin 3.  I ohm'd the RS port and the ST3232 and all is fine i.e. no shorts.

      "I'm not using R2OUT (pin #9). Where would CTS be coming from on the MCU or ST3232?"
      As in third line of my "schematic"

      What schematic are you referring to?  I'm using the upsd3300 Dev Board.pdf from ST's web site.

       
      • Patryk
        Patryk
        2007-06-04

        "V+ = +5.9V and V- = -5.5V "
        OK.

        "Actually T1OUT (ST3232 pin #14) is connected to RS232 pin 3."
        "I'm using the upsd3300 Dev Board.pdf from ST's web site."
        Do you mean ED3k3, uPSD3300 Evaluation Board Schematics, 1.0, May-2005
        http://mcu.st.com/mcu/download2.php?file=1115656037.pdf&info=µPSD Evaluation Board Doc &url=/mcdfiles/1115656037.pdf
        There is only schematic on site, no manual. You use that board or your own, based on this schematic? There is error on schematic: T1OUT (ST3232 pin #14) should be connected to RS232 pin #2 of RS connector, R1IN (pin #13) to pin #3, as in my "schematic" (netlist?) posted in one of the previous posts, copied below:

        RxD (P3.0) <- R1OUT (pin #12) R1IN (pin #13) <- pin #3 <- <- pin #3 TX
        TxD (P3.1) -> T1IN (pin #11) T1OUT (pin #14) -> pin #2 -> -> pin #2 RX

        R2OUT (pin #9 ) R2IN (pin #8 ) <- pin #7 <- <- pin #7 CTS (TYPO: should be RTS)
        (irrelevant if you use ED3k3)

        If you use ED3k3 board, check if it follows schematic (with error) or it's only schematic typo. Check also your cable, if it's really straight-thru.

         
    • Stephen Blair
      Stephen Blair
      2007-06-07

      Your right about there being a wiring error on pins 2 and 3 of the Female RS-232 connector on the MCU.

      Loading RCAP2H = 0xFF and RCAP2L = 0xBF with fosc MHz = 40.00 yields 2400 baud, not 19200 baud as shown in table 43 in the manual entitled:

      uPSD34xx
      Turbo Plus Series
      Fast Turbo 8032 MCU with USB and Programmable Logic
      July 2006 Rev 4.

      All hardware, that is the MCU and the ST3232, operate fine at 2400 baud.  Any ideas why this is occurring?  Clearing the Turbo Bit makes no difference.  And the math (baud rate = fosc/(32 x (65536 - [RCAP2H, RCAP2L])) according to the formula given on page 77 jives with Table 43.