UART with PIC18F458 problems

Thread Starter

Sharpiedeluxe

Joined Apr 1, 2010
8
Hello, I'm having some issues with baudrate problems when sending serial data from my PC to my PIC using bluetooth. Any help is much appreciated.

Basically, I have a PIC dev board with the TX and RX lines tied to a bluetooth module. I can connect to the module through a USB module on my computer. Here is the example program that came with the board.

Rich (BB code):
/*
Code Support     : Board ET-USBPIC/4550
Compiler         : PIC C Compiler Version 3.249
Micro Controller : PIC18F4550
OSC              : 48MHz
*/    

#include <18F4550.h>
#fuses HSPLL,USBDIV,PLL5,CPUDIV1,VREGEN,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=48000000)

#define TX1   PIN_C6
#define RX1   PIN_C7

#use rs232(baud = 9600, xmit = TX1, rcv = RX1)


#use fast_io(C)


void main() {

  char Dat;

      set_tris_c(0B10000000);


   While (1)
   {
     delay_ms(2); 
     putc('B'); 
     delay_ms(2); 
     putc('A');
   }
}

The bluetooth module has a command interface. The default baudrate is 115200, and I set that to 9600. Using PuTTY as a terminal, I also set the serial settings to 9600. Everything is set the same: 8 bits, 1 stop bit, no parity, no flow control.

On output, instead of getting "A"'s and "B"'s, I get stuff like:

Rich (BB code):
¿ñ×ö¿¿ñ×ö¿¿ñ×ö¿¿ñ×ö
If anyone can help, that'd be great.
 

ErnieM

Joined Apr 24, 2011
8,377
That sounds like a baud rate problem giving you garbled data. The code was written for a PIC18F4550 but you say you are using a PIC18F458 and don't spec a frequency. The line:

#use delay(clock=48000000)

tells the compiler the hardware clock speed, and it needs to match.
 

Thread Starter

Sharpiedeluxe

Joined Apr 1, 2010
8
Yes, this is true. I changed to #use delay(clock=10Mhz), changed the header to be for the correct pic. changed the fuse to be HS instead of HSPLL, but am still having the same issues.

I'm working on a dev board, but they didn't give me any sample code to work with for this board. they had it for the PIC18f4550, but that's it.
 

Thread Starter

Sharpiedeluxe

Joined Apr 1, 2010
8
Do you have a max232 on hand? If so what happens when you wire direct through the max232?
I have my PIC which has the TX/RX lines correctly mapped to the max232. Thats part of the dev board. Then I wired my TX,RX lines of my bluetooth to the max232.

EDIT: Okay, since I'm a beginner I couldn't really understand this very well. But I think I'm getting closer. I'm using this bluetooth module :

http://www.sparkfun.com/products/10269

And I'm using this dev board:

http://www.futurlec.com/PIC18F458_Development_Board.shtml

On the bluetooth page I couldn't understand what they meant when they say that you cannot map the bluetooth directly to a serial port, you need a max232. However, after I took out the max232 on my dev board and shorted the connections, I was able to get the correct outputs.
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,377
Double (and triple) check the "#fuses" settings to insure the instruction rate is what you want. Same for OSCCON.

It's not such a bad idea to write a test program to exercise a pin and check it on a scope to make sure things run as fast as you think they do.
 
Top