Page 1 of 1
Serial issue
Posted: Sun Apr 13, 2014 6:42 pm
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.
Re: Serial issue
Posted: Mon Apr 14, 2014 6:35 am
by Tabulous
Forgot to mention this is STM32F4
Re: Serial issue
Posted: Mon Apr 14, 2014 7:21 am
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
Re: Serial issue
Posted: Mon Apr 14, 2014 7:53 am
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));
Re: Serial issue
Posted: Mon Apr 14, 2014 7:59 am
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
Re: Serial issue
Posted: Mon Apr 14, 2014 8:36 am
by Tabulous
the calculated BRR values are
35000 for 1200
4375 for 9600
Re: Serial issue
Posted: Mon Apr 14, 2014 2:45 pm
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
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.......
Re: Serial issue
Posted: Mon Apr 14, 2014 3:21 pm
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.