KV31F - what are the Kinetics LPI2C flags that are equal to I2C driver

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

KV31F - what are the Kinetics LPI2C flags that are equal to I2C driver

754 Views
shai_b
Senior Contributor II

Hello team,

I’m starting to make a migration of my code from K32 to KV31.

I saw that I used in K32 the LPI2C, but for the FRDM-KV31 there is no example code for such driver only I2C.

First question, can we use LPI2C in the KV31?

Second, In my code I’m using in the following flags,

  1. kLPI2C_SlaveAddressValidFlag
  2. kLPI2C_SlaveRxReadyFlag
  3. kLPI2C_SlaveTxReadyFlag

Could you please advise what is the equal flags in the I2C driver?

Thanks in advance

Kind regards,

Shai

Labels (1)
Tags (2)
0 Kudos
Reply
3 Replies

746 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

The LPI2C and the I2C are different modules. The LPI2C can't be used in the KV31 since registers and other features are different.
The available flags of the i2c driver of the KV31 are in the Status register. You can find detail about the available flags in chapter 41.3.4 of the reference manual.
I suggest you refer to the I2C example of the KV31 SDK, although they are different drivers some implementations are similar.

Let me know if this is helpful, if you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos
Reply

718 Views
shai_b
Senior Contributor II

Dear @Omar_Anguiano,

 

The customer has tried in the last two days to enable the I2C interface in the FRDMKV31F and still not working probably.

See below the customer IRQHandler function that works with fsl_lpi2c driver.

Could you please check what is the implementation changes that need to be done in order to work with fsl_i2c driver?

Waiting for your kind response, Thanks in advance 

Shai 

 

the code under the spoiler  

 

void LPI2C_SLAVE_IRQHandler(void)

