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.

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.
 
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. :)
 
Status
Not open for further replies.

Latest threads

Back
Top