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.
9 years, 9 months ago.
KL25Z multiple I2C problem.
Hi all,
I am working on a double gas mass flowmeter project to migrate KL25Z platform. Currently its working on LPC1768 and because of the cost problems its needed to migrate to KL25Z..
Anyway, My problem is, I was using two I2C differential presssure sensors (with the same address:0X51) with two different I2C pins on LPC1768 (p9-p10, p28-p27), But with KL25Z I cant! One of them reads always 0.. Theyre connected to PTE0-PTE1 and PTC9-PTC8, The sensor which connected to I2C1 (PTE0-PTE1) works correctly however the other one which connected to I2C0 never works! I tried everything I know and the connections are double checked (pull up resistors etc ok). And the code is the same as LPC1768;
I2C i2c(PTE0, PTE1); I2C i2can(PTE0, PTE1); .... char data [3]; char esra [3]; ...
i2c.read(0x51, data, 2); i2can.read(0x51, esra, 2);
.. May you give some help please..
3 Answers
9 years, 9 months ago.
Hi, I tried with my FRDM-KL25Z and MAG3110
mag3110 = new MAG3110( PTC9, PTC8, MAG3110_I2C_ADDRESS) ;
and it worked with my system.
But meantime I noticed that the on-board MMA8451Q is also connected to I2C0 via PTE25 and PTE24.
In case on-board MMA8451Q is active, MAG3110 on PTC9, PTC8 did not work right.
So I removed my code with MMA8451Q and added
// may be following two lines are not necessary DigitalOut outA(PTE24) ; DigitalOut outB(PTE25) ;
to explicitly disable I2C0 via PTE24/PTE25
moto
In fact I've removed the onboard accelerometer and tried without it, but nothing changed. And there is no other I2C0 pin on the header. I guess your last codes are not necessary as you mentioned. Because if you don't declare them as I2C then they should be straight GPIO natively. (or not?)
posted by 10 Feb 2015I just checked RM for I2C0 pins and there are
I2C0_SCL
PTE24
PTB0
PTB2
PTC8
I2C0_SDA
PTE25
PTB1
PTB3
PTC9
Although I agree with you that unless the pin is defined as I2C0, it should not bother us.
But just in case, explicitly defining suspicious pins to other function or disabling them won't cost us a lot.
Also, when I activated the MMA8451Q via PTE24/25, over writing the program did not fix the situation
and I had to plag out/in the USB cable to cold start my FRDM-KL25Z board.
Yes I've noticed that after Eric's last comment.. :) And tried with PTB1/PTB2 pins. But nothing changed!!!! I dont know, I am very confused about that! I2C0 channel is not working definately.. Thanks for the answer..
posted by 10 Feb 2015I think some/many/most MCUs won't reset their peripheral registers to default values on just a software reset. So if one GPIO is set to the I2C, it will stay set to that until it gets a power-on reset or explicitly set to something else. But that should not be the issue here.
posted by 10 Feb 2015I double checked with my board. And as Ozgur-san noted, re-defining PTE24/PTE25 for GPIO was not necessary. With on-board MMA8451Q intact, my board is accessing MAG3110 via PTC9/PTC8.
So the good news is, yes PTC9/PTC8 can be used as I2C0 on FRDM-KL25Z.
The bad news is something wrong might have happened on Ozgur-san's FRDM-KL25Z board.
9 years, 9 months ago.
Could this be an issue ? Please review.
http://mcuoneclipse.com/2012/12/05/kl25z-and-i2c-missing-repeated-start-condition/
9 years, 9 months ago.
Your code snippet shows both on PTE0/PTE1, I assume this is a copy paste error and not in your actual program?
If you only use the PTC8/9 I2C, does it work then? You do have latest mbed lib? Do you have a logic analyzer to check what is happening?
Yes this is a copy-paste error. Actually its I2C i2c(PTC9, PTC8); I2C i2can(PTE0, PTE1).. I tried with just PTC9 - PTC8 and it did not work. I tried both the newest mbed lib and the old one (which works with LPC1768). With the newest library it hangs at least 2-3 seconds while reading I2C0 channel, after that it reads (or skipped I guess) always 0. With the old library (December 2013 dated not know the revision number) it doesnt hang but reads 0 always. I have no logic analyzer but as I can see in my oscilloscope there is no signal acitivity both SDA or SCL channel..
posted by 10 Feb 2015Can you verify that the DC levels are indeed correct on those pins, and that you are connecting the correct pins? (It sometimes happens you got your pins shifted one location).
Reason for asking is that it might be different in newer version that it timeouts different when bus seems busy: When there are no pull up resistors the bus will always seem to be busy.
posted by 10 Feb 2015In fact I am already suspicied about that issue. Because I had to pull up to 5v (not 3v3) LPC1768's I2C pins to work with these sensors; http://tr.mouser.com/ProductDetail/GE-MC-NovaSensor/NPA-700B-10WD/?qs=sGAEpiMZZMvhQj7WZhFIACCBXe74v8hwY%2ftuWhLlA3E%3d However I am not sure that KL25Z pins are 5v tolerant or not..
posted by 10 Feb 2015KL25 pins are NOT 5V tolerant. I don't think that it is currently your issue, although they could have broken already, often they survive for quite some time overvoltage situations.
However obviously that isn't something you want in a product. It does show on the mouser page it works on 3.3V too.
posted by 10 Feb 2015No, if you use 3v3 then they should be recalibrated and its impossible for low counts of purchases. Anyway, it cannot be the signal level problem because the other channel works (I2C1) perfect. Do you think PTE0/PTE1 pins have different logic voltage levels than the others?
posted by 10 Feb 2015The signal level issue could have physically broken those pins. For a product you will either need a 5V tolerant MCU, or a level shifter.
Here you can find the complete pinout: http://developer.mbed.org/users/mbed_official/code/mbed-src/file/fc4922e0c183/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c, can you try other pins?
posted by 10 Feb 2015I've tried I2C0 with PTB1-PTB2 pins but still doesn't read the sensor while I2C1 channel is reading the same sensor.. I am tired about that! I guess I will continue with LPC1768 ...:(
posted by 10 Feb 2015Dear Eric,; Do you think the sensor could kill my KL25Z's I2C0 channel (because of it works with 5v) ? Just an idea..!
posted by 10 Feb 2015No that can't be it. It could kill the pins it is connected to, but not the I2C channel itself, there are buffers in between which will prevent that from happening.
So while technically it is possible that you are really lucky that one channels keeps working while the other one does not work, I consider it to be very unlikely.
To be fair I have no idea what could be the problem now. (Unless it would be the overvoltage). I was going to test it later today myself, but Motoo already did it, and it should just work. You are not using any other I2C than those two? Did you try it with a very simple program? (So nothing besides just the I2C).
posted by 10 Feb 2015I've done whole these tests with only a I2C reading code..Not more.. May you share the test results please..
posted by 11 Feb 2015