(pic18f4550) Uart sends jibberish to realterm. (C18)

Status
Not open for further replies.

jokke009

New Member
Hello everybody.

I'm trying to get my Pic18f4550 to send a simple 'hello' to realterm through the uart. I receive data, sometimes it looks like a 'hello', but sometimes also hnllo... hxxxx lwwlo ....
**broken link removed**

As you can see I've got realterm at 2400bps. My pic should be setup this way aswell. Right?
Code:
#include <p18f4550.h>
#include <stdio.h>
#include <delays.h>
#include <spi.h>
#include <usart.h>

/* 4550's settings */
#pragma config WDT = OFF
#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
#pragma config MCLRE = OFF
#pragma config LVP = OFF

void setup(void)
{
	/* Port Set Up*/
	ADCON1 = 0b00001111; //set all pins to digital mode
	TRISD = 0;
	TRISA = 0;
	TRISB = 0b00000011; //set RB0 and RB1 as input for SPI communication
	TRISC = 0b10000000; // RX is an input, TX is output
	
	/* Interrupt Setup */
	INTCON = 0x00; /* Clear Registers */
	PIR1 = 0x00;
	PIE1 = 0x00;
	TMR1L = 0x00;
	TMR1H = 0x00;
	T1CON = 0x00;
	RCON = 0x00; 

             /* RS232 Enable */
	//RCSTA = 0b10000000;
	//TXSTA = 0b00100000;
	//BAUDCON = 0b00000000;		
	//SPBRG = 51; //FOSC = 8.000 MHz,SYNC = 0, BRGH = 0, BRG16 = 0
	OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);



	/* Clock Setup*/ 
	OSCCON = 0b01110110; //select 8 MHz clock

void main()
{
	setup();	
	while (1)
	{
		putrsUSART("Hello");
		while(BusyUSART());
		Delay1KTCYx(1000);
		//refresh(red_byte_array,green_byte_array,blue_byte_array);
	}
}

It seems like there is some synchronization problem. Is it okay to use the internal clock ? Any help would be greatly appreciated.
 
Internal clock should be fine for 2400 baud, it's absolutely fine at 9600 baud.

Do you have an MAX232 (or similar) between the PIC and PC?.
 
Yes, I have one of those max232 adapters connected between PC and uart.

Could it be the internal clock at 8MHz that's faulty ?
 
Yes, I have one of those max232 adapters connected between PC and uart.

Could it be the internal clock at 8MHz that's faulty ?

It seems unlikely? - I would double check the USART settings, and perhaps try altering the timing setting and see if it helps.
 
Try inverting the bits. If still bad set the realterm to show bytes (hex) i think you can . I forgot. Ill look into code more
 
Also try this for OSC Setup:
Code:
        OSCCON = 0b01110010; //select 8 MHz clock (0x72)
	while(!OSCCONbits.IOFS); //wait for OSC to stabilize
 
Last edited:
My guess would be that you have not connected the uart ground to your signal ground.. or the ground connection is unreliable.
 
Nope he has it set wrong for what he is receiving Realterm has so many setting it wold that a week to learn how to use it. You can have the ground off but most times it will not write
try this
 

Attachments

  • first.JPG
    59.5 KB · Views: 303
  • first1.JPG
    50.7 KB · Views: 269
Last edited:
Set the pic to use two stop bits and it will sync up better.

Edit, and you definitely need the ground connecting. If it works without then it's connected via your Pickit2 or some other way.

Mike.
 
Last edited:
Problem Solved

Thanks for all your suggestions. I'm going to suspect it was a grounding problem because i plugged the same setup in the olimex pic-pin40 board, eventhough i fully grounded my breadboard setup, the max232, both pic vss pins..

Now let's see how high we can get the baudrate !
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…