Author Topic: SBC56EC I2C GPIO Expander  (Read 9509 times)

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
SBC56EC I2C GPIO Expander
« on: May 24, 2012, 04:14:32 PM »
Hey,
I am working on a project to control a large array of relays using PCA9506 I2C GPIO chips and ULN2803 Darlington Transistor Arrays.

To send the I2C commands, I updated the software on my SBC to 3.11 which has a UDP to I2C routine setup in the Buses firmware file.  In theory, when I send it http://10.1.0.1/?S4088FFP, the S4088FFP gets sent to the I2C bus as a start command followed by three bytes of data (40, 88, FF IC Specific commands for GPIO) and a stop command.

Unfortunately, when I send the command, nothing happens to my relays.  I tried to monitor the output of RC3(clock) and RC4(data) for the I2C bus and I got the result in the image attached when no command is sent over UDP.  Signal 1 is the data line and signal 2 is the clock.

When I try to send data over UDP to the I2C bus, the O-Scope screen flickers and the same signal remains as if it were in steady state.

My PCB is a simple backplane style system with 8 GPIO chips setup to drive the relays and provide positive feedback on relay closures.  The I2C bus has Pull Up resistors on the data and clock lines (value 10k).  The trace lines on the PCB are at longest 45cm but I am not seeing much noise and the drop off on the signals shown on the O-Scope seem fine, so I don't think there is anything wrong with my PCB.

Is there something I need to do in the code to get this to work fully or is there something wrong in my design?

Thanks

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #1 on: May 24, 2012, 09:34:53 PM »
Is that image from the scope when you send the udp packet?  Or when you send nothing?  Please clarify.

That image definitely looks like typical i2c but it's such a tiny amount of data.

That image only shows one byte.  Maybe you need to zoom out a bit more.  it looks like a start then binary 010100001 then an end.  I didn't look at the I2C documentation recently so to be sure I'd have to look at a doc first.  Typically the first 4 bits or so are an address to the chip it is controlling: 0101.  Or device 5.  But then only having 5 more bits is pretty lame.  It's probably a setup for a read or write command or something.  It's simply much too little to do much of anything.  You should see 10 or 20X this much going on.

I think you need to zoom out a bit with your scope.  There's probably 20 more of these little i2c blasts a few milliseconds later.

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #2 on: May 25, 2012, 08:30:26 AM »
So the scope image attached is when nothing is connected to the SBC65EC except the o-scope probes (ie. no pull up resistors or GPIO chips) and Nothing has been sent over UDP

The image in my previous post is the same thing with a larger ms/div.

In both cases, as far as I can tell, the signal repeats every 40ms (second image attached).  I tried to zoom in on one of the second packets but my scope wouldn't let me see it in too much detail but it looked to be the same.  Could it be some sort of idle signal?

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #3 on: May 25, 2012, 09:17:00 AM »
Bummer.  Yes, I forget what else the i2c bus connects to but clearly it is being updated in a loop.

Your multibyte data is going to be very hard to capture among all those 1 byte signals but I have 2 ideas:

1) If you are comfortable editing the mxwebsvr code you could find what is sending signals to i2c and comment this out so that your data will stand out.
2) Otherwise I would send 2 udp packets very very quickly in a row (<40ms).  In the first one toggle some unused io pin.  Use that iopin to trigger your scope to start capturing.  In the second udp packet do your i2c code.  This way you can find your multibyte data in among those single byte i2c commands that you need to ignore.  Start off with the scope zoomed way out (maybe capture a whole second).  The multibyte packet should stand out.


FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #4 on: May 29, 2012, 12:13:44 PM »
Hey,
Thanks for the suggestions.  I have been trying to capture an image of the multibyte packet which I think is being sent over the I2C bus using the trigger setup you suggested but I can't seem to get my scope to trigger on a rising or falling edge.  The external trigger function doesn't seem to do anything either.

I was hoping you might know what piece of code in the mxwebsvr code caused the repeated signals on the I2C bus so I could comment it out.  I have been looking through the code, but I'm not particularly adept at software.  This might allow me to trigger my scope on just the I2C data bus allowing me to see what is happening.

Alternatively, if anyone knows if the OWON PDS 5022S has some weird trigger setup that I need to do to get it to trigger off of channel 2 which is hooked to an output, let me know

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #5 on: May 30, 2012, 09:58:33 AM »
Yikes.  Well looking at the schematic I see I2C is used for the eeprom.  This I beleive contains things like the web pages so any access to a web page would generate thousands of I2C packets.  I think.  Maybe you could test that - refresh one of the boards web pages with browser refresh (F5 key in most browsers) and see if you get a huge spike in I2C traffic.  But UDP should be safe I think.

Anyway I didn't see anything obvious except maybe this one thing which I don't understand.  Commenting it out might break the ability to use I2C and hence break the ability to read web pages but it looks kind of useless and runs in the main loop which I thought was about 1ms but if you say 40ms I suppose that's possible.  In mxwebsrvr.c:


        //I2C Task
        i2cTask();

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #6 on: May 30, 2012, 03:57:33 PM »
Hey,
I'll check out if removing the i2cTask(); section of code does anything adverse and post my results later.

Also, I was wondering if it could have something to do with the LCD and as you said, the I2C is being used for EEPROM.  Could either of these be causing a repetative signal over I2C?  I am looking through the LCD code for something like that.

And just to be sure, it seems like only code referenced in the mxwebsrvr.c file will be run, correct?  Or are there some other main sections of code that could cause other .c files to execute?

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #7 on: May 30, 2012, 04:05:19 PM »
Hey,
I just found something right after I put my last post.  There is a section of code in the lcd2s.c file starting on line 124, the "void lcdService(void) {" section of code has a section that executes every 40ms that requests a status byte from the lcd (assuming i'm reading the comments correctly).

If I remove this section of code from the mxwebsrvr.c file: (line 365-366)
        //Service LCD display
        lcdService();
Do you suppose anything adverse would happen?  I will check up on this and report back.
« Last Edit: May 30, 2012, 04:07:37 PM by FrozenMel »

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #8 on: May 30, 2012, 04:37:18 PM »
There you go!  That's almost certainly it.  I don't have an LCD so I don't know anything about it.

That line: lcdService() and also i2cTask() and many other function calls are all in the "main" loop of mxWebsrvr.c.  If you scroll up you see a while(1).  All the code I've written for my board pretty much goes in that loop somewhere.

I recommend you comment out the lcdService() line and leave i2cTask alone.  See if that helps you get a good trace on you oscilloscope.

Did you do the experiment of refreshing a web page to see if you get tons of i2c signals?


FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #9 on: May 31, 2012, 10:08:42 AM »
Hey,
So the lcd2s.c code seems to be with all the default code for the sbc65ec boards.  Mine doesn't have an lcd screen on it but it still has the code, presumably to support it if I ever decide to attach one.

I did do the experiment of refreshing my webpage (http://mxboard/) and there was a large group of signals on the i2c bus.  This could be what I have been seeing when I thought I was sending the I2C code over udp.

I also removed any reference to the lcd2s.c code from the mxwebsrvr.c code starting with the lcdService() line and eventually even the lcdInit() but the repeated signal is still there.

Is there a way to check/look at the .c files on the SBC while it is running?  this way I can be sure that the programming was successful? I am curious about this because I have upgraded the firmware to 3.11 but the system settings page still says it is 3.10.  If this is true, there is no udp to i2c code implemented yet.

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #10 on: May 31, 2012, 10:17:33 AM »
have upgraded the firmware to 3.11 but the system settings page still says it is 3.10.
That might explain your problem.

Change the LED code to blink 4X faster or 4X slower.  The line of code is near the very begining of the while(1) loop in mxwebsrvr.c.    Then see if it worked.
examples:
Code: [Select]
            if ( TickGetDiff8bit(tick_led) >= ((TICK8)TICKS_PER_SECOND / (TICK8)10) ) // toggles 10 times per second
            if ( TickGetDiff8bit(tick_led) >= ((TICK8)TICKS_PER_SECOND / (TICK8)4) ) // toggles 4 times per second
            if ( TickGetDiff8bit(tick_led) >= ((TICK8)TICKS_PER_SECOND / (TICK8)1) ) // toggles 1 times per second

Even if you are successfully making edits, you still might have the source code to the older version of software.

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #11 on: May 31, 2012, 10:34:00 AM »
Hey,
So changing the code in the mxwebsrvr.c file didn't change the frequency of the led.  Is there something I need to do with the .hex file that I use to program the SBC with the netloader?  I have been using the websrvr65_mc_hw211.hex file in the bin folder from the v3.11 software like I am supposed to (reference: http://forum.modtronix.com/index.php?topic=1179.0)

Everything seems to go fine when I try to program the board
Quote
10:24:21.486 - Trying to connect with Target..................
10:24:24.716 - Found: SBC65EC, Hardware V3.01 (PIC18F6627)
10:24:24.717 - Bootloader V1.0
10:24:24.717 - Successfully connected
10:24:27.328 - Do not close program or switch target's power off!!
10:24:27.329 - Upgrading firmware...........................
10:24:27.329 - Erasing Target...
10:24:29.638 - Target successfully erased
10:24:29.662 - Programming target FLASH from 0x800 to 0xc53e.................................................
10:24:39.896 - Programming target EEPROM from 0xf00000 to 0xf0011b
10:24:40.756 - Target successfully programmed!
10:24:40.766 - Target exited bootloader mode
10:24:40.766 - Target has been reset

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #12 on: May 31, 2012, 10:38:22 AM »
This message guarantees you that some software was successfully loaded on some board.

But was it the right board (do you have more than 1? I do.) and more importantly did you point the boatloader at the right binary file?  Is the date on the binary file recent or from weeks ago?

Try my test.  It's more definitive.

FrozenMel

  • Full Member
  • ***
  • Posts: 19
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #13 on: May 31, 2012, 10:57:05 AM »
So I only have 1 board and I did try your test with the LED and nothing happened.

The date on the binary file is from ages ago.  I assume it is when the files were zipped together and added to the forum.  Is there a way to remake/update the hex file for the code I want to update the SBC with?

gr

  • Hero Member
  • *****
  • Posts: 171
    • View Profile
Re: SBC56EC I2C GPIO Expander
« Reply #14 on: May 31, 2012, 11:30:10 AM »
Ah. so you probably aren't using the compiler or anything. lol.  I was impressed that you had gotten all that working but I guess not.  There are a few posts to learn how to install and build the source code into a hex file.

Here's some instructions for compiling the modtronix software.  I suggest you start over with a fresh copy because so many damn things can go wrong!  Then make your changes again starting with LED flash speed:

http://forum.modtronix.com/index.php?topic=1330.msg4153#msg4153