SAM4S16C UART not appending stop bit

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

SAM4S16C UART not appending stop bit

Thu Jan 08, 2015 5:55 pm

Hello,

Recently I have run into a problem, where, while sending a character via UART interface the transmit data frame is not appended with the stop bit while sending some characters such as "+" and "-". With all the other characters the stop bit is appended. Has anyone here ever ran into such a problem or has experience as to what could be causing this behavior. If so, please share your experience. Thanks in advance.

Regards.
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: SAM4S16C UART not appending stop bit

Thu Jan 08, 2015 7:00 pm

Owais wrote:please share your experience
never have seen this ... have you verified your uart configuration and have you witnessed the problem on a scope?

A test i always perform when setting up a new uart is to send a stream of 0xAA or 0x55 and verify the frame and bit times on a scope *first* to make sure my configuration is setup correctly ;)
Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

Re: SAM4S16C UART not appending stop bit

Fri Jan 09, 2015 9:50 am

Thanks for the responses. I have confirmed this behavior using a scope where I send a '+' character from UART and confirm it on scope which shows no parity bit. I am using Picoscope 3206MSO which has the capability of decoding serial data and displaying it in table where it separates the data start and stop bits. I have also tried sending the same character from PC terminal and there it shows the stop bit been appended. The UART setup is as follows:

Code: Select all

void Config_UART1 ( void )
{
	/* Set peripheral A on PB2 */
	PIOB->PIO_ABCDSR[0] = ~PIO_ABCDSR_P2;
	PIOB->PIO_ABCDSR[1] = ~PIO_ABCDSR_P2;
	
	/* Disable PIO controller for PB2 */
	PIOB->PIO_PDR = PIO_PDR_P2;
	
	/* Set peripheral A on PB3 */
	PIOB->PIO_ABCDSR[0] = ~PIO_ABCDSR_P3;
	PIOB->PIO_ABCDSR[1] = ~PIO_ABCDSR_P3;
	
	/* Disable PIO controller for PB3 */
	PIOB->PIO_PDR = PIO_PDR_P3;
	
	/* Enable peripheral clock for UART1 */
	PMC->PMC_PCER0 = PMC_PCER0_PID9;

	/* Reset and disable receiver & transmitter */
	UART1->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;

	/* Configure baud-rate to 115200 */
	/* Baud-rate = MCK/(16*UART_BRGR) */
	/* Asynchronous, no oversampling */
	UART1->UART_BRGR = 65;
	
	/* Configure mode */
	UART1->UART_MR = UART_MR_PAR_NO;

	/* Disable PDC channel */
	UART1->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;

	/* Enable receiver and transmitter */
	UART1->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
	
	/* Configure UART in normal mode */
	UART1->UART_MR = UART_MR_CHMODE_NORMAL;
}
I have also matched both the signals from PC and from SAM4S for the same character and can see the difference at the end of the signal.

Also note that all the other characters *are* appended with a stop bit as expected.
Regards.
Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

Re: SAM4S16C UART not appending stop bit

Fri Jan 09, 2015 4:57 pm

Please check the link below for a copy of the two frames. The Frame represented in RED is from PC terminal which is the correct one and the one in BLUE is from SAM4S which is the bad one. Note the difference at the end of both frames.
https://www.dropbox.com/s/0du0yocn3ne72 ... e.jpg?dl=0
blue_z
Location: USA
Posts: 1762
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAM4S16C UART not appending stop bit

Fri Jan 09, 2015 10:45 pm

Owais wrote:Recently I have run into a problem, where, while sending a character via UART interface the transmit data frame is not appended with the stop bit while sending some characters such as "+" and "-".
Describing an issue solely in terms of what does not occur is not helpful and incomplete. The list of what does not happen is almost infinite, whereas what did happen is finite.
For instance I can add that there was no sine wave after the character, that there was no picture of Santa Claus, that there was no music playing and so on.
Owais wrote:Please check the link below for a copy of the two frames. The Frame represented in RED is from PC terminal which is the correct one and the one in BLUE is from SAM4S which is the bad one. Note the difference at the end of both frames.
https://www.dropbox.com/s/0du0yocn3ne72 ... e.jpg?dl=0
The first trace could be 8N1 or 7E1 or 7S1.
The second trace could be 9N1 or 8E1 or 8S1; that is, there's one more bit (for data or parity) in the frame.

There is no indication that the stop bit is missing, especially since the line idles at the Mark state. You could confirm that by immediately transmitting a second character, so that the stop bit would be revealed by the start bit.
If the stop bit was truly absent, then the line would idle at whatever state of the last bit (MSb data or parity), which is the space level in this case.

Regards
Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

Re: SAM4S16C UART not appending stop bit

Sat Jan 10, 2015 12:22 pm

