Hi all,
We are trying for I2C interface with kinetis KL03 using KDS3.0.0 + PE
We are trying using "fsl_I2C" component in PE. in this I2C_DRV_MasterReceiveData(); is used.
writing in parameters of this function for "number of data to read" as count=2
expected output is >> Before: 0 0 After: C1 E0
we are getting as >> Before: 0 0 After: 1 FF
But
writing in parameters of this function for "number of data to read" as count=1
expected output is >> Before: 0 0 After: C1 0
we are getting as >> Before: 0 0 After: C1 0
Master: KL03
Slave address: 0x18
Data register: 0x05
Number of bytes to read: 2
Clock: Internal clock used (Externally 32.768Khz crystal is not connected)
while reading only one byte from slave is giving output as expected, but no luck with reading two bytes from slave.
projet file is attached here, please guide me how to resolve this problem of reading 2 bytes data from slave? Is there any correction in my parameter passing to function?
Idris
Original Attachment has been moved to: I2C_2bytesReadingIssue.zip
Solved! Go to Solution.
Hello syed,
Have your problem be solved ?
if not , i still think you need debug step by step and set breakpoint to check.
I test the I2C demo on two FRDM-KL03 board (one master , one slave ) ,
when i set count = 1 , 2, 3 .... they all can work well.
The demo is under KSDK :
KSDK_1.3.0\examples\frdmkl03z\driver_examples\i2c\i2c_polling\master\kds
KSDK_1.3.0\examples\frdmkl03z\driver_examples\i2c\i2c_polling\slave\kds
BR
Alice
Hello syed,
I have checked your project , there is no problem about the usage of I2C_DRV_MasterReceiveData(); .
What about the slave , which chip ?
I recommend you first check the waveform on I2C bus .
BR
Alice
Alice,
We are using MCP9805 as slave chip.
waveform of KL03 interfaced with MCP9805 is as below
to confirm that our slave device is OK or not we checked it with arduino. It is working fine,
waveform of arduino interfaced with MCP9805 is as below
Idris
Hello Syed,
What about the waveform ? Read one byte or two ?
While from the datasheet of mcp9805, when read one byte ,it should show four byte :
when read two byte , it should show five byte :
So what about the wave ?
BR
Alice
Reading 2bytes from 9805 gives
>>Reading 2bytes from 9805 gives 1st byte as
>>Reading 2bytes from 9805 gives 2nd byte as
>>Reading 2bytes from 9805 gives 3rd byte as
>>Reading 2bytes from 9805 gives 4th and 5th byte as
Sorry for lengthy post,
I thought it will help you to guide me,
For 1 byte reading the data what we are seeing on waveform as we are getting on console output are perfect.
but for reading 2 bytes what we are seeing on waveform (Address+W, Register pointer, Address+R, MSB, LSB) in that the data which is on 4th byte (MSB) and 5th byte (LSB) we are not getting them on console output.
Idris
Hello Idris,
Could you please also expand the last picture as the others .
It hardly know the data of the last one , while the last one is the key one .
BR
Alice
Alice,
I attached here the waveform of 4th and 5th byte while reading 2 bytes from MCP9805.
But as the MCP9805 is digital temperature sensor and these two bytes are for determining the ambient temperature, so it's data will change as ambient temperature changes.
Idris
Hello Syed,
The last picture not only just the waveform of 4th and 5th byte ,from the
datasheet, it only includes MSb Data and LSb Data :
from the screenshot of your picture , i think the last part is the MSb and LSb Data :
you can compare the two picture , the two data is 1 FF .
So the master(kl03) show is right data , there is no wrong about the kl03 code .
Hope it hleps
Alice
Hi Alice,
I don't think 0x01FF is the right data which is expected,.
To elaborate my view I'll write few points here
>>POINT-1: We checked on Arduino with MCP9805 it is showing 0xC1E0 as two bytes.
>>POINT-2: As per datasheet if we are reading two bytes then there should be only 2 bytes after 3rd byte (Address+R) then NAK
but as observed on I2C bus we are getting 4bytes after 3rd byte (Address+R) then NAK
>>POINT-3: I can say that 1 FF is the appended data to our expected data, because the temperature data is changing we are unable to say that in waveform which is our expected data,
so I just tried reading the Manufacturing ID and device ID registers
so green colored is 0x0054 is as expected and red colored 0x01FF is appended,
so green colored is 0x0000 is as expected and red colored 0x01FF is appended,
So When I am trying to read two bytes from register why I am getting 4 bytes on I2C bus? :smileyconfused:
>>POINT-4: For exploring more I tried for reading 3 bytes from register 0x06 .instead of showing 3 bytes it was showing 6 bytes.
after expanding
so first 2bytes 0x0054 is as expected and red colored 0x01FF 0xFFFF is appended,
and for this 3bytes reading I was suspecting I'll get FF FF on console for printing buffer[0] and buffer[1] but I got 1 FF. :smileyshocked:
Idris
Hello Syed,
Thank for your explanation , it very cleay !
The reason of slave send more than two bytes is after it send 0x0045 , the master
not send NACK.
So I check the KSDK i2c driver code today , i think maybe there is a bug in the code.
While i don't sure . After slave send two bytes (for example the count =2), master should send NACK.
While from the waveform , it send ACK . So please set breakpoint on the interrupt function , check
the first received data , then step by step to run , check whether it have issue or bug .
In the function of void I2C_DRV_MasterIRQHandler(uint32_t instance):
Another method is use the latest version of KDSK v2.0 , it fixed the bugs which ksdk1.3 have .
You can see the ksdk1.3 really have some issue :
Strange behaviour in i2c driver (KSDK 1.3.0)
About the download and use of KSDK v2.0 , please refer to here :
https://community.nxp.com/docs/DOC-329662
Hope it heps
Alice
Hi Alice,
Does KSDK2.0 support PE?
I remember somewhere I read that KSDK2.0 is not supported for PE, is it?
Idris
Hello syed,
Have your problem be solved ?
if not , i still think you need debug step by step and set breakpoint to check.
I test the I2C demo on two FRDM-KL03 board (one master , one slave ) ,
when i set count = 1 , 2, 3 .... they all can work well.
The demo is under KSDK :
KSDK_1.3.0\examples\frdmkl03z\driver_examples\i2c\i2c_polling\master\kds
KSDK_1.3.0\examples\frdmkl03z\driver_examples\i2c\i2c_polling\slave\kds
BR
Alice
Hi Alice,
Thanks a lot for your support.
I didn't come to know what is the problem with I2C_DRV_MasterReceiveDataBlocking(); and I2C_DRV_MasterReceiveData(); for reading two bytes data from slave.
BTW I just used I2C_DRV_MasterReceiveDataPolling(); function so now its working fine.
Thanks again.
Have a great time.
Idris
Hello syed,
No, KSDK doesn't support PE.
If you need PE, we only can continue find the problme on KSDK 1.3 .
And one hand you debug step by step to check i mentioned last time ,
on other hand , i find another chip to check it , i will reply you .ASAP.
BR
Alice
Hi Alice,
I will attach here the details of waveform.
Reading 1byte from 9805 gives
I'll give the more snaps byte by byte
>>Reading 1byte from 9805 gives 1st byte as
>>Reading 1byte from 9805 gives 2nd byte as
>>Reading 1byte from 9805 gives 3rd byte as
>>Reading 1byte from 9805 gives 4th byte as