Shop OBEX P1 Docs P2 Docs Learn Events
SX to SX serial problem — Parallax Forums

SX to SX serial problem

lboucherlboucher Posts: 139
edited 2009-03-17 21:53 in General Discussion
Hi All

So i have pieced together a 17 channel light controller using the SX28.
I am using the Renard protocol version 1.

Everything is generally working great.
I have built 2 boards each of which can control the lights perfectly fine by themselves.

I run into issues when i try to run them both together.
So my laptop connects to the first sx board with 17 light channels, then from the first sx board serially to the second sx board with another 17 channels.
The first board controls its 17 channels perfect, the second board generally does great but every 10 30 seconds I randomly get bright flashes on random channels.

What is the proper way to hook up serial between two SX boards?
I just have the RA.1 pin on the first board hooked directly to the RA.2 pin on the second board.
Both boards have the same ground.
Each board has its own +5 V regulator.

Serial settings are 38400 baud, 8 data bits, no parity, 1 stop bit.

Attached is the code, its not optimized "yet" but it works and i can read it.

Anyone know if i am doing someting wrong?

Comments

  • lboucherlboucher Posts: 139
    edited 2009-03-15 03:59
    Update:

    1 of the boards is a homemade board, and the other is the SX tech board.

    So playing around some more, i realized I only have the problem if the SX Tech board is the first in the series.
    If i hook my laptop directly to my homemade board, then have it relay the serial to the SX on the Tech board everything works perfect.

    Any ideas??
    Maybe the SX is getting reset for some reason?, will test for that soon.
    (Actually looking at it, i don't think this is it, because not all channels flash high at the same time, if it were a reset i would expect it to affect all pins equally.)

    One other thing, not that i think it matters, but i do have each 5+V regulator powered by different AC-DC power supplies. The sx tech board 5V regulator is being supplied dam near 5 volts. My homemade boards 5 V regulator is being supplied about 18 volts. Again grounds are common.
    (Thinking about it, i am probably not providing enough voltage to the SX tech board, but it works fine until i hook up the second board, i am thinking its unlikely to be the problem·but who knows.)

    Post Edited (lboucher) : 3/15/2009 4:42:46 AM GMT
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-15 06:15
    I hadn't used the Renard protocol before so I looked it up:
    -- computerchristmas.com/ForumBoard/download.php?f=2&file=renard_protocol.txt

    [noparse][[/noparse]Edit] Program removed -- wasn't implementing protocol correctly

    Post Edited (JonnyMac) : 3/15/2009 4:18:47 PM GMT
  • lboucherlboucher Posts: 139
    edited 2009-03-15 14:20
    I think in version 1 of the protocol, the output pluging simple changes a 126,127,128 value to 129, or something like that.
    Basicly version 1 doesn't do two byte values.

    I am pretty sure of this, because if this was my problem i would see it all the time, with just one board hooked up.
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-15 16:15
    I can't find any reference to a "version 1" of the protocol but the information I found this morning causes me to believe that I didn't implement the protocol properly -- that will teach me for staying up and writing code so late. The information I found seems to suggest that the protocol is based on eight channels; can your master controller (Vixen on a PC?) be set to transmit variable packets? The protocol seems to be:

    <sync><address1><value1>....<value8> <sync><address0><value1>....<value8>

    I'm going to pull down my program until I can spend more time -- right now I've got a trade show looming and don't have much time to play; when I do I'll get out my dimmer board and see if I can implement the Renard protocol on it.
  • lboucherlboucher Posts: 139
    edited 2009-03-15 16:46
    UPDATE 2:

    So playing around some more, if i configure the outgoing serial from the Vixen software to use 2 stop bits, then everything works fine. This is perfectly good for me, it all works. I am just left not understanding why.

    I have tried pulling the pin high via a 2.2K & and 4.7K resistor, and also tried pulling it low with the same resistors.
    Neither worked.

    Any ideas out there?
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-15 17:23
    It may be a slight timing thing with the way you're handling the incoming bytes -- that gigantic set of IF-THEN statements takes time to process. By adding a stop bit you give the SX a little more time before the next byte arrives.

    You seem to be coming from the PC without using a MAX232-type inverter; is this true? If yes, you should insert a 22k resistor between the PC TX pin and the RX pin on your first board. Using Inverted mode (as you seem to be doing) the idle state of the serial input is low, so you could pull it down through a 10K if you want.

    Post Edited (JonnyMac) : 3/15/2009 5:46:05 PM GMT
  • lboucherlboucher Posts: 139
    edited 2009-03-15 17:29
    Yep do have the 22K resistor. Don't have the 10K, but i think i will just leave it the way it is and use 2 stop bits.
    As long as it works ehh.

    Thanks
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-15 17:45
    Would you mind trying the program I've attached to see if it works any better?
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2009-03-15 18:44
    A couple questions about your setup...

    - How are the boards connected? Are you using logic level serial or RS-232 style with something like a MAX232 driver between each board.

    - How close are the boards? Is it a very short connection between the boards or is it a longer run?

    - Are the boards using the same PS or separate ones?

    - Do you have any filter caps on the PS and small .1uf caps at each IC where the power comes into the chips?
  • lboucherlboucher Posts: 139
    edited 2009-03-15 20:12
    RobotWorkshop said...
    A couple questions about your setup...

    - How are the boards connected? Are you using logic level serial or RS-232 style with something like a MAX232 driver between each board.

    - How close are the boards? Is it a very short connection between the boards or is it a longer run?

    - Are the boards using the same PS or separate ones?

    - Do you have any filter caps on the PS and small .1uf caps at each IC where the power comes into the chips?
    From the laptop to the first SX board is RS232 to logic level with a 22 k resistor.
    From first SX board to second SX board is just logic level, no resistors.
    All have common ground.

    Boards are currently 6 inches apart, very short breadboard setup, will be longer once it gets to christmas.

    Seperate power supplies (one is 18 V·one is 5 V)·and seperate 5 volt regulators.
    All have their ground wires connected.

    One of the boards is the SX tech board, and my homemade board does have 0.1uf caps.

    All this makes sense right?
  • lboucherlboucher Posts: 139
    edited 2009-03-15 20:13
    JonnyMac said...
    Would you mind trying the program I've attached to see if it works any better?
    Sure thing, not sure if i will get to it today, but will do.
    Thanks
    Lucas

    Gave it a quick try with one board.
    Unfortunately it didn't work. Lights just came on full bore all the time.
    The only thing i changed was some channel layouts to match my current hardware setup.
    Attached is exactly what i just tested.

    For reference i only have·5 channels hooked up, RA.0, RB.0-3.
    When using vixen though, i am sending data for a full 34 channels.
    (Not that any of this matters, should still work the same.)

    Haven't looked into debugging why that didn't work.



    Post Edited (lboucher) : 3/15/2009 10:17:00 PM GMT
  • lboucherlboucher Posts: 139
    edited 2009-03-16 20:14
    Jonny Mac, did you see my edit to the post above?
  • lboucherlboucher Posts: 139
    edited 2009-03-17 21:13
    Hey, i think i got it.

    This is what happens when you use code you didn't write and don't fully understand.
    The line below in red is making the system expect 1.5 bit periods for the stop bit. (I think)
    So since I was only setting vixen to 1 bit period for the stop bit, every once in a while the most significant bit would get incorrectly set to one.
    Thus why I only get flashing and never quick dimming.

    So i think if i change this from a #6 to a #4 it will work.

    (But do i really care to take the time to test it when just setting the stop bit to 2 will work. Would up my max channel count to fix it.)

    Does anyone agree this is probably the source of the problem?

    bank #rx_count
    movb c,/rx_pin ·····'serial receive
    test rx_count
    jnz :rxbit ·····'if not, :bit
    mov w,#9 ·····'in case start, ready 9
    sc ······'if start, set rx_count
    mov rx_count,w
    mov rx_divide,#6'baud15 ····'ready 1.5 bit periods
    :rxbit djnz rx_divide,rxdone ···'8th time through?
    mov rx_divide,#4'baud
    dec rx_count ·····'last bit?
    sz ······'if not, save bit
    rr rx_byte
    snz ······'if so, set flag
    setb rx_flag
    rxdone···
  • JonnyMacJonnyMac Posts: 9,214
    edited 2009-03-17 21:53
    I don't think that's going to help. The #6 is loaded when the start bit is detected so that the next sample will be in about the middle of the first bit. After that #4 is used because you use 4x oversampling (i.e., four ISRs per bit width).

    The stop bit is really just a dead space before the next start bit -- this gives the receiver time to do something with the byte it just received. If you tell Vixen to add an extra stop bit this just means you have an extra 26 microseconds before the next byte shows up and it has nothing to do with your bit sampling.

    You may be wondering why you use #9 for the bit count -- the reason is that you need to count the start bit plus eight data bits. Once the eighth bit has arrived and rx_flag is set you have one or two bit periods (depending on the number of stop bits) to retrieve rx_byte before something else shows up.

    Post Edited (JonnyMac) : 3/17/2009 9:59:43 PM GMT
Sign In or Register to comment.