I2C example

Interesting! Always the same. You think something should work in theory, and then … damned real world. But… that’s the fun!

1 Like

Did some more research and I think 1-wire is the way to go. Ill try the .NET MF 4.3 bits.
I presume there’s no support in TinyCLR yet?

I’m not so hopeful I will get this done, Arduino platform has libraries to make Arduinos master or slave on the OneWire protocol. Heading there next.

I think that your main problem is the way how you want to identify the clients, independent of the way of communication. I have no idea how this could work with your premises and a bus protocol for communication. For me it seems that only if each client has two Input/Output ports through which each client can talk only to its neighbours it is possible to assign IDs to the clients in an initialization process. But such a solution would require expensive cables and other hardware. If one client fails, the more distant clients would be not reachable as well. Did you consider to use DIP Switches?

I’ve tried a bit of OneWire, and couldn’t get it to work.
I’m back at I2C, and I found that the I2C bus can be scanned for addresses attached to the bus.
It even reports the time of response, which could aid in identifying which slave is further away from the master.
This way I get the order of slaves. Only thing now is I need to assign an address to each slave.
So I was thinking of generating a GUID and saving it as a variable and assigning it as an address for I2C slave.

This way no matter how many slaves I’ve got, they have completely different unique addresses, scanner finds the ones attached and in which order. So the network is done. I just have to implement this now.

The only thing is this is all for Arduino because @Brett says that “its unusual to want to be an I2C slave device” which I find odd because the Arduino has this built-in in the IDE.

I don’t believe that you can get the “order” of the slaves from the time to respond. I would think that it is by chance which slave responds as the first. So it should be possible to assign a unique ID to each slave (at start they all have the same ID) but then you don’t know which slave has which ID. There may be applications where this doesn’t matter, but in most cases you want to know to which individual client you talk (e.g. the client in the kitchen, the garden or the livingroom).

In I2C I beleive there is always one master and one or more slaves so I would say it is more common to want to be the slave :slight_smile:

My point is that you buy an I2C chip that does what you want. That is the slave. Your controller is the master, it tells the slaves what to do. You want an LED controller? Buy an I2C one. You want a relay control? Buy an I2C module.

Ok then as per your logic, I want an I2C microcontroller that can do more then an I2C LED controller, or an I2C relay control or any other I2C module.

Almost every MCU has an I2C why shouldn’t it be set up as a slave? why do I need an external chip?

so buy an Arduino! Nobody is stopping you… But Netmf is an I2C MASTER and that is all.

More than likely the G30 processor can be run in slave, it’s just that GHI have not supported this in their current software.

That’s like saying every computer has usb so why can’t they be setup as a usb device? I2C Chips have internal circuitry that facilitate the communications. For a µC to be a slave (esp an arduino) it would have to halt processing to deal with the incoming data. Have you ever noticed that I2C slave devices tend to be simple sensors or ADCs.

That’s what happens with a UART and it doesn’t have any detrimental effect on the rest of the system unless you are dealing with real real time sensitive code.

It works well with UART on Netmf devices because of the support that has been given to that type of bus in GHI’s software.

Given the price that you pay in order to have Netmf on the chip it doesn’t seem to me to be worthwhile to use a G30 as each node if they don’t process something as complex as the main application of the Master Device.

If each Slave is only going to do something as simple as light an LED, then I think you are wise to make slaves out of cheaper devices. In my opinion Netmf is only worthwhile when you have a large application to develop. One that likely has multiple threads and handles many different kinds of communications.

Arduino is pretty expensive too but that’s just name brand BS. You can get a clone for way cheaper and still use the arduino software. Better yet get a little chip with a dev board for just a couple bucks and find some free C++ toolchain for that chip. The code for an I2C LED lighting Slave is just too straightforward to warrant expensive software. GHI probably feels the same way or they would have found a way to implement their device as both Master and Slave.

Main point: no use being upset over the G30’s inability to fill all roles. It has plenty of roles that it fills well and directing lesser systems around it is one of them.

All this being said… If I was going to try and accomplish this using a bunch of G30s. I would look into the feasibility of my Slaves using the Input Capture class to gather incoming addresses and data. and maybe some fancy OneWire or PWM could get data back to the Master. Idk what kind of control and speed you really need for this kind of thing.