Serial issue

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Serial issue

Post by Tabulous »

Im trying to run UART2 @ 115200 and UART3 @ 9600, but it seems this combination does not work UART3 will not recieve data. These are both on APB1 and im using STM32_PPRE1_DIV4 for bus pre-scaler STM32_PPRE1.

If i change UART3 to 1200 baud, the UART works fine.......

I'm using a PC / Hyperterminal to send the data to the MCU.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

Forgot to mention this is STM32F4
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial issue

Post by Giovanni »

Hard to tell, try verifying the UART divider values and check if those are the values expected. It is strange anyway, if 1200 works then 9600 should work as well.

Giovanni
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

So the Interrupt is calling this ok

Code: Select all

chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);


But after this the thread waiting for the data never gets signalled ?

Code: Select all

        flags = chEvtGetAndClearFlags(&elEticketdata);

        if(flags & CHN_INPUT_AVAILABLE)
        {
           do
           {
              charbuf = chnGetTimeout(&SD3, TIME_IMMEDIATE);

              if ( charbuf != Q_TIMEOUT )
              {
//                  chprintf((BaseSequentialStream*)&SD6, "<%X>\r\n", charbuf);

                  decodeEticketStateMachine( ps, (char)charbuf );
              }
           }
           while (charbuf != Q_TIMEOUT);
        }

        chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

Tabulous wrote:So the Interrupt is calling this ok

Code: Select all

chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);


But after this the thread waiting for the data never gets signalled ?

Code: Select all

        flags = chEvtGetAndClearFlags(&elEticketdata);

        if(flags & CHN_INPUT_AVAILABLE)
        {
           do
           {
              charbuf = chnGetTimeout(&SD3, TIME_IMMEDIATE);

              if ( charbuf != Q_TIMEOUT )
              {
//                  chprintf((BaseSequentialStream*)&SD6, "<%X>\r\n", charbuf);

                  decodeEticketStateMachine( ps, (char)charbuf );
              }
           }
           while (charbuf != Q_TIMEOUT);
        }

        chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));


but if i set baud rate to 1200 all works fine. It as if the baud rate is not set correctly for 9600
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

the calculated BRR values are
35000 for 1200
4375 for 9600
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

Just to clarify, it does not work at any baud rate above 1200.

I can breakpoint on

Code: Select all

  /* Data available.*/
  chSysLockFromIsr();
  while (sr & USART_SR_RXNE) {
    /* Error condition detection.*/
    if (sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE  | USART_SR_PE))
      set_error(sdp, sr);
    sdIncomingDataI(sdp, u->DR);
    sr = u->SR;
  }
  chSysUnlockFromIsr();


and

Code: Select all

sdIncomingDataI(sdp, u->DR);


is called all the time whether its 1200 or 9600, and the u->DR register contain '\r' (this is the byte i'm sending), so this says to me that the data is been clocked in ok so UART and interrupts are working.

First thing ive noticed when running at 9600 there is a spurious interrupt when application is started, a byte 0xFE is recieved.

sdIncomingDataI() is called this checks the queue and then sets the flag, it also loads into queue.

Code: Select all

  if (chIQIsEmptyI(&sdp->iqueue))
    chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
  if (chIQPutI(&sdp->iqueue, b) < Q_OK)


But the application thread flags is never set.

Code: Select all

        flags = chEvtGetAndClearFlags(&elEticketdata);

        if(flags & CHN_INPUT_AVAILABLE)
        {
        }



Non of this happens at 1200. There is no spurious interrupt etc.......
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial issue

Post by Tabulous »

have fixed this issue, i control the power to the RS232 chip, for low power reasons and i was not waiting long enough for the power to come up before enabling the serial driver hence the spurious byte.
Post Reply