Thank you for taking time to response. Of all the responses above, I can see that I have to be more convincing that the problem really exist. I have not only observed the frame on scope but also an external device that I need to communicate with is not responding to character '+' send from SAM4S(BLUE) but responding to the one sent by PC(RED). Moreover, as seen in the above frame the scope has decoded the character as 0x2B corresponding to a '+' character in ASCII. I could also include a table which shows the stop bit and data byte separately from which it is more clear that there is no stop bit. Besides this could anyone suggest in the meantime what I could do to rectify the problem? Also from the above given initialization does anyone see something that I am missing? Thanks for the support.

Regards.
blue_z
Location: USA
Posts: 1762
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAM4S16C UART not appending stop bit

Sat Jan 10, 2015 10:09 pm

Owais wrote:Of all the responses above, I can see that I have to be more convincing that the problem really exist.
There is an issue, but you are mischaracterizing it and the root cause is in your code.
Owais wrote:... it is more clear that there is no stop bit.
Your persistence in describing this issue in those inaccurate terms discourages me from simply pointing out the root cause.
Instead you should learn about RS-232 framing and stop bits by sending two characters in succession (instead a a single character) so that the stop bit (and frame of the first character) will be distinguishable from the idle line.

You could also loop back the TxD to the RxD, and check if a framing error is detected on these alleged bad frames that have "no stop bit"; the SAM4S UART will be able to receive these frames without any issues.

You could also expand the debugging of this issue and transmit more/different values to categorize which characters trigger this issue and which do not.

Regards
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: SAM4S16C UART not appending stop bit

Sun Jan 11, 2015 1:31 pm

Listen to what these people are telling you.
Stop bits are high, and thus indistinguishable from the idle state. The extra bit you are seeing is low, it is almost certainly a parity bit.
Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

Re: SAM4S16C UART not appending stop bit

Sun Jan 11, 2015 1:46 pm

Thanks again for all the suggestions. I will follow all the steps to better understand the problem and probably find a solution to it.
jarnoldbrown wrote:Listen to what these people are telling you.
Stop bits are high, and thus indistinguishable from the idle state. The extra bit you are seeing is low, it is almost certainly a parity bit.
As long as my initialization is correct it most certainly is not a parity. Please see the initialization code posted above.

Regards.
bseljak
Posts: 28
Joined: Thu Apr 03, 2014 1:28 am

Re: SAM4S16C UART not appending stop bit

Sun Jan 11, 2015 10:02 pm

Hi!
It took me 2 minutes to found out the problem, 1 to search an download datasheet, 1 to check your code...  ;)

You set even parity in the last line of your initialization!  

Regards.
jarnoldbrown
Posts: 36
Joined: Thu Aug 22, 2013 5:31 pm

Re: SAM4S16C UART not appending stop bit

Mon Jan 12, 2015 12:39 pm

bseljak wrote:Hi!
It took me 2 minutes to found out the problem, 1 to search an download datasheet, 1 to check your code...  ;)

You set even parity in the last line of your initialization!  

Regards.
Good catch.
In case you don't understand what bseljak is saying here, when you write UART_MR_CHMODE_NORMAL to the UART_MR, you are clearing the PAR bits, which gives even parity.
You should either set all the bits in one go, i.e.
UART_MR = UART_MR_CHMODE_NORMAL | UART_MR_PAR_NO;
and remove the last line.

Or

Change the last line to:
UART_MR |= UART_MR_CHMODE_NORMAL;
which actually does nothing, as ORing with 0x00000000 does nothing, but shows your intention and allows you to change to another mode at a later date, if you wish.

I'd go for the first option.
Owais
Posts: 57
Joined: Wed Jul 23, 2014 3:25 pm

Re: SAM4S16C UART not appending stop bit

Mon Jan 12, 2015 1:39 pm

Thanks everyone for the support.
jarnoldbrown wrote: In case you don't understand what bseljak is saying here, when you write UART_MR_CHMODE_NORMAL to the UART_MR, you are clearing the PAR bits, which gives even parity.
I completely understood what bseljak meant, in fact that was my very first thought after reading the post. So I changed the initialization and wrote to the register in one go and *VOILA* it started working. 

Once again thanks everyone for all the suggestions and guidance. Now I know how to better debug a problem.

Regards.
blue_z
Location: USA
Posts: 1762
Joined: Thu Apr 19, 2007 10:15 pm

Re: SAM4S16C UART not appending stop bit

Mon Jan 12, 2015 10:56 pm

bseljak wrote:It took me 2 minutes to found out the problem, 1 to search an download datasheet, 1 to check your code...  ;)
You are neither the first or only person to spot the code bug.
Your post to demonstrate your cleverness also reveals your vanity.

Have you ever read the proverb "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime"?
You gave the OP a "fish", whereas others were trying to get the OP to realize his mistakes and learn how to properly use information from a 'scope. With a code fix in hand, the OP has no incentive anymore to follow through with more analysis.
You obviously saved the OP some time & effort, but IMO you also did him a disservice.

Regards

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests