Page 1 of 1

MOD54415 I2C example code

Posted: Mon Dec 15, 2014 8:41 am
by nicobari
Hi,
In the NetburnerRuntimeLibraries.pdf on page number 12 it says "Note:An example I2C application can be found in C:\Nburn\example\<HWPLatform>" but when I opened my C:\Nburn\example\MOD54415 folder I didn't see any I2C example. Where can I find an I2C example code?

Thanks,
TM

Re: MOD54415 I2C example code

Posted: Mon Dec 15, 2014 1:00 pm
by mbrown
I've answered this question a few times in the past week or two and I'm going to add a few examples to our standard eclipse build to demonstrate for people. For the most part, our i2c drivers are cross-platform, so if you wrote it for one platform, it most likely works on another. I'm going to attach 3 programs to this post, each with different uses.

The first is our classic i2c2serial example that allows two Netburner devices to communicate over serial, or for you to control an i2c bus on a serial console. As usual, you'll note there is a choice of includes. i2cmaster will run only in master mode controlling any number of slave devices. i2cmulti will run in either run as a master or respond as a slave device to whatever address you give in the i2cinit call.

The second example I'm including here has a really simple function Paul wrote to find all i2cdevices attached to your hardware module. It basically sends out a call on the bus and waits for an ack, scanning each address in the address space. If a device responds, it reports that it's found a device at xx address. This one is really useful for figuring out what address you should give to the sendbuf and readbuf commands to talk to your i2c devices. This should be helpful in two ways, one it tells you that you have the hardware hooked up right and two it avoids confusing datasheets. (Anyone familiar with i2c datasheets will know their address are written 3 different ways and 2 of them are wrong depending on who you ask.)

The third example is the probably what 90% of i2c sensor calls will look like. I took some code from our cloud learn article: http://www.netburner.com/learn/sparkfun ... ner-device and distilled it just down to i2c calls using restarts. I've also adapted the code to use the multichanneli2c library I developed a while back for the mcf5441x processors. This will allow you to communicate on any i2c module on the MOD5441x and NANO, of which there are 6, with the ease of using the other libraries.

Hope this helps.

Re: MOD54415 I2C example code

Posted: Wed Dec 17, 2014 1:42 pm
by nicobari
Thank you very much