RT1176 I2C operation

cancel
Showing results for 
Search instead for 
Did you mean: 

RT1176 I2C operation

441 Views
VicKrawciw
Contributor I

Hi,

I am trying to implement I2C operation on a board using RT1176 similar to the RT1170-EVK. I am using the fsl_lpi2c.c device driver calling the LPI2C_MasterTransferBlocking function. However, although I can see a CLK output on the pin the SDA line seems to go low for the I2C start but then no address is output. It then continues to output CLK continuously and any further attempts to transmit are met with a bus busy.

I looked at the SDK lpi2c 'polling_b2b_master_cm7' device demo and followed the correct initialisation etc. However upon looking more closely at this demo it cannot possibly work as it sets up i2c on pins that are connected to the EVK USB and not the J26 connector! I tried to download it to my EVK and indeed it does not run.

Are there any working demos of using the I2C?

Labels (1)
0 Kudos
9 Replies

428 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @VicKrawciw ,

   When you test this SDK code:

SDK_2_11_1_MIMXRT1170-EVK\boards\evkmimxrt1170\driver_examples\lpi2c\polling_b2b

  You need to MIMXRT1170-EVK board, one as I2C master, another as I2C slave.

  Just as the readme.txt mentioned:


Hardware requirements
=====================
- Mini/micro USB cable
- Two MIMXRT1170-EVK board
- Personal Computer

Board settings
==============
LPI2C one board:
+ Transfer data from MASTER_BOARD to SLAVE_BOARD of LPI2C interface, LPI2C1 pins of MASTER_BOARD are connected with
LPI2C1 pins of SLAVE_BOARD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MASTER_BOARD CONNECTS TO SLAVE_BOARD
Pin Name Board Location Pin Name Board Location
LPI2C1_SCL J26-12 LPI2C1_SCL J26-12
LPI2C1_SDA J26-10 LPI2C1_SDA J26-10
GND J10-14 GND J10-14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

You mentioned, master can send out the clk, but the address no data, it is caused by your slave, do you connect the I2C slave board or not?

master code:

\SDK_2_11_1_MIMXRT1170-EVK\boards\evkmimxrt1170\driver_examples\lpi2c\polling_b2b\master

slave code:

SDK_2_11_1_MIMXRT1170-EVK\boards\evkmimxrt1170\driver_examples\lpi2c\polling_b2b\slave

when run it, slave should run it at first, then wait the master send the clock and command.

Please find two RT1170 board and test it.

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

Kerry

0 Kudos

420 Views
VicKrawciw
Contributor I

OK I understand the demo now - I was looking at the wrong pins - my bad.

So now I am calling  LPI2C_MasterTransferBlocking to read 315 bytes of data from an M24c64 eeprom device, and it appears to be getting stuck after reading 256 bytes - sitting in an endless loop awaiting data that is not transmitted.

lpi2c_master_transfer_t xfer;

xfer.flags = kLPI2C_TransferDefaultFlag;
xfer.slaveAddress = part_addr;
xfer.direction = kLPI2C_Read;
xfer.subaddress = 0;
xfer.subaddressSize = 2;
xfer.data = data;
xfer.dataSize = 315;

if ( LPI2C_MasterTransferBlocking(I2C, &xfer) == kStatus_Success)
{

}

 

If I manually split the read into 255 bytes followed by 60 bytes then it works OK. So it appears the logic in the fsl_lpi2c.c driver has a bug reading over 256 bytes.

Is this known issue? Is there a fix available?

Thanks

0 Kudos

415 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @VicKrawciw ,

  If you check the driver detail code, you will find it:

kerryzhou_0-1654056960155.png

 

Make sure your transfer data is not exceed the max size.

You also can debug it find the root issue.

Wish it helps you!

Best Regards,

kerry

0 Kudos

412 Views
VicKrawciw
Contributor I

Hi

315 bytes does not exceed this limit which would be 256*4.

I have tried to debug it but the device just stops at 256 bytes. I cannot determine if the problem is actually in the LPI2C hardware as I can see no reason for the apparent failure to move on to the next read command in the MTDR command fifo. Two read commands are placed into the MTDR fifo (0x1ff, 0x159) but it appears that no more reads are placed on the I2C bus when the first command completes, which causes the the read of the MRDR register to have the RXEMPTY flag set - and the code just loops expecting this situation to change - which it does not as reads are not happening on the bus.

 

0 Kudos

409 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @VicKrawciw ,

  Please test this code:

SDK_2_11_1_MIMXRT1170-EVK\boards\evkmimxrt1170\driver_examples\lpi2c\interrupt\cm7

  Then set the size to larger than 256, whether that work or not?

  Or you can refer to the polling code, use this API: LPI2C_MasterSend, when the size is larger than, whether it works or not, I find the i2c driver sdk demo also didn't use LPI2C_MasterTransferBlocking API.

  When you use LPI2C_MasterTransferBlocking, meet issues, do you check the status flag MSR, which issue happens?

 

Best Regards,

kerry

 

  

0 Kudos

407 Views
VicKrawciw
Contributor I

Hi,

I have no need of the interrupt version in my project - the polling version is sufficient.

As I mentioned during my debug, there is no error returned - it fails to move on in the fifo to the next read command and so just repeatedly attempts read values from the MRDR which returns empty.

LPI2C_MasterTransferBlocking calls LPI2C_MasterReceive which is where the issue arises.

It is stuck in this loop:

 

uint32_t value = 0U;
do
{
/* Check for errors. */
result = LPI2C_MasterCheckAndClearError(base, LPI2C_MasterGetStatusFlags(base));
if (kStatus_Success != result)
{
break;
}

value = base->MRDR;
#if I2C_RETRY_TIMES != 0U
waitTimes--;
} while ((0U != (value & LPI2C_MRDR_RXEMPTY_MASK)) && (0U != waitTimes));
if (0U == waitTimes)
{
result = kStatus_LPI2C_Timeout;
}
#else
} while (0U != (value & LPI2C_MRDR_RXEMPTY_MASK));
#endif

 

I am sure LPI2C_MasterSend will be OK as that just writes each byte of data to MTDR one at a time.

 

0 Kudos

402 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @VicKrawciw ,

   Thanks for your updated information.

   So, when the datasize larger than 256, then your MRDR[RXEMPTY] always =1 - Receive FIFO is empty, then it always in the loop, right?

  Could you please check the I2C bus, whether after send 0-255 bytes clock, master send the 256 byte clock? Seems the master didn't receive the data from the slave, just to check whether the slave share the data or not.

   Due to COVID-19, I am working at home now, so, lack the tools to test it, anyway, I will record this API issues, when I have chance to test it, I will test it on my side.

   If your project is  busy, you can send frame as 256bytes at first, then use the new API to receive the new other bytes.

 

Best Regards,

Kerry

0 Kudos

364 Views
VicKrawciw
Contributor I

Hi,

 

As far as I can tell it appears the master stops generating the clock in order to read the bytes of the following FIFO command to read bytes 257 onwards.

I have implemented a work around that splits the read into separate 256 byte LPI2C_MasterTransferBlocking calls adjusting the subaddress for each call.

0 Kudos

359 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @VicKrawciw ,

   Thanks for your effort.

   I already record it, I will test this function in our internal new version which is not published, if I reproduce the issues, the SDK team will help to fix it and release the new version in the near future.

   Thanks a lot for your report.

   Any SDK issues you found, welcome let us know.

Best Regards,

Kerry

0 Kudos