UART with PIC18F458 problems

Discussion in 'Embedded Systems and Microcontrollers' started by Sharpiedeluxe, Feb 19, 2012.

  1. Sharpiedeluxe

    Thread Starter New Member

    Apr 1, 2010
    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.

    Code ( (Unknown Language)):
    2. /*
    3. Code Support     : Board ET-USBPIC/4550
    4. Compiler         : PIC C Compiler Version 3.249
    5. Micro Controller : PIC18F4550
    6. OSC              : 48MHz
    7. */    
    9. #include <18F4550.h>
    11. #use delay(clock=48000000)
    13. #define TX1   PIN_C6
    14. #define RX1   PIN_C7
    16. #use rs232(baud = 9600, xmit = TX1, rcv = RX1)
    19. #use fast_io(C)
    22. void main() {
    24.   char Dat;
    26.       set_tris_c(0B10000000);
    29.    While (1)
    30.    {
    31.      delay_ms(2);
    32.      putc('B');
    33.      delay_ms(2);
    34.      putc('A');
    35.    }
    36. }

    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:

    Code ( (Unknown Language)):
    1. ¿ñ×ö¿¿ñ×ö¿¿ñ×ö¿¿ñ×ö
    If anyone can help, that'd be great.
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.
  3. Sharpiedeluxe

    Thread Starter New Member

    Apr 1, 2010
    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.
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    Do you have a max232 on hand? If so what happens when you wire direct through the max232?
  5. Sharpiedeluxe

    Thread Starter New Member

    Apr 1, 2010
    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 :

    And I'm using this dev board:

    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: Feb 19, 2012
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.