Shop OBEX P1 Docs P2 Docs Learn Events
Serial Flow control — Parallax Forums

Serial Flow control

edgellmhedgellmh Posts: 85
edited 2008-05-27 22:46 in General Discussion
I will have two serial ports and wish to poll them for incoming data. However, when I use RX_BYTE to collect a byte from one of the ports it hangs there until data arrives. How do I tell the microcontroller to move on when no data is at the port?

marshall hall edgell

Comments

  • BeanBean Posts: 8,129
    edited 2008-05-27 21:03
    Please post your code.
    RX_BYTE could be anything...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?

    www.iElectronicDesigns.com

    ·
  • edgellmhedgellmh Posts: 85
    edited 2008-05-27 21:11
    Sorry. Here is my code


    RX_BYTE:
    'USE: RX_BYTE port
    temp1 = __PARAM1 'Which port
    IF temp1 = DB9Port THEN
    SERIN RX_DB9, Baud, temp3 'incoming byte into temp3, later add code for USB
    ENDIF
    RETURN temp3

    marshall
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-05-27 21:18
    edgellmh said...
    I will have two serial ports and wish to poll them for incoming data. However, when I use RX_BYTE to collect a byte from one of the ports it hangs there until data arrives. How do I tell the microcontroller to move on when no data is at the port?

    marshall hall edgell

    If you expect the SX chip to buffer any serial data coming into it in the back ground so you can do other things then you'll probably want to look at JohnyMac's ISR based serial routines. It normally watches just one serial line but I suppose with some work you could watch two ports and have a dedicated buffer for each one. Since it keeps track of the number of items in the receive buffer you can just check that. If the count is 0 just continue on.

    I did something similar to that with just a single Serial input. It does it in the background. If anything does come in then it is processed. You can see the example code from the April 2008 issue of SERVO:

    www.servomagazine.com/downloads.php?year=2008

    Robert
  • edgellmhedgellmh Posts: 85
    edited 2008-05-27 21:31
    Robert

    When I search on the forum for JohnyMac I only get your msg. Where should I look for those routines?

    marshall
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-05-27 21:40
    I've attached a program that demonstrates buffered serial I/O with the SX20/28. If you port this code to the SX48/52 you'll need to change the BANK $00 statements to BANK $10 in the assembly sections (BTW, the version 2.0 compiler has a constant called __DEFAULT that simplifies this).

    Post Edited (JonnyMac) : 5/27/2008 9:49:12 PM GMT
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-05-27 22:46
    edgellmh said...
    Robert

    When I search on the forum for JohnyMac I only get your msg. Where should I look for those routines?

    marshall

    That was because I made a typo in the name. Sorry about that. Looks like the answer is in this thread now anyhow...

    Robert
Sign In or Register to comment.