{

    uint32_t flags = 0U;

    uint32_t flags2 = 0U;

 

    /* Get interrupt status flags. */

    flags = LPI2C_SlaveGetStatusFlags(EXAMPLE_LPI2C_SLAVE_BASEADDR);

 

    if (flags & kLPI2C_SlaveAddressValidFlag)

    {

        /* Release the i2c bus */

       EXAMPLE_LPI2C_SLAVE_BASEADDR->SASR;

        return;

    }

 

    if (flags & kLPI2C_SlaveRxReadyFlag)

    {

              RXData = EXAMPLE_LPI2C_SLAVE_BASEADDR->SRDR;

 

              #if defined(DEBUG_I2C)

                     PRINTF("RX: 0x%2x ", RXData);

                     PRINTF("\r\n");

              #endif

 

              if((RXData < WR_OFFSET) & (!i2cTxProcessIsStart))

              {

                     /* Send NACK at the last byte. */

                     EXAMPLE_LPI2C_SLAVE_BASEADDR->STAR = LPI2C_STAR_TXNACK_MASK;

 

                     switch (RXData)

                     {

                           // Read Registers ///////////////////////////

                           case DEVICE_ID_L:

                                  TXData = DEVICE_ID_LOW;

                                  break;

                           case DEVICE_ID_H:

                                  TXData = DEVICE_ID_HIGH;

                                  break;

                           case FW_VERSION_L:

                                  TXData = FW_VERSION_LOW;

                                  break;

                           case FW_VERSION_H:

                                  TXData = FW_VERSION_HIGH;

                                  break;

 

                           case V_POS_X_L:

                                  TXData = adcXValueInBytes[1];

                                  break;

                           case V_POS_X_H:

                                  TXData = adcXValueInBytes[0];

                                  break;

                           case V_POS_Y_L:

                                  TXData = adcYValueInBytes[1];

                                  break;

                           case V_POS_Y_H:

                                  TXData = adcYValueInBytes[0];

                                  break;

                           case V_SUM_L:

                                  TXData = adcSumValueInBytes[1];

                                  break;

                           case V_SUM_H:

                                  TXData = adcSumValueInBytes[0];

                                  break;

 

                           case DAC1_OUT_L:

                                  TXData = 0x00;

                                  break;

                           case DAC1_OUT_H:

                                  TXData = 0x00;

                                  break;

                           case DAC2_OUT_L:

                                  TXData = 0x00;

                                  break;

                           case DAC2_OUT_H:

                                  TXData = 0x00;

                                  break;

 

                           case K_FACTOR_RD_0:

                                  TXData = stabParamsInBytes.k_factor[1];

                                  break;

                           case K_FACTOR_RD_1:

                                  TXData = stabParamsInBytes.k_factor[0];

                                  break;

 

                           case CL_OFFSET_L:

                                  TXData = stabParamsInBytes.offset[1];

                                  break;

                           case CL_OFFSET_H:

                                  TXData = stabParamsInBytes.offset[0];

                                  break;

 

                           case QUAD_GAIN_L:

                                  TXData = stabParamsInBytes.quad_gain[1];

                                  break;

                           case QUAD_GAIN_H:

                                  TXData = stabParamsInBytes.quad_gain[0];

                                  break;

 

                           case LIM_OUT_MAX_L:

                                  TXData = stabParamsInBytes.limiter_out_max[1];

                                  break;

                           case LIM_OUT_MAX_H:

                                  TXData = stabParamsInBytes.limiter_out_max[0];

                                  break;

                           case LIM_OUT_MIN_L:

                                  TXData = stabParamsInBytes.limiter_out_min[1];

                                  break;

                           case LIM_OUT_MIN_H:

                                  TXData = stabParamsInBytes.limiter_out_min[0];

                                  break;

 

                           case I_GAIN_L:

                                  TXData = stabParamsInBytes.i_gain[1];

                                  break;

                           case I_GAIN_H:

                                  TXData = stabParamsInBytes.i_gain[0];

                                  break;

                           case P_GAIN_L:

                                  TXData = stabParamsInBytes.p_gain[1];

                                  break;

                           case P_GAIN_H:

                                  TXData = stabParamsInBytes.p_gain[0];

                                  break;

 

                           case W_INTEGRATOR_L:

                                  TXData = stabParamsInBytes.w_integrator[1];

                                  break;

                           case W_INTEGRATOR_H:

                                  TXData = stabParamsInBytes.w_integrator[0];

                                  break;

                           case TS_INTEGRATOR_L:

                                  TXData = stabParamsInBytes.ts_integrator[1];

                                  break;

                           case TS_INTEGRATOR_H:

                                  TXData = stabParamsInBytes.ts_integrator[0];

                                  break;

                           case LIM_INTEGRATOR_L:

                                  TXData = stabParamsInBytes.limiter_integrator[1];

                                  break;

                           case LIM_INTEGRATOR_H:

                                  TXData = stabParamsInBytes.limiter_integrator[0];

                                  break;

 

                           case OUT_SELECT_L:

                                  TXData = stabParamsInBytes.output_select[1];

                                  break;

                           case OUT_SELECT_H:

                                  TXData = stabParamsInBytes.output_select[0];

                                  break;

                           case DAC1_VALUE_L:

                                  TXData = stabParamsInBytes.dac1_value[1];

                                  break;

                           case DAC1_VALUE_H:

                                  TXData = stabParamsInBytes.dac1_value[0];

                                  break;

                           case DAC2_VALUE_L:

                                  TXData = stabParamsInBytes.dac2_value[1];

                                  break;

                           case DAC2_VALUE_H:

                                  TXData = stabParamsInBytes.dac2_value[0];

                                  break;

                           case SAMPLE_INT_L:

                                  TXData = stabParamsInBytes.sample_interval[1];

                                  break;

                           case SAMPLE_INT_H:

                                  TXData = stabParamsInBytes.sample_interval[0];

                                  break;

 

                           default: TXData = 0x00;

                     }

              }

 

              else

              {

                     i2cTxProcessIsStart = true;

                     if (g_slaveRxIndex < I2C_WR_DATA_LENGTH)

                     {

                           /* Send NACK at the last byte. */

                           if (g_slaveRxIndex == (I2C_WR_DATA_LENGTH - 1U))

                           {

                                  EXAMPLE_LPI2C_SLAVE_BASEADDR->STAR = LPI2C_STAR_TXNACK_MASK;

                                  i2cTxProcessIsDone = true;

                           }

 

                           //i2c_slave_buff[g_slaveRxIndex] = EXAMPLE_LPI2C_SLAVE_BASEADDR->SRDR;

                           i2c_slave_buff[g_slaveRxIndex] = RXData;

                           g_slaveRxIndex++;

 

                     }

 

 

                     if(i2cTxProcessIsDone)

                     {

                           g_slaveRxIndex = 0;

                           i2cTxProcessIsStart = false;

                           i2cTxProcessIsDone = false;

                           WR_Address = i2c_slave_buff[0];

 

                           switch (WR_Address)

                           {

                                  // Write Registers ///////////////////////////

 

                                  case K_FACTOR_WR:

                                         stabParamsInBytes.k_factor[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.k_factor[0] = i2c_slave_buff[1];

                                         break;

                                  case CL_OFFSET_WR:

                                         stabParamsInBytes.offset[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.offset[0] = i2c_slave_buff[1];

                                         break;

                                  case QUAD_GAIN_WR:

                                         stabParamsInBytes.quad_gain[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.quad_gain[0] = i2c_slave_buff[1];

                                         break;

                                  case LIM_OUT_MAX_WR:

                                         stabParamsInBytes.limiter_out_max[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.limiter_out_max[0] = i2c_slave_buff[1];

                                         break;

                                  case LIM_OUT_MIN_WR:

                                         stabParamsInBytes.limiter_out_min[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.limiter_out_min[0] = i2c_slave_buff[1];

                                         break;

                                  case I_GAIN_WR:

                                         stabParamsInBytes.i_gain[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.i_gain[0] = i2c_slave_buff[1];

                                         break;

                                  case P_GAIN_WR:

                                         stabParamsInBytes.p_gain[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.p_gain[0] = i2c_slave_buff[1];

                                         break;

                                  case W_INTEGRATOR_WR:

                                         stabParamsInBytes.w_integrator[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.w_integrator[0] = i2c_slave_buff[1];

                                         break;

                                  case TS_INTEGRATOR_WR:

                                         stabParamsInBytes.ts_integrator[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.ts_integrator[0] = i2c_slave_buff[1];

                                         break;

                                  case LIM_INTEGRATOR_WR:

                                         stabParamsInBytes.limiter_integrator[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.limiter_integrator[0] = i2c_slave_buff[1];

                                         break;

                                  case OUT_SELECT_WR:

                                         stabParamsInBytes.output_select[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.output_select[0] = i2c_slave_buff[1];

                                         break;

                                  case DAC1_VALUE_WR:

                                         stabParamsInBytes.dac1_value[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.dac1_value[0] = i2c_slave_buff[1];

                                         break;

                                  case DAC2_VALUE_WR:

                                         stabParamsInBytes.dac2_value[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.dac2_value[0] = i2c_slave_buff[1];

                                         break;

                                  case SAMPLE_INT_WR:

                                         stabParamsInBytes.sample_interval[1] = i2c_slave_buff[2];

                                         stabParamsInBytes.sample_interval[0] = i2c_slave_buff[1];

                                  break;

 

 

                                  default: TXData = 0x00;

                           }

                           convertParametersToTypes(stabParams);

                     }

              }

 

              if (g_slaveRxIndex == I2C_RD_DATA_LENGTH)

              {

                     //LPI2C_SlaveDisableInterrupts(EXAMPLE_LPI2C_SLAVE_BASEADDR, kLPI2C_SlaveRxReadyFlag | kLPI2C_SlaveAddressValidFlag);

              }

 

    }

 

    if (flags & kLPI2C_SlaveTxReadyFlag)

    {

       EXAMPLE_LPI2C_SLAVE_BASEADDR->STDR = TXData;

 

       #if defined(DEBUG_I2C)

                    PRINTF("TX: 0x%2x ", TXData);

                    PRINTF("\r\n");

              #endif

 

       //LPI2C_SlaveDisableInterrupts(EXAMPLE_LPI2C_SLAVE_BASEADDR, kLPI2C_SlaveTxReadyFlag | kLPI2C_SlaveAddressValidFlag);

 

    }

 

    SDK_ISR_EXIT_BARRIER;

 

}

 

 

0 Kudos
Reply

706 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

I suggest you check the example i2c_interrupt from the KV31 SDK, the functionality is the same as the example from the lpi2c example and it already has the necessary adaptations to work on the i2c module of the KV31.

If you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos
Reply