HSEROUT question


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    59

    Default HSEROUT question

    I have a current board and am using the HSEROUT command. The settings are:
    DEFINE HSER_RCSTA 90h ' Serial Input Enabled
    DEFINE HSER_TXSTA 24h ' Serial Output Enabled (High Speed)
    DEFINE HSER_BAUD 9600 ' Serial Baud Rate (9600 BPS)
    and the output commands are
    HSEROUT [dec2 RID, " "] ' Decimal 2 Characters, Space
    HSEROUT [dec2 RUD, " "] ' Decimal 2 Characters, Space

    Now I want to output do a different device that operates at 2400 buad and follows the the following protocol: Cntrl-A "p" "+" "01" Cntrl-C
    I have hooked the new device to my computer and via hyperterminal I can send this and it receives and performs its function. Now I'm tying to get my board to do the same. So I changed the settings to:
    DEFINE HSER_RCSTA 90h ' Serial Input Enabled
    DEFINE HSER_TXSTA 24h ' Serial Output Enabled (High Speed)
    DEFINE HSER_BAUD 2400 ' Serial Baud Rate (2400 BPS)
    and I tried several outputs including:
    HSEROUT [1] ' Decimal character 1 for SOH "Cntrl-a"
    HSEROUT ["p"] ' ASCII letter p
    HSEROUT ["+"] ' ASCII character +
    HSEROUT ["01"] ' ASCII number "01"
    HSEROUT[3] ' Decimal character 3 for EOH "Cntrl-c"


    I'm trying to hard code what I can type into my keyboard and output the same thing from my board and am missing something.

    Please help me out.
    Thank you,
    Hylan

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT question

    You will need a digital to RS232 translator as MAX232. Check also if your device is a DCE or a DTE, this matter for Rx & Tx connections.

    Cheers

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT question

    My current board has a USB output on it controlled by an FTDI FT232RL contoller and outputs fine to a compter. So now I'm using a usb to db9 serial adapter to go to the new device.

    It sounds like I have a setting issue, but also is my code correct?

    Thank you,
    Hylan

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT question

    It sounds like I have a setting issue, but also is my code correct?
    Yes your code will output @ 2400 bauds the string equivalent of [Cntrl-A "p" "+" "01" Cntrl-C], but you should tell the frequency of your clock to check it completely.

    Assuming your clock to be 4 MHz then the setting should be:

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0,17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically


    Now if your board Tx & Rx fine with your PC and your device as well then you will need a crossed cable to communicate from board to device. Check the RS232 cable you are using to communicate from your PC to the Device and see if pin 2 (DB9) correspond to pin 2 on the other side and if pin 3 correspond to pin 3. In this case your device is wired as a DCE and you are using correctly a straight cable since your PC is a DTE. In this case also your bord is a DCE so to communicate between two DCEs you will need to cross the Pin2 with Pin 3 (DB9) on one side, so that Rx ----> Tx & Tx ----> Rx Ground -----> Ground.

    You should then have the serial communication you desire.

    Cheers

    Al.
    Last edited by aratti; - 22nd February 2011 at 17:03.
    All progress began with an idea

  5. #5
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT question

    Al,
    I think the cable connection is probably my problem as you mentioned, going from device to device without the computer. I'm in India at the moment and due to some strikes and other stuff going on, I'm limited to be able to get a actual cable. So I took regular USB cable, cut it open and then crossed the green and white wires (D+ and D-) and left the red and black alone. I then plugged this into the usb to serial cable and I still didn't get anything.
    I then put the white and green back just to make sure it still worked normally when hooking the device to the computer and it did.
    So did I miss something? Logically this made complete sense when you mentioned it and I was dissappointed when it did't work. I've also got some questions in to the tech support group for the other device to see what their take on this is.
    Thank you,
    Hylan
    Last edited by Hylan; - 24th February 2011 at 04:21.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT question

    Hylan, I am a little lost! Let 's do step by step an analysis of your system.

    1) Very likely your PC (laptop) has no serial port so you are using an USB to serial converter.

    2) Your different device that operates at 2400 bauds is a RS232 serial device, which means that you will connect it to the PC via a serial cable. This serial cable should have two DB9 connectors, one to be inserted into the corresponding DB9 on your device and the other into the DB9 (male) of your USB/RS232 converter.

    3) Your PIC board MUST have a RS232 connection since you are using the HSEROUT command, so I assume also this board has a DB9 connector.

    It is possible that you plug the USB/RS232 converter directly (via DB9M to DB9F) to your boards, so you are not using a serial cable.

    Now you need to made a serial cable for connecting your pic board to device that operates at 2400 bauds. This is not very difficult. You have to obtain two DB9 connectors that plug respectively into the pic board and into the 2400 bauds device board (these two boards should have a female conectors, if so you will need a males couple. But you do better check)

    Once you have the correct DB9 connectors you should wire them in this way :

    DB9 (pic device) DB9 (2400 bauds device)
    --------------------------------------------------------
    Pin 2 ----------------------> Pin 3
    Pin 3 ----------------------> Pin 2
    Pin 5 ----------------------> Pin 5
    ---------------------------------------------------------

    Make the cable long as you desire, but not longer than 2 meters, plug this cable into the two devices, power up both devices and run your code, 2400 bauds device should receive the serial string you have coded.

    Please note that a RS232 serial cable is not an USB cable.

    Good luck

    Al.
    Last edited by aratti; - 24th February 2011 at 05:15.
    All progress began with an idea

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts