Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: why there is a more bit between two byte
PostPosted: Tue Apr 12, 2011 2:33 am 
Offline

Joined: Fri Mar 04, 2011 5:21 am
Posts: 11
i use uart2 to send data,but when i send two bytes 0xff,there always one more bit between them,who know why?the following is the initial code about uart2.

void UART2_INIT(unsigned int baudrate)
{
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_US2);//enable us2 peri clock
AT91C_BASE_PIOB ->PIO_ASR|=(AT91C_PB8_TXD2|AT91C_PB9_RXD2); //set piob8,9 as txd2,rxd2
AT91C_BASE_PIOB -> PIO_PDR|=(AT91C_PB8_TXD2|AT91C_PB9_RXD2); //disable piob8,9 control by piob
/* Disable interrupts */
AT91C_BASE_US2->US_IDR = 0xFFFFFFFF;
/* Reset the receiver and transmitter */
AT91C_BASE_US2->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX
| AT91C_US_RXDIS | AT91C_US_TXDIS;

AT91C_BASE_US2->US_BRGR = baudrate;
// Configure mode
AT91C_BASE_US2->US_MR = AT91C_US_USMODE_NORMAL
|AT91C_US_CHRL_8_BITS|AT91C_US_PAR_EVEN|AT91C_US_NBSTOP_2_BIT;

// Configure baudrate
// Asynchronous, no oversampling

// AT91C_BASE_US3->US_BRGR = (masterClock / baudrate) / 16;
AT91C_BASE_US2->US_CR |= AT91C_US_TXEN;
AT91C_BASE_US2->US_CR |= AT91C_US_RXEN;
}


Top
 Profile  
 
 Post subject: Re: why there is a more bit between two byte
PostPosted: Tue Apr 12, 2011 3:34 am 
Offline

Joined: Thu Apr 19, 2007 10:15 pm
Posts: 204
Location: USA
Hi there

Is this mystery bit marking or spacing?
How many bits are you assuming there are in each character frame?
Why don't you report all the bits that you have identified that surround this mystery bit?

> when i send two bytes 0xff,there always one more bit between them

The only possible answers would be:
a. if the bit is marking, then it could be the second stop bit of the preceding character frame, or idle time between characters (you have not shown us the code that outputs the chars);
b. if the bit is spacing, then it would be the start bit of the succeeding character frame.

Regards


Top
 Profile  
 
 Post subject: Re: why there is a more bit between two byte
PostPosted: Tue Apr 12, 2011 6:59 am 
Offline

Joined: Fri Mar 04, 2011 5:21 am
Posts: 11
the format is 1bit start,8bit data,1bit partiy,2bit stop,the total byte is 12bit,
the output of 2byte is 25bit,and there is a low bit between two bytes.
i dont know how to capture the waveform from osciograph.
it seems can be used to usb-stick to save.i will post the waveform picture after i have learnd how to save it into my computer.


Top
 Profile  
 
 Post subject: Re: why there is a more bit between two byte
PostPosted: Tue Apr 12, 2011 8:46 am 
Offline

Joined: Thu Apr 19, 2007 10:15 pm
Posts: 204
Location: USA
Hi there

> the format is 1bit start,8bit data,1bit partiy,2bit stop,the total byte is 12bit,

That looks correct.

> the output of 2byte is 25bit,and there is a low bit between two bytes.

A "low bit" is the line just marking between character frames: the line is idle.
Is there some kind of delay between the writes to the transmit register?

If you're concerned about throughput, then perhaps you could reduce the frame length by two bits:

The 2 stop bits could be reduced to just 1 stop bit. Modern electronics only need 1 stop bit. The last time I needed to use 2 stop bits was because of an inaccurate baud rate generator on one end.

The parity bit could be omitted since it is not reliable for ensuring data integrity. Parity will catch single bit errors, but give a false negative with a double-bit error (i.e. the error is not reported). If it's binary data, you are much better off including a CRC32 checksum covering the transmitted block than relying on parity checks.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: