Shop OBEX P1 Docs P2 Docs Learn Events
SX serin / serout filter at 57600 — Parallax Forums

SX serin / serout filter at 57600

VonSzarvasVonSzarvas Posts: 3,414
edited 2006-12-06 07:33 in General Discussion
Hello all,

I am trying to implement a kind of RS232 filter using an SX28.

The SX28 should listen on RA0, accept a 38 byte array (shown below), then output only bytes 14 - 21 on RA1

RA0 receives the byte array every 1 second, at 57600 baud (TTL non-inverted). Output on RA1 should be the same.

1. I have the 4mhz and 50mhz external osc's, Which should I use?
2. Does any example code exist for serin / serout at 57600?

I am happy to experiment! But I could really appreciate some pointers. I have read lots on this forum, but there are samples for 9600 baud etc.. and talk of problems with byte arrays larger than 16, so before I flounder in at 57600, I would like to see if any samples or advices at this baud rate exist!

The sample byte array:
58 32 58 01 02 20 49 02 01 93 28 42 43 1f 04 9d 25 95 00 00 81 00 00 00 1b 33 50 a3 0d 20 50 50 00 00 28 0a 0d b7

First 3 bytes are fixed header
Last 3 bytes are always 0a, 0d then a checksum.


Best regards, Max.

Comments

  • BeanBean Posts: 8,129
    edited 2006-12-04 12:08
    Max,
    Since you only need to store bytes 14-21 the 16 byte array limit shouldn't come into play.
    I would use the 50Mhz resonator for sure.

    Basically you want to do this:

    · Wait for a byte to arrive (don't store the value)
    · Receive 12 more bytes (don't store the values)
    · Receive 8 more bytes (store the values in an array)
    · Send the 8 bytes that we stored (no need to receive anymore, we don't care about the rest of the incoming data)
    · Pause to allow the incoming data stream to finish. (a couple milliseconds should do it)
    · Repeat the whole process

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin


    Post Edited (Bean (Hitt Consulting)) : 12/4/2006 12:24:20 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-04 17:42
    Terry,
    ·
    ·· I agree that there is no need to store data not used, however I would still recommend looking for the header bytes, since they’re known/fixed and waiting for the $0A, $0D before processing the output.· This would keep you from getting out of sync.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-04 21:12
    Thank you both for your comments.

    I would like to ask if you can guide me a little more. I am attaching my code file. At the moment, when I power up the SX28 and observe the data received on Hyperterminal (Windows), I get 5f 27 00, which is not what I expected from sending "A" then $62 from the code.

    The SX28 to PC connection is simply: RA.1 to DB9 pin 2 (RX), SX28 vss to DB9 pin 5 (GND)
    Protocol is 57600, 8 databits, No parity, 1 stop, No flow.

    I haven't progressed onto making the serin part work correctly yet, and first I wanted to be able to transmit/serout to the PC correctly. Hopefully by understanding the solution to the first part, I will have learnt enough to solve the 2nd part (if indeed it needs solving from what I have already!)

    But on the first part I have tried lots of different settings, and still seem to fail.

    So I would really appreciate your suggestions! No doubt it is something simple - I only started with this SX dev yesterday!

    Max.
  • BeanBean Posts: 8,129
    edited 2006-12-04 22:19
    Max,
    Your code looks pretty good, I think if you get the PC to recieve good data you'll have it made.

    Try just sending "A" once a second and get that working.
    Note that some PC's won't see 0V & 5V as serial data. You may need to use a transistor level-shift circuit or a MAX232 chip.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-05 07:19
    Thanks Bean.

    I made a slight change to the Main routine:

    FOR index = 0 to 100
    TX_BYTE "A"
    DELAY 2
    TX_BYTE $20
    DELAY 10
    NEXT

    On hyperterminal I receive 100 "5f 03" bytes

    So it seems data is coming in, just the wrong value consistently arrives!

    Can that point to the need for a max232, or should it be something else? I mean, that I would really prefer just to use the sx28, and the fact that 100 bytes are coming in consistently might suggest the voltage is not the issue here? ... or maybe it does...

    Thanks, Max
  • BeanBean Posts: 8,129
    edited 2006-12-05 14:20
    Max,
    ··Try using "N57600" for a baud rate.

    · Since you are getting the same thing every time, I would assume the PC is receiving it. Usually if it won't work you get nothing.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin


    Post Edited (Bean (Hitt Consulting)) : 12/5/2006 2:24:52 PM GMT
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-05 14:27
    Yes. Also tried lowering to T9600, although not N9600.....

    I also tried putting a 500ms delay in the transmission of just letter "A" (inside a 10 loop), and could watch the digits appear slowly as expected. (Although 5f's rather than A's!)

    I just ordered the icl232 (couldn't get the max232 here), so I will try installing that when it gets here to see if this is a problem with the pc serial port.

    From the sounds of it, everything else should work correctly. Ummhh!

    Will update in a few days. Max.
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-05 14:29
    Actually... could it be the resonator ? How do I check if it is working ?

    (I could see the circuit has OSC1 / OSC2 either side and center pin gnd, so I guessed polarity does not matter?)

    I am using the 50mhz one that came with my sx tech kit.
  • BeanBean Posts: 8,129
    edited 2006-12-05 14:58
    Do you have hyperterminal setup for 8 data bits, no parity, 1 stop bit ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-05 14:59
    Yes.
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-05 16:56
    Hey !!!

    I just tried N57600 again and its working.

    As it is Santas night here, I have to rush off and drink lots / get presents together for the children. However, will look at it carefully tomorrow and feedback on the whole project.

    Thanks for all your help.

    Max.
  • VonSzarvasVonSzarvas Posts: 3,414
    edited 2006-12-06 07:33
    Hello all,

    Now the filter is working correctly. Thanks to Bean for persisting, and Chris for your earlier support !

    I think we had 2 problems:

    1. An bug in the program: serByte = RX_BYTE was added after reading the 3 header bytes. That pushed all the other values out of sync.

    2. Maybe the SX-Key being plugged in whilst testing was interfering with the frequency, as I was using an external 50mhz resonator at the same time. This may have conflicted with the resonator on the SX-Key??? Not sure, but don't want to test it plugged in again now incase I damage it!

    These were the only changes of substance that I made before trying the N57600 again. I guess they were enough.


    Many thanks again for the help. I feel far more confident with how the SX works now and look forward to putting this and future devices into production.

    Parallax and its community make the SX well worth the effort!

    Max.
Sign In or Register to comment.