PIC18F UART Issue

Status
Not open for further replies.

AtomSoft

Well-Known Member
All i get is gibberish... or HIGH values like 0xE0 or higher...

Im going for a 40MHz using PLL and a 10MHz OSC... Its not a hardware problem as i had this board working before using some other code... (LOST)

So am i setting this all up ok? Any Thoughts?

Im trying for 19200bps 8-N-1

Thanks Guys/Gals
Code:
#pragma config OSC = HSPLL, BOREN = OFF, WDT = OFF, MCLRE = OFF, LVP = OFF, XINST = ON

/******************************************************************************/
/* User Global Variable Declaration                                           */
/******************************************************************************/


/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/

void main(void)
{
    unsigned char var;
    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();

    /* TODO <INSERT USER APPLICATION CODE HERE> */

    while(1)
    {
        var = getChar();
    }

}

void ConfigureOscillator(void)
{
    // 40MHZ - 10MHZ * 4xPLL
    OSCCON = 0;                 //Primary OSC Selected
    while(!OSCCONbits.OSTS);    //Wait until Primary OSC is ready and running

    ADCON0 = 0;
    ADCON1 = 0x0F;
    CMCON = 0x07;
}

void InitApp(void)
{
    //Enable UART 19200,8-N-1
    RCSTAbits.SPEN = 1;
    TRISC |= 0b11000000;
    SPBRG = 129;
    TXSTA   = 0b00100100;

    BAUDCON = 0b00000000;
    RCSTA   = 0b10010000;


    PIR1 = 0;
}

unsigned char getChar(void)
{
    unsigned char rxTemp = 0;

    while(PIR1bits.RCIF == 0);
    rxTemp = RCREG;
    return rxTemp;
}
 
Last edited:
Oops sorry ... Its a PIC18F4620
It triggers fine when i send a character but just not right data, im sure it has to be either osc settings or uart settings... But i cant see the problem
 
Last edited:
It looks fine to me. Do you have a max232 fitted as that chip can work without one.

Mike.
 
Hah i think its the crystal lol, i remember doing a repair on this PCB and i guess my iron was too hot... going to replace and retry
 
Them crystals get you every time I married one she took me to the cleaners LOL

Back to this crystal osc I've cooked some myself.
 
Hi Atom, as a simple test you can send out 0x00 out the USART repeatedly with a pause between, and it will make a period of 9 LOW bauds which looks like a single LO period on the 'scope.

Assuming you have a 'scope you just probe the TX pin and can see instantly what the baudrate is as it will be the LO period divided by 9. It's a quick and reliable test that can save heaps of messing in code checking setups.
 
Ah cool Roman, and funny Burt lol

I dont have a scope but do have a logic analyzer (saleae) which should be fine, thanks again guys!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…