S32K I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K I2C

5,938 Views
hajianik
Senior Contributor I

Seems to me based on my own working (past 10 days )with the SDK I2C drivers and searching the forum , there are issues with using the non blocking I2C send and receive drivers:

 

 

/*!

* @brief Perform a non-blocking receive transaction on the I2C bus

*

* This function starts the reception of a block of data from the currently

* configured slave address and returns immediately.

* The rest of the reception is handled by the interrupt service routine.

* Use LPI2C_DRV_MasterGetReceiveStatus() to check the progress of the reception.

*

* @param instance  LPI2C peripheral instance number

* @param rxBuff    pointer to the buffer where to store received data

* @param rxSize    length in bytes of the data to be transferred

* @param sendStop    specifies whether or not to generate stop condition after the reception

* @return    Error or success status returned by API

*/

status_t LPI2C_DRV_MasterReceiveData(uint32_t  instance,

                                               uint8_t * rxBuff,

                                               uint32_t rxSize,

                                               bool sendStop);

 

and

 

 

/*!

* @brief Perform a non-blocking send transaction on the I2C bus

*

* This function starts the transmission of a block of data to the currently

* configured slave address and returns immediately.

* The rest of the transmission is handled by the interrupt service routine.

* Use LPI2C_DRV_MasterGetSendStatus() to check the progress of the transmission.

*

* @param instance  LPI2C peripheral instance number

* @param txBuff    pointer to the data to be transferred

* @param txSize    length in bytes of the data to be transferred

* @param sendStop    specifies whether or not to generate stop condition after the transmission

* @return    Error or success status returned by API

*/

status_t LPI2C_DRV_MasterSendData(uint32_t instance,

                                            const uint8_t * txBuff,

                                            uint32_t txSize,

                                            bool sendStop);

 

 

 

I can’t say for certain but I sense from the discussion in the forum and my own dealing with this,

The blocking versions of the above functions are to be used. For me the blocking is stable while the none blocking version triggers exceptions.

Can someone confirm this please?

Thanks

Labels (1)
Tags (1)
0 Kudos
Reply
5 Replies

4,634 Views
AlinaB
NXP Employee
NXP Employee

Hello Koorosh, 

What kind of exceptions did you get by using non-blocking functions? 

If you use non-blocking functions you must ensure the transfer finished before starting a new transfer. You should use LPI2C_DRV_MasterGetTransferStatus or LPI2C_DRV_SlaveGetTransferStatus  to check the status of the driver.

Best regards, 

Alina

0 Kudos
Reply

4,634 Views
hajianik
Senior Contributor I

Hi Allina,

This is i2c project that sends 16 byte , to a slave device at address 0x52 and register address 0x0080.

I realize you can’t test it without having the slave device connected to your board, however I’m requesting to review the code from the master device perspective and point out that which is incorrect.

 

I’m using the none blocking send and receive drivers (SDK)and basically before any transmission/reception, I’m making sure the current transfer is done.

 

My issue is that the transfer stops after few seconds, that is probably few hundred transfers .

The issue could very well may be on the slave side or some hardware problem, but at least you or your colleagues can see if I’m using these routines correctly.

 

Thanks,

Koorosh Hajiani

0 Kudos
Reply

4,634 Views
AlinaB
NXP Employee
NXP Employee

Hello Koorosh,

 

At a first look upon your code I have the following remarks:

 

  1. At line 146 from main.c: LPI2C_DRV_MasterSendDataBlocking(0,tx_buff2,2,0,5), here instead of 5 (which represents the timeout in ms) put a greater value such as 0xFFFF.
  2. Instead of using this kind of checking:

     LPI2C_DRV_MasterReceiveData(INST_LPI2C1, buffer, 16, true);

     do{

           LPI2C_DRV_MasterGetTransferStatus(0,&bytesRemaining);

      }

      while(bytesRemaining);

   Try with this one:

status_t retCode;

 

     LPI2C_DRV_MasterReceiveData(INST_LPI2C1, buffer, 16, true);

     while ((retCode = LPI2C_DRV_MasterGetTransferStatus(INST_LPI2C1, NULL)) == STATUS_BUSY) {};

    This way you know for sure if status is not busy and you can start a new transfer.

 

  1. Check if the transfer run successful if using a smaller baud rate, such as 100000 Hz.

 

Please let me know if the transfer succeeded after using one of the above.

 

Best regards,

Alina

4,634 Views
hajianik
Senior Contributor I

Hi Alina,

Thanks for your response,

The issue turned out to be a hardware problem and it is resolved now.

I just need to verify one other thing:

Based on the I2C protocol , I understand that the MASTER drives the CLK however the DATA line is bidirectional and in fact no one drives it high (since there is a pull up on the line to VDD , as there is a pull up on the CLK too.)

only it is driven low by either master or slave.

The CLK on S32 device however is driven low only by the master. what would be the configuration for that pin(CLK) on the S32K  side?

Is it open drain only when driven low and just a high input impedance when high or in both cases it is an open drain output?

The manual is not clear about that.

and lastly, is there a I2C DMA example for this micro using PE,  somewhere? 

Hope you're not confused by my question.

Thanks,

0 Kudos
Reply

4,634 Views
AlinaB
NXP Employee
NXP Employee

Hello Koorosh,

Both CLK and DATA pins should be configured as open-drain (for both master and slave).

Slaves can also drive the CLK low to slow down the bit rate. After the master has driven

the CLK pin low, the slave can drive SCL low for the required period and then release it.

 

I have attached you a short description of how to use lpi2c using DMA transfers.

 

Best regards,

Alina

0 Kudos
Reply