Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 5 months ago.
KL25Z i2c multidevice problem!
Hello! Sorry for my bad english...
I tried to connect and use three i2c devices at one time:
1. MMA8451Q internal KL24Z accelerometr;
2. 3 axis gyro ITG 3200 http://www.seeedstudio.com/wiki/Grove_-_3-Axis_Digital_Gyro;
3. Dallas RTC DS1307 http://www.seeedstudio.com/wiki/index.php?title=Twig_-_RTC;
I have a strange bug. If i initialize MMA8451Q on internal i2c(0) and connect GYRO to i2c(1), all works perfectly. if I additional connect Dallas RTC to i2c(1), it does not work. But If I don't initialize GYRO, RTC is working fine! if I connect GYRO or RTC to i2c(0) with MMA8451Q on bus, the MMA8451Q failed to work.
Resume. All devices is working fine whan it separately. But if I tried to use more then one device on i2c bus, I can't do that. I don't understand in what a problem! :( Help me please!
3 Answers
11 years, 5 months ago.
Do you have a scope to see the waveforms? It could be in theory that the integrated resistors on those boards are fairly small, so when you place them in parallel they become too small. Although there generally is quite a range of resistances which are acceptable.
Or you can measure them with a multimeter (from SDA/SCL to Vdd).
11 years, 5 months ago.
of course all addresses are different:
include the mbed library with this snippet
// Internal Accelerometr I2C Address #define ACC_SDA PTE25 #define ACC_SCL PTE24 #define MMA8451_I2C_ADDR (0x1D<<1) // Gyro I2C #define GYRO_SDA PTE0 #define GYRO_SCL PTE1 #define ITG3200_I2C_ADDR (0x69<<1) // RTC #define RTC_SDA PTE0 #define RTC_SCL PTE1 #define DS1307 (0x68<<1)
11 years, 5 months ago.
You are using a port (PTE25,PTE24) that may not be fully supported by Mbed. I had a similar issue trying to program a 32pin version KL25Z, the spec indicated i2c on a port that would not work even though the pin out sheet on Mbed said it would.
Try using PTC8,PTC9 instead.
Also try a different way to use the port, I use the following, may not be the best but it works for me.
I2c
#include "mbed.h" I2C i2c(PTC9, PTC8); // I2C device sda, scl char set[2]; char cmd[2]; char rst[3]; int main() { i2c.frequency(400000); rst[0]=0x0C; rst[1]=0x00; i2c.write(0xD0,rst,2);// send 2 bytes to start rtc and register output of clock ic. //0xD0 is my RTC chip address. set[0]=0x12; // read time zone from clock rtc register i2c.write(0xD0,set,1); i2c.read(0xD0,cmd,1); tz=cmd[0]; }
As Erik said, check you're pull-up resistors, generally 10k is good and is only required once, not 3 lots of 10k. This will have an effect on the 'sharpness' of the data edges. Also check you're connecting wires, shorter the better and not a 'birds nest'. You can lower the frequency to get round wiring issues but will slow the system down.
If you are using an ISR, make sure all the code can complete within the ISR interval, that caught me out many times!
Check the I2c address of each device is different, I have had 5 devices connected before without a problem, you could use a second i2c port on the kl25z, 2 devices on one port and 1 device on the other.
posted by Paul Staron 16 Jun 2013Thank you very much, for your attention to my problem!
The problem was on face. Those modules that I tried to connect was designed for 5v Arduino boards and does not work properly on 3v system, when I go brave and connect it to 5v (i mean power pins of modules) I got it work! Thanks one more time!
But I still can't work with i2c0 bus :( When I connect my devices on PTC8, PTC9, I got only internal MMA8451Q data, and nothing more :(
posted by Evgeney Kirik 17 Jun 2013