Menu

Help With RS232

Help
didis_be
2010-06-01
2013-05-30
  • didis_be

    didis_be - 2010-06-01

    Hi all,

    I'm trying to use the RS232 functionnality with a PIC16F84a ..

    My questions :

    1) it's possible to use only software RS232 routine with the PI16F84a (since it doesnt support RS232 internally)

    2) How to setup the RS232 in the hardware configurator (High / Low) ?

    3) Setting the serial initialisation is ok (I think)

    4) How to decide the pin choosen (on the PIC)  for the TX and the pin for the RX ? (16F84a)?.

    Any help, will be really appreciated.

    Best Regards,

    Didier.

     
  • Nobody/Anonymous

    Do you have a MAX232 in your circuit ? A MAX232 is a level shifter or something like that to make the PIC's +5V compatible with RS232's +12V to -12V swing.
    As extracted from Proton's help file,

    RS232 is the electrical specification for the signals that PC serial ports use. Unlike standard TTL logic, where 5 volts is a logic 1 and 0 volts is logic 0, RS232 uses -12 volts for logic 1 and +12 volts for logic 0. This specification allows communication over longer wire lengths without amplification. Most circuits that work with RS232 use a line driver / receiver (transceiver). This component does two things: -
    1. Convert the ±12 volts of RS-232 to TTL compatible 0 to 5 volt levels. 
    2. Invert the voltage levels, so that 5 volts = logic 1 and 0 volts = logic 0. 
    Because of the excellent IO capabilities of the PICmicro range of devices, and the adoption of TTL levels on most modern PC serial ports, a line driver is often unnecessary unless long distances are involved between the transmitter and the receiver. Instead a simple current limiting resistor is all that's required.
    
     
  • Nobody/Anonymous

    Sorry for the double post,
    To answer your questions,

    1) Yes software rs232 has no hardware requirements. (only remember to set your TRISA/TRISB, Input/Outputs)
    The downside is that your program jams/halts while sending/receiving data.

    2) If you are planning to use Hardware RS232, the 16F84A doesn't support it.
    No configuration is needed since it is not supported.

    3) & 4) err… I think you are the software rs232 routines that came together with GCB?
    If I am not mistaken they are still broken as of 1/6/2010.
    On the other hand, kent_twt4 has made an excellent softrs232 routine.

    You can get it here: http://sourceforge.net/projects/gcbasic/forums/forum/629990/topic/2155758
    It is under the "Contributors" section of the forum.

     
  • didis_be

    didis_be - 2010-06-01

    Hi,

    I know this .. ('about MAX232) …
    But I found a circuit  where the guy directly plug a Gps device (who work with +5v)  …
    and this, without a MAX232 apprently ..

    (here : http://www.ke4nyv.com/gpslcd.htm )

    the guy said : "I found a serial routine that did software inversion and allowed me to eliminate the MAX232"

    so, it's not possible ?

     
  • didis_be

    didis_be - 2010-06-01

    HI, ..

    Thank for your replies ..

    I will try the RS232 soft routine … if it doesn't work, I will try hard mechanism with a PIC that contains UART .. or a PIC & a MAX232 …

    But normally, the signal is very simple .. (from the GPS)
    A GPS is only sending information repetitively …

     
  • Nobody/Anonymous

    Oh for signal inversion, it worked on my PIC16F88 using internal oscillator at 1MHz with 1200 baud, code was

    #define baud 833    ;1/baud 1/1200
    #define halfbaud 412    ;place Read of SerRx in middle of bit
    [b]#define SerTxHigh Set PortB.5 Off
    #define SerTxLow Set PortB.5 On[/b]
    #define SerRx PortB.6
    
    Sub Ser_Init
        dir PortB.6 in ;Rx
        dir PortB.5 out ;Tx
    [b] SerTxLow ;Initial RS232 idle state[/b]
    End Sub
    Sub RCV_RS232
        RxWait:
    [b] IF SerRx Off then goto RCV_RS232 ;wait for start bit[/b]
        wait halfbaud us ;do half bit time delay
    [b] If SerRx Off then goto RxWait[/b]
        RxByte = 0
        For RxBit = 1 to 8 ;set up to read 8 bits
            wait baud us
            Rotate RxByte Right
    [b]     If SerRx On then Set RxByte.7 0
            If SerRx Off then Set RxByte.7 1[/b]
        Next
        wait baud us
    End Sub
    

    I think that is the difference with the original to make it inverted.
    If you use an external clock you will be able to run at much higher speeds, maybe 9600 is required for the GPS or something lower.
    I hope it works out fine.

     
  • didis_be

    didis_be - 2010-06-02

    Hi,

    I will use 16F84a since my reseller don't have 16F88 :(
    So, using 16F84a and a Max232, it  will works, no ?

    In your code, I see :  wait halfbaud us and  wait baud us 

    How did you calculate  833 for baud  and  412 for halfbaud  ?

    it' just 1000/1200 ?  (=833)
    but 500/ 1200 = 416, not 412 ?

    If I will use a quartz 4Mhz .. and want to have a speed of 4800 Baud (my Gps is working at this speed)
    4000/4800 ,I dont have to change the speed, 833 is good  also, no ?

    Thank for your help,

    Regards,

     
  • Nobody/Anonymous

    Sorry for the very late reply,
    833 was calc by 1/1200, that's 8.33e-4 = 833 us, as seen here "wait baud us"
    so if it was a 4800, it'd be 1/4800 ~208 us, these values are ±(5/10/15)?
    If 208 doesn't work, try 208-5, or 208-10 or 208+7.
    halfbaud would be 1/2 of the baud rate;
    if baud = 208 ± (5/10/15), halfbaud = 104±(2/5/7).

    I'm not too sure about specific details. Thus I cannot give an explanation. I'm guessing it's something to do with time taken to process the asm lines and that's where the ± comes in.

    If you're using the max232, just copy and paste kent's routine and change the SerTx, SerRx pins and also the baud/halfbaud.
    It'll work normally.

    If you have a serial cable, maybe you should do it with PC-PIC so that you can monitor what's being sent.
    This is only a suggestion, if you do this you may waste more time on the project ):
    If you are doing PC-PIC, use Realterm, it worked quite well for me, because I can see my data in lots of formats.
    Instead of PIC sending an A, I'll see a '01000001' or a h'41' or a '65'.
    It can change various datatypes like Hex or the usual ascii or binary or integers.

     
  • didis_be

    didis_be - 2010-06-02

    Thank's a lot !! :)

    I will try all these stuffs tonight or tomorrow (since I have other real projet on the fire).

    See u.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.