+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Member level 1
    Points: 253, Level: 3

    Join Date
    Mar 2018
    Posts
    32
    Helped
    0 / 0
    Points
    253
    Level
    3

    Hardware for RS232 with PIC

    Hi.. The hardware such as PIC16F877A, MAX232, USB to UART cable(i.e. one end compatible with usb port in PC, and other end is DB9 connector), 8MHz crystal oscillator, 33Pf (2 no.), 10uF(4 no.), are used in my UART project. I'm connecting these in bread board. I used pickit3 to program my IC.
    1). PIC16F877A
    - 13th and 14th are connected by oscillator and osc is grounded by two 33pF capacitors.
    - 11th pin is connected to supply(+5V), 12th pin is grounded.
    - RC6(TX) pin is connected to MAX232 10th pin(Tx), likewise RC7(RX) pin is connected to MAX232 9th pin(Rx).
    2).MAX232
    - 16th pin is connected to supply(+5V), and 15th pin is grounded.
    - 10uF is connected across 16th pin and 2nd pin.
    - 1st and 3rd pins are connected by 10uF similarly 4th and 5th pins, and 6th pin is grounded.
    - DB9 connector Rx(2nd pin) is connected to 7th pin, and Tx (3rd pin) is connected to 8th pin.
    - 5th pin of DB9 connector is grounded.
    This is my setup and i'm trying to send a single character with LED indication, the code is attached below. My IC is programmed well using pickit3. I also checked the code in Proteus, it generated A in virtual terminal.
    In real time i received nothing in terminal window, i've checked the baudrate, parity, stop bits, etc... also i downloaded several codes like this and dump the hex code and checked, but i didn't get any output. Software - MPLAB X IDE.
    Please give me a solution i'm doing this project for a long time. Whether my hardware setup is correct?

  2. #2
    Super Moderator
    Points: 64,830, Level: 62
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    13,161
    Helped
    3040 / 3040
    Points
    64,830
    Level
    62

    Re: Hardware for RS232 with PIC

    Hi,

    A schematic is by far more informative than a textual description.

    Usually
    Rx <-- Tx and
    Tx --> Rx:
    Be sure your connection is correct. Please check that the output of one device goes to the input of the other device. (Read datasheets)

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisment

        
       

  3. #3
    Advanced Member level 4
    Points: 7,866, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,294
    Helped
    262 / 262
    Points
    7,866
    Level
    21

    Re: Hardware for RS232 with PIC

    hello


    MAX232 ... and 6th pin is grounded.
    No, you must insert a capacitor capacitor - on pin 6 and capacitor + to ground
    more details [B]here [/B]

    some MAX232 requier less value of capacitoe , like 1µF instead of 10µF

    today, it is more easy to use a USB/TLL cable like Prolific or other ( with FTDI device integrated).



  4. #4
    Super Moderator
    Points: 27,654, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,253
    Helped
    1045 / 1045
    Points
    27,654
    Level
    40
    Blog Entries
    5

    Re: Hardware for RS232 with PIC

    The MAX232 is outdated, being recommended the MAX233 which has fixed some issues on its predecessor, particularly when interfacing with computers having no legacy serial ports, as in the case of USB/Serial adapters. Unfortunately, both devices are not pin compatible.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisment

        
       

  5. #5
    Member level 1
    Points: 253, Level: 3

    Join Date
    Mar 2018
    Posts
    32
    Helped
    0 / 0
    Points
    253
    Level
    3

    Re: Hardware for RS232 with PIC

    Sorry for late reply...
    By using proper capacitors and baudrate value, i got a result along with more continues reception of garbage values. I find that decoupling capacitors are mandatory to reduce errors.

    I've connected 1uF across 15th and 16th pin of MAX232, and in my code i just changed my baudrate value as 51.
    Thanks all...
    Last edited by vilfred; 21st May 2018 at 05:39.



  6. #6
    Super Moderator
    Points: 27,654, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,253
    Helped
    1045 / 1045
    Points
    27,654
    Level
    40
    Blog Entries
    5

    Re: Hardware for RS232 with PIC

    The Watchdog feature is enabled on your code, but you don`t manage its counter anywhere.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  7. #7
    Member level 1
    Points: 253, Level: 3

    Join Date
    Mar 2018
    Posts
    32
    Helped
    0 / 0
    Points
    253
    Level
    3

    Re: Hardware for RS232 with PIC

    Initially i thought to put WDT(watchdog timer) in OFF state, but mistakenly i made it ON, so only i haven't use counters in software. According to my knowledge watchdog timer is used to reset the MCU if any interrupt occurs, which is based on a counter that counts down from some initial value to zero. Usually, software selects the counter's initial value and periodically restarts it. Whether it will affect the output generation?
    Thanks...



  8. #8
    Super Moderator
    Points: 27,654, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,253
    Helped
    1045 / 1045
    Points
    27,654
    Level
    40
    Blog Entries
    5

    Re: Hardware for RS232 with PIC

    According to my knowledge watchdog timer is used to reset the MCU if any interrupt occurs, which is based on a counter that counts down from some initial value to zero. Usually, software selects the counter's initial value and periodically restarts it. Whether it will affect the output generation?
    No to the above statement. When enabled, watchdog counter will count down from the value you just stored, and will reset the system when its value reaches 0; therefore you need to periodically update the value on its timer. I don`t know precisely how it works on PIC, but it is the general working process. In other words, if everithing works as expected (ie, program execution not being trapped within an endless loop), your program will prevent the system from being reset by calling watchdog updater; when running some routine which requires more time to be accomplished, you can update a larger value in watchdog counter.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisment

        
       

  9. #9
    Advanced Member level 3
    Points: 6,600, Level: 19

    Join Date
    Jan 2015
    Posts
    957
    Helped
    304 / 304
    Points
    6,600
    Level
    19

    Re: Hardware for RS232 with PIC

    We seem to have gone down a bit of a rabbit hole with the WDT but the simplest way to handle it is to turn it off. The WDT is there to restart your MCU if something has gone wrong that has caused it to (effectively) stop working. That is not your problem right now. It can be added back in at a later stage if required. (BTW you need to execute the CLRWDT instruction before the WDT times out; typically you put this in the main loop.)
    As for the 'garbage characters' being sent, the usual cause for that is selecting the wrong BAUD rate. Use a scope and just continuously send a character such as 0x55 and measure the pulse widths.
    Susan


    1 members found this post helpful.

--[[ ]]--