Shop OBEX P1 Docs P2 Docs Learn Events
Non-Polarized Serial Data — Parallax Forums

Non-Polarized Serial Data

LightfootLightfoot Posts: 228
edited 2007-07-13 15:09 in General Discussion
I have two lines of code that work but rejects the first serial transmission if the data is inverted. What is the best way for a SERIN statement to read data that is either inverted or not inverted?

SERIN RA.0, T2400, rb
SERIN RA.0, N2400, rb

Thanks?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-11 15:55
    I think it would help if you tell us a little more about what you are trying to do. I am having a hard time thinking of an application where you would not know what type of serial data was about to be sent.

    In general, I think you should be able to look at the idle state of the serial line and determine from that whether to expect true serial or inverted serial.

    - Sparks
  • LightfootLightfoot Posts: 228
    edited 2007-07-11 18:46
    The application should except both inverted serial and true serial. The transmission device in the project i am working on is capable of sending both and the receiver needs to accept both.

    thx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-07-11 19:19
    That's interesting. To Sparks' point, you'd have to check the line idle state -- in SX/B you could do this:

    FUNC RX_BYTE
      IF RX = 1 THEN
        SERIN RX, T9600, tmpB1
      ELSE
        SERIN RX, N9600, tmpB1
      ENDIF
      RETURN tmpB1
      ENDFUNC
    
  • LightfootLightfoot Posts: 228
    edited 2007-07-11 19:37
    Thanks, i'll give this a try.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-07-11 19:40
    Lightfoot,

    Assuming that the incoming data consists of long idle periods, detecting the idle state, as shown here, will work. But, in general, the requirement being imposed on you by the transmission device makes absolutely no sense. You really need to know ahead of time what kind of data you're receiving. But, absent any cues, like long idle periods, there's no way to know; and if you guess wrong, you'll end up receiving garbage.

    Plus, I'm not even sure what you mean when you say that the transmitting device can send both types of data. Does this mean that it can change it's mind at any point in time and begin sending data of the opposite polarity? If so, an idle marking state will, all of a sudden, become either a bogus start bit, or the beginning of a long BREAK. If not, why can't you know ahead of time which polarity is being used?

    I have to admit: I'm stumped by what seems to be a rather capriciously-inspired design requirement. I hope, for the sake of your project's success, that you can convince the designers of the transmitting device to make up their minds one way or the other.

    -Phil
  • LightfootLightfoot Posts: 228
    edited 2007-07-11 20:32
    Thanks, I got it to work. I agree with phil that that the designers should have told me to use one or the other. I guess they feel they can make a cheaper circuit that way but no!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-07-11 20:41
    I'm stumped, too, Phil -- and would love to know why the designers made the decision to support true and inverted transmissions. And Lightfoot, I think it actually costs more to support both; if not in hardware then in the code to generate the serial data.
  • LightfootLightfoot Posts: 228
    edited 2007-07-12 18:59
    Can serin receive a word value?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-12 19:20
    Not to my knowledge but...

    You can call it twice (be sure to place it inside a function if you do) and assign the return value of each instance to either the MSB or LSB of a previously defined Word variable. Thereafter you can treat the result just like any other Word variable!

    - Sparks


    P.S. If you wait a little while JonnyMac or Bean will probably come along and post the exact code to do this! smilewinkgrin.gif
  • LightfootLightfoot Posts: 228
    edited 2007-07-12 19:35
    I found a way to test to see if it does. How do you split a word into two bytes and make one equal to the rb registar and the other equal to the rc register?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-07-12 19:43
    'RBC' is the reserved word used to address both the RB and RC registers together.

    Something like “RBC = WordVariable” should accomplish what you have asked.




    - Sparks
  • LightfootLightfoot Posts: 228
    edited 2007-07-12 19:47
    cool

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • JonnyMacJonnyMac Posts: 8,943
    edited 2007-07-13 15:09
    SERIN only works with bytes; to receive a word you must receive it as two separate bytes -- and you'll want to make sure you know the order they're being sent. Many systems use "little Endian" which is to say that a word is transmitted low byte, then high byte.
Sign In or Register to comment.