EmbeddedRelated.com
Forums
Memfault Beyond the Launch

USART Transmit Issue

Started by elamaranv November 28, 2007
Hi All, 

I am facing an issue with the USART Transmit. My code is as shown
below...... 

#include <p18F4523.h> 
#include <usart.h> 
void main( void ) 
{ 
char group[10]="Microchip "; 
int i; 
OpenUSART( USART_TX_INT_OFF & 
USART_RX_INT_OFF & 
USART_ASYNCH_MODE & 
USART_EIGHT_BIT & 
USART_CONT_RX & 
USART_BRGH_HIGH, 
129 ); 
while( 1 ) 
{ 
for(i=0; i<10; i++) 
{ 
while (BusyUSART()); 
putcUSART(group [ i ] ); 
} 
} 
CloseUSART( ); 
} 

The above program gets compiled successfully. 

But the result is as follows when checked in the Hyperterminal....... 

icrochip Microchip Microchip Microchip Microchip Microchip Microchip
Microchip Microchip 

The first character 'M' doesn't gets transmitted on to the Hyperterminal,
but in the rest of the sequence the word 'Microchip ' gets transmitted
fine. 

Any idea why the first character 'M' doesn't get transmitted on to the
hyperterminal? 

I am using the MPLAB version 8, C18 compiler Version 3.14, PIC18F4523
Microcontroller. 



On Nov 28, 7:29 pm, "elamaranv" <elamar...@hotmail.com> wrote:

> Hi All, > > I am facing an issue with the USART Transmit. My code is as shown > below...... > > #include <p18F4523.h> > #include <usart.h> > void main( void ) > { > char group[10]="Microchip "; > int i; > OpenUSART( USART_TX_INT_OFF & > USART_RX_INT_OFF & > USART_ASYNCH_MODE & > USART_EIGHT_BIT & > USART_CONT_RX & > USART_BRGH_HIGH, > 129 ); > while( 1 ) > { > for(i=0; i<10; i++) > { > while (BusyUSART()); > putcUSART(group [ i ] ); > > } > } > CloseUSART( ); > } > > The above program gets compiled successfully. > > But the result is as follows when checked in the Hyperterminal....... > > icrochip Microchip Microchip Microchip Microchip Microchip Microchip > Microchip Microchip > > The first character 'M' doesn't gets transmitted on to the Hyperterminal, > but in the rest of the sequence the word 'Microchip ' gets transmitted > fine. > > Any idea why the first character 'M' doesn't get transmitted on to the > hyperterminal?
Perhaps the UART TxD pin was not in an idle condition before it got enabled ? If so, the first character would not have a clear start bit, and would be garbled in the receiver. Try adding a delay (e.g. 10 bit times) between enabling the UART and sending the first data.
You might want to try a delay between initialising the USART and
starting to write to it. The fact that it is outputting the string
correctly after the first character  suggests that the busyUART() wait
is working correctly.

TW

On Nov 29, 2:39 am, Arlet <usene...@c-scape.nl> wrote:
> On Nov 28, 7:29 pm, "elamaranv" <elamar...@hotmail.com> wrote: > > > > > > > Hi All, > > > I am facing an issue with the USART Transmit. My code is as shown > > below...... > > > #include <p18F4523.h> > > #include <usart.h> > > void main( void ) > > { > > char group[10]="Microchip "; > > int i; > > OpenUSART( USART_TX_INT_OFF & > > USART_RX_INT_OFF & > > USART_ASYNCH_MODE & > > USART_EIGHT_BIT & > > USART_CONT_RX & > > USART_BRGH_HIGH, > > 129 ); > > while( 1 ) > > { > > for(i=0; i<10; i++) > > { > > while (BusyUSART()); > > putcUSART(group [ i ] ); > > > } > > } > > CloseUSART( ); > > } > > > The above program gets compiled successfully. > > > But the result is as follows when checked in the Hyperterminal....... > > > icrochip Microchip Microchip Microchip Microchip Microchip Microchip > > Microchip Microchip > > > The first character 'M' doesn't gets transmitted on to the Hyperterminal, > > but in the rest of the sequence the word 'Microchip ' gets transmitted > > fine. > > > Any idea why the first character 'M' doesn't get transmitted on to the > > hyperterminal? > > Perhaps the UART TxD pin was not in an idle condition before it got > enabled ? > > If so, the first character would not have a clear start bit, and would > be garbled in the receiver. > > Try adding a delay (e.g. 10 bit times) between enabling the UART and > sending the first data.- Hide quoted text - > > - Show quoted text -
As pointed by Arlet that you got to provide a decent time for initialization. And another quick fix would be adding/sending a dummy single char that will do the initialization for sure. ali
On Nov 28, 11:43 pm, Ted <tedw...@btinternet.com> wrote:
> You might want to try a delay between initialising the USART and > starting to write to it.
Will it need such a time between initalizing and starting to write ? Strange :(:( What could be the possible reasons ? Any ideas ?
> The fact that it is outputting the string > correctly after the first character suggests that the busyUART() wait > is working correctly. >
Accepted . Karthik Balaguru
On 29 Nov, 09:18, karthikbalaguru <karthikbalagur...@gmail.com> wrote:
> > Will it need such a time between initalizing and starting to write ? > Strange :(:( What could be the possible reasons ? Any ideas ?
Well, at a guess the USART HW is being clocked much slower than the processor clock, and may take a while to initialise. So you need to wait for it. TW

Memfault Beyond the Launch