Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

No LF & CR

Status
Not open for further replies.

AtomSoft

Well-Known Member
Im trying to write a ROM string out to UART at high speed (even at low speed same results)

My Speed is 115.2kbps (using a 14.7456MHz Crystal)

NO PLL ...

Code:
rom char welcome[23] = "AtomSoftTech Hey\xD\xA";

//... Init UART
init_uart();

//...SEND ROM STRING
UartRomStr(welcome);

//... Functions
void init_uart(void){
    TRISC  = 0b10000000;
    TXSTAbits.SYNC = 0;
    BAUDCTLbits.BRG16 = 0;
    TXSTAbits.BRGH = 1;
    SPBRG = 7;        //115,200bps (115.2Kbps) for 14.7456 MHz

    RCONbits.IPEN = 1;
    IPR1bits.RCIP = 1; //PRIORITY

    TXSTAbits.TXEN = 1;  //ENABLE TX
    RCSTAbits.CREN = 1;  //ENABLE RX
    RCSTAbits.SPEN = 1;  //ENABLE SERIAL PORT and PIN Config

    //Disable All Interrupts
    PIE1 = 0; 
    PIR1   = 0;
    INTCON = 0;

    Delay10TCYx(100);
}

void UartRomStr(rom char *string){
    char temp = 0;

    while(*string)
    {
        temp = *string++;
        while(!PIR1bits.TXIF);     //wait until TXIF is high
        TXREG = temp;    //put byte into Transmit Register
    }
}

The code works as i get the message on my terminal but it does not create a Line Feed...

I tried:
\n\r --------and-------\r\n
\xA\xD --------and-------\xD\xA

ALSO TRIED:
welcome[]....

NO LUCK! You think its my terminal ? Im using Putty (0.62) (windows 7)

Thanks in advance guys (and some gals)
 
Last edited:
Ok i got it to work like:
Code:
rom char welcome[] = "AtomSoftTech Hey\r\n \0";

Has to have a space... fra.jpg

EDIT: Fixed

Code:
rom char welcome[24] = "AtomSoftTech Hey\r\n\0";
 
Last edited:
Ok switched to a 10Mhz crystal so i can use PLL... need more speed..

To my calculations:
10mhz x 4xPLL = 40 Mhz

40Mhz / 115200 = 347.2222222222222 / 16 (BRGH = 1) = 21.70138888888889 - 1 = 20.70138888888889

I rounded it up to 21 which would be: FOSC/(16 ([SPBRGH:SPBRG] + 1))

40Mhz / (16 x (21 + 1)) = 40Mhz / (16 x (22)) = 40MHz / (352) = 113636.3636363636

Which means i get a error of : ((113636.3636363636 - 115200)*100) / 115200 = -1.35%

Is that too much ? I know its way off but it seems to work. I just dont want to run into a problem later on :(
 
Hi Atom,

Theoretically, if you have a start bit, 8 data bits and a stop bit, then you can allow for around 5% frequency mismatch before you start reading the last bit wrong.

Be aware that's 5% total, so each end may have 2.5% or one end may have 5%.


My thinking goes:

The UART samples in the middle of the bit therefore you can allow your frequency to be off by half a bit before you start getting errors. In total there are 20 half-bits. 1/20 = 5%
 
Last edited:
I've found RS232 to be quite tolerant of frequency mismatches. If you do get problems then switch to two stop bits and that normally fixes it.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top