I2C Slave mode?

28 Apr 2010

Hello,

I am thinking about using an MBED to communicate with a Lego Mindstorms NXT brick - ie as an "intelligent sensor".

To do this, I need to use I2C in slave mode, since the NXT only implements I2C master mode.

It doesn't look like the I2C library class supports slave mode, so I'm thinking I need to write my own I2C interrupt handlers etc.

Has anyone out there managed to use I2C slave mode on mbed yet?

Any words of wisdom you can offer (or better still, some code)?

28 Apr 2010

Check the DriverLibrary, it has all kinds of I2C communications implemented.

28 Apr 2010

Awesome, thanks Igor.

I did download the original from NXP a few days ago, but figured I'd need to use GCC or Keil offline to make use of it directly. Nice to know you've ported it already for the online compiler, since I'm not quite ready to go down the GCC route yet (only got my mbed yesterday...).

28 Apr 2010

FYI, the online compiler is the same that's used by Keil, so you can usually use the Keil version of the sources with minimal changes.

28 Apr 2010

I've implemented a SPISlave class, which is in the new version of the library which we hope to release soon. It doesn't use interrupts, but instead uses a similar poll scheme to the Ethernet class:

#include "mbed.h"

int main() {
    // p11 = mosi, p12 = miso, p13 = sclk, p14 = csel
    SPISlave slave(p11, p12, p13, p14);
    int value;

    slave.format(8, 3);
 
    // Prime tx buffer with something to shift out with first receive  
    slave.reply(0x50);

     while(1) {
        if(slave.receive()) {
            value = (slave.read() + 2) % 0x10;
            slave.reply(value);
        }
    }
}

02 Jul 2010

Hi folks!

i'm a mbed newbie, and i would like to manage the i2c slave mode.

I read about DeviceLibrary.zip and Kneil compiler, however I would like to have a guide for use this libraries. That's possible??? Do you know someone? How did you solve your problem, Andrew?

 

Thanks in advance

02 Jul 2010

I have a prototype of I2C Slave for the mbed library, but I haven't got it fully tested yet. I hope it will appear in the library not too far in the future, but I cannot say when.

05 Jul 2010

Firstly, thanks Jon for your answer!

Could I help you testing your i2c slave mode librarie?

08 Jul 2010

Version 24 of the library has been released, which has the I2C slave mode in it. Any problems, do not hesitate to raise them in the bugs & suggestions forum!