I2C two bytes reading issue

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C two bytes reading issue

Jump to solution
2,164 Views
syed_idris
Contributor III

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

Labels (1)
Tags (3)
0 Kudos
1 Solution
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

pastedImage_1.png

BR

Alice

View solution in original post

0 Kudos
14 Replies
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 Kudos
690 Views
syed_idris
Contributor III

Alice,
We are using MCP9805 as slave chip.

waveform of KL03 interfaced with MCP9805 is as below

KL03_I2C_read.bmp

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

Arduino_I2C_read.bmp

Idris

0 Kudos
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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 :

pastedImage_0.png

when read two byte , it should show five byte :

pastedImage_1.png

So what about the wave ?

BR

Alice

0 Kudos
690 Views
syed_idris
Contributor III

Reading 2bytes from 9805 gives

2ByteFull22082016.bmp

>>Reading 2bytes from 9805 gives 1st byte as

2_1byte.bmp

>>Reading 2bytes from 9805 gives 2nd byte as

2_2ndbyte.bmp

>>Reading 2bytes from 9805 gives 3rd byte as

2_3rdbyte.bmp

>>Reading 2bytes from 9805 gives 4th and 5th byte as

2_45thbyte (2).bmp

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

0 Kudos
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 Kudos
690 Views
syed_idris
Contributor III

Alice,
I attached here the waveform of 4th and 5th byte while reading 2 bytes from MCP9805.
2_45thbyte (3).bmp
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

0 Kudos
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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 :

pastedImage_0.png

from the screenshot of your picture , i think the last part is the MSb and LSb Data :

pastedImage_1.png

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

0 Kudos
690 Views
syed_idris
Contributor III

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

pastedImage_0.png

but as observed on I2C bus we are getting 4bytes after 3rd byte (Address+R) then NAK

4th_5thbyte.bmp

>>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

data.PNG

  • While reading 2 bytes from register 0x06 shows as

device_Register 0x54.bmp

so green colored is 0x0054 is as expected and red colored 0x01FF is appended,

  • While reading 2 bytes from register 0x07 shows as

revision Reg_23082016.bmp

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.

id3byte23082016.bmp

after expanding

id3byte_extended_23082016.bmp

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

0 Kudos
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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):

pastedImage_4.png

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) 

I2C+KSDK+PE+Interrupt Problem 

About the download and use of KSDK v2.0 , please refer to here :

https://community.nxp.com/docs/DOC-329662 

Hope it heps

Alice

0 Kudos
690 Views
syed_idris
Contributor III

Hi Alice,

Does KSDK2.0 support PE?

I remember somewhere I read that KSDK2.0 is not supported for PE, is it?

Idris

0 Kudos
691 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

pastedImage_1.png

BR

Alice

View solution in original post

0 Kudos
690 Views
syed_idris
Contributor III

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

0 Kudos
690 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 Kudos
690 Views
syed_idris
Contributor III

Hi Alice,
I will attach here the details of waveform.

Reading 1byte from 9805 gives
1BYteFull 22082016.bmp

I'll give the more snaps byte by byte
>>Reading 1byte from 9805 gives 1st byte as

1_1stbyte.bmp

>>Reading 1byte from 9805 gives 2nd byte as

1_2ndbyte.bmp

>>Reading 1byte from 9805 gives 3rd byte as

1_3rdbyte.bmp

>>Reading 1byte from 9805 gives 4th byte as

1_4thbyte.bmp

0 Kudos