Strange error in RS-232 transmission

Status
Not open for further replies.

kyru27

New Member
I have a pretty weird error trying to do a sample RS-232 transmision. This is the code that's hardly going to be bad as it's pretty short:

# include <p18F4620.h>
# include <usart.h>

#pragma config XINST=OFF
#pragma config OSC=XT
void main ()
{

TRISC = 0x00;
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 129);

while (1)
{
putrsUSART ("hola");

}

}

It should be showing on the hyperterminal window "holaholaholahola" and this way all the time, but instead it shows strange simbols like the ones shown in the screenshot:

Any idea of what can be happening? The error is so strange that I do not even know what to start checking .

Thanks.
 
Doesn't seem to be that... whether I put it on 1200, 2400 or 4800 bauds I get strange symbols. In anything below or above those bauds I get nothing...

Thanks, anyway.
 
ALL settings have to match, not just baud rate, but from what i see, i have to agree, this is consistent with wrong baudrate.
 
Last edited:
I think the biggest worry here is..... with a osc setting of XT (up to 4mhz) there IS no setting that requires the BRG = 129...

Tell me the crystal you are using and I'll give you the correct settings.... I think at the moment we have a baud of about 2000.... windows will not see this atall....
 
Last edited:
Hi. I was using an XT oscillator (external quart clock with 4 Mhz) and I misread the number needed, but it seems to be giving now some type of problems so, I'd better use the internal one.

I rewrote the code as this:

# include <p18F4620.h>
# include <usart.h>


#pragma config XINST=OFF
#pragma config OSC=INTIO67

void main ()
{

TRISC = 0x00;
OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 103);

while (1)
{
putrsUSART ("hola");

}

}

That, I understand, according to datasheet (http://www.datasheetcatalog.org/datasheet2/d/0j1scipt8ektr10e9szi820j36cy.pdf, page 209) should work, but I guess I'm stilll missing something as it keeps on showing Ç all the time.

Thanks.
 
Last edited:
2400 baud =

OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 103);

9600 baud =

OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE &
USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 25);
 
Now it works but it's working on 2400 with the one that should be for 9600... but whatever, it works, so I can continue with this.

Thanks everyone a lot, seriously.
 
If it works at 2400 with a BRG of 25.. then your USART_BRGH_HIGH is still USART_BRGH_LOW
 
Here's a couple of useful tricks when working with serial comms that have issues;
1. Send only 1 byte at a time, and force a long delay (like 10mS) between each byte.
2. Once the single bytes are working, try adjusting the BRG value up and down until you find the values where it STOPS working. Then the best BRG value is right in the middle of the extremes.
3. It's also good practice to put 2 or 3 baud delay between bytes sent, these act like extra "stop bits" and make it easier for the receiver to re-sync (it makes the baud rate less critical).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…