LockedEcho using USART on 16F88

Author
Guest
Super Member
  • Total Posts : 80499
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2004/02/04 09:38:57 (permalink)
0

Echo using USART on 16F88

All,

I am experiencing a problem that sounds all too familiar: I am echoing a character send from a PC back to the PC using the PIC's UART. Obviously it is only a starting point, but it's not working. I'm using the 16F88.

It does echo something back, but I can't decipher how it relates to the incoming data. It appears like an offset in the binary code or something, and it consistently sends back the same results. An example send/receive pattern is shown below:

Send, Receive as number, Receive as ASCII
1 64 76
2 96 102
3 32 38
4 112 115
5 65 77

The code I'm using is below; I don't want to inundate the board with the same basic question, but I'd appreciate any help.

Regards,
MJ

include "p16F88.inc"
;__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_OFF

org 0

Main ; Start of the main program
call init ; Port initialization subroutine

Loop
btfss pir1, rcif
goto Loop
movf rcreg, w
call txchar
goto Loop

init
bsf STATUS,RP0
bcf STATUS,RP1 ; data page 1
bcf TXSTA,SYNC ; asynchronous mode (TXSTA in 1)
bsf TXSTA,BRGH ; high speed (TXSTA in 1)
bcf TXSTA,TX9 ; only 8 bits (TXSTA in 1)
bsf TXSTA,TXEN ; enable transmitter (TXSTA in 1)
movlw 0x0c ; Variable for baud rate = 19.2 kbps
movwf SPBRG ; set baud rate generator (SPBRG in 1)
bsf TRISB,4 ; Make RB2/TX data an output (TRISB in 1)
bsf TRISB,2 ; Make sure RB1/RX is an input (TRISB in 1)
bcf STATUS,RP0 ; data page 0
bsf RCSTA,SPEN ; enable serial port (RCSTA in 0)
bsf RCSTA,CREN ; Continuous receive (RCSTA in 0)
return

txchar
btfss PIR1,TXIF ; see if buffer register is empty
goto txchar ; wait until it is
movwf TXREG ; load character to transmit buffer regsister
return

end ; End the program
#1

7 Replies Related Threads

    Ken_Pergola
    Super Member
    • Total Posts : 2065
    • Reward points : 0
    • Joined: 2003/11/07 12:48:48
    • Status: offline
    RE: Echo using USART on 16F88 2004/02/04 11:01:27 (permalink)
    0
    ORIGINAL: mjllc

    ...It does echo something back...



    Hi Jeffrey,

    a few questions for you:

    1) You are using 4 MHz for Fosc, correct?

    2) Are you using an RS-232 level translator between your PIC and your PC?
    (i.e., MAX232, MAX233)

    3) Do you have a ground wire connected between your PIC project's ground and the PC's serial port ground pin?

    4) Have you verifed your baud rate on the PC side -- is it 19,200 bps?


    If you could answer these questions we might be able to zero in on the problem.


    Best regards,

    Ken Pergola
    #2
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Echo using USART on 16F88 2004/02/04 12:13:11 (permalink)
    0
    Ken,

    Thank you for your help.

    * Yes, I am using a 4 MHz oscillator
    * No, I am not using a level shifter such as the MAX232--However, I have been able to communicate with a 16F627's USART (Hardware implementation) and 16F819 (Software implementation) without using it. It could be that the F88's output is different enough from those that the results are different.
    * Yes, I have the serial ground connected to the same PIC ground
    * Yes, I can confirm that the serial port is reading at 19.2 kbps (as far as one can confirm it; I have set it up to read at that rate using the RealTerm software).

    The circuit delivers that same response even after restarting everything; so it is consistent. Thank you in advance for your help.

    Regards,
    Jeff
    #3
    Ken_Pergola
    Super Member
    • Total Posts : 2065
    • Reward points : 0
    • Joined: 2003/11/07 12:48:48
    • Status: offline
    RE: Echo using USART on 16F88 2004/02/04 13:05:52 (permalink)
    0
    ORIGINAL: mjllc

    * No, I am not using a level shifter such as the MAX232--However, I have been able to communicate with a 16F627's USART (Hardware implementation) and 16F819 (Software implementation) without using it. It could be that the F88's output is different enough from those that the results are different.


    Hi Jeff,

    I would use a MAX232 or equivalent -- let us know if it works ok or not after that.

    Best regards,

    Ken Pergola
    #4
    ric
    Super Member
    • Total Posts : 22098
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: Echo using USART on 16F88 2004/02/04 14:32:28 (permalink)
    0
    You must use a level shifter chip, because it also inverts the signal.
    I can imagine you might get away with a software UART which allows for this, but a hardware USART would be totally confused by the inverted data!

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Echo using USART on 16F88 2004/02/04 20:59:36 (permalink)
    0
    All,

    I will try using a level shifter; I was confused because I had had good results without one for some reason, but I understood that one was needed. Thank you all for your input.
    #6
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Echo using USART on 16F88 2004/02/25 21:23:44 (permalink)
    0
    That's what it was--it works. After adding the level shifter (max232n) I get the correct results. Thanks for all the help.
    #7
    ric
    Super Member
    • Total Posts : 22098
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    RE: Echo using USART on 16F88 2004/02/25 21:55:32 (permalink)
    0
    Thanks for letting us know you got it sorted out :)

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    Jump to:
    © 2017 APG vNext Commercial Version 4.5