Posted by Piotr Piwko January 11, 2008
Hello.

I try to use USART Iterface, so I initiate it:

RCSTA |= (1<<7); // SPEN, Serial Port Enable
TRISC |= 0xC0; // Piny RC6 i RC7
TXSTA &= ~(1<<6); // TX9, 8-bit transmission
TXSTA |= (1<<5); // TXEN, Transmission enabled
TXSTA &= ~(1<<4); // SYNC, Asynchronous mode
TXSTA &= ~(1<<3); // SENDB, Sync break transmission completed
RCSTA &= ~(1<<6); // RX9, 8-bit reception
RCSTA |= (1<<4); // CREN, Enables receiver
BAUDCON |= (1<<1); // WUE, Wake-up Enable
BAUDCON &= ~(1<<0); // ABDEN, Auto-baud detect disable
SPBRG = 12; // Baud rate 9600, Fosc = 8MHz
TXSTA &= ~(1<<2); // BRGH, Low speed
BAUDCON &= ~(1<<3); // BRG16, 8-bit Baud Rate Generator

My transmit function is:

void usart_send(char value)
{
while(!PIR1bits.TXIF);
TXREG = value;
while(!TXSTAbits.TRMT);
}

I don't know why, but I always get on my terminal only first two byte
and some 0x00. After that, program suspends on checking TRMT bit.

Thanks in advance for any help.

--
Peter