0
\$\begingroup\$

I was just trying to send continuous stream of letter 'G' from my PIC MCU (PIC18F452) to my laptop.

Here is my assembly code that i am using :

#include <p18f452.inc>

    CONFIG  OSC=XT,WDT=OFF,PWRT=OFF
    ORG     0H
    MOVLW   D'12'
    MOVWF   SPBRG
    MOVLW   B'00100000'
    MOVWF   TXSTA
    BCF     TRISC,TX
    BSF     RCSTA,SPEN
    OVER    MOVLW   A'G'
    S1      BTFSS   PIR1,TXIF
    BRA     S1
    MOVWF   TXREG
    BRA     OVER
    END

I design the circuit in proteus and simulate it with realterm and hyperterminal i get the desired output. But when i try to implement the hardware i face some problem. I do not get output at Realterm just when i connect my source. But at the instant i remove the source (unplug just ground or live wire) i get the output (G string). Can any one tell me what is the problem? Devices that i use: 01. PIC18F452 02. 8MHz Crystal Oscillator, 03. MAX232 with five 10uF capacitor 04. USB to RS232 cable. Here is my connection diagram: PIC MCU serial communication

\$\endgroup\$
  • \$\begingroup\$ Funny how you only show us the software when the problem manifests itself in the hardware... \$\endgroup\$ – Ignacio Vazquez-Abrams Jun 15 '15 at 5:22
  • \$\begingroup\$ sorry, i thought the problem statement was suffice. :) \$\endgroup\$ – Sabbir Ahmed Jun 15 '15 at 5:34
1
\$\begingroup\$

If the PIC is a 3.3V one you might find the MAX232 is borderline working with the levels on its TX pin. You might need to use the 3V version of the MAX232.

Otherwise you need to put a digital oscilloscope on pin3 of your P1 and check if you have your data there, if yes measure the width of a bit and make sure the baud rate is what you are expecting. (1 divided by width of one bit in seconds will give you close to the actual baud rate).

If no data, then check on pin 25 of U1 and see if you have data there. If not there might be a software bug.

\$\endgroup\$
  • \$\begingroup\$ I guess there is baud rate issue. i lower the baudrate to 2400 now it works. The strange thing is in the datasheet there is no value mentioned for external 8MHz oscillator for asynchronous transmission. I calculated the formula they provide but it didn't work. But now for 4MHz 2400 baud rate it works. \$\endgroup\$ – Sabbir Ahmed Jun 15 '15 at 7:12
1
\$\begingroup\$

I think your problem was in the configuration, if you are using xtal that frequency higher than 4MHz, you'll need to use OSC=HS instead of OSC=XT

\$\endgroup\$
0
\$\begingroup\$

If it works on some baud rates and not others sometimes it can be due to using a clock frequency that is too low for the baud rates that don't work. Try a much higher clock.

The baud rate generator (BRG) usually gets its baud rate by dividing the system clock by the binary number you have loaded into it. If its a 16 bit BRG you can divide the clock by numbers loaded in up to 65536 to get a baud rate.

If the clock speed is low and the baud rate is high sometimes the baud rate generator doesn't have enough time division resolution to get the baud rate close enough to what it should be.

ie. as a silly example to explain the idea, depending on MPU type, if you had an 1MHz clock and only a 2 bit baud rate generator the baud rates available would be 1MHz/1, 1MHz/2 and 1MHz/4. None of the results would be a "standard" baud rate.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.