Need LPI2C example

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

Need LPI2C example

Jump to solution
4,206 Views
huaping
Contributor III

Need one LPI2C master mode working example, referring to the example under SD32 installation, it see can send out right data, but get the wrong data when receiving.  This LPI2C module is different with old Freescale MCU.

Thanks a lot!

Labels (1)
0 Kudos
1 Solution
3,225 Views
raresvasile
NXP Employee
NXP Employee

Hi,

Assuming that you want to read a value from an address, in your case 0x8C, you need to modify the code to perform a repeated start instead of a stop-start sequence when writing the code. 

while(1)
{
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = i;
}
buffer[0]=0x8C;
/* Send a packet of data to the bus slave */
LPI2C_DRV_MasterSendDataBlocking(FSL_LPI2C1,buffer,1, false /* Do not send stop after the transfer */, OSIF_WAIT_FOREVER);

/* Clear the buffer to prepare it for the next operation */

/* Request data from the bus slave */
LPI2C_DRV_MasterReceiveDataBlocking(FSL_LPI2C1, buffer, 3, true, OSIF_WAIT_FOREVER);

for(i=0;i<9999;i++);

}

Here is a snip with a read operation of some IC registers(I can confirm the validity of the data, since reading the WHO_AM_I register returned the expected data):

pastedImage_3.png

As for the callback name generation, you should replace in the lpi2c component lpi2c1_MasterCallback0 with NULL to avoid modifying it at every code generation.

Hope that this helps.

Best regards,

Rares

View solution in original post

0 Kudos
11 Replies
3,225 Views
huaping
Contributor III

Dear Rares:

        I can't upload project, so I write one ticket in TIC for help.

        Pls help it!

Thanks!

0 Kudos
3,228 Views
huaping
Contributor III

Dear Bares:

        It's ok now!

        Thanks a lot!

Huaping

0 Kudos
3,228 Views
raresvasile
NXP Employee
NXP Employee

Hi,

Can you attach the project that is receiving wrong data? Also it would be useful to add the expected and received data.

Thank you,

Rares 

0 Kudos
3,228 Views
huaping
Contributor III

Hi, Bares:

     Pls help check my project, I just didn't use interrupt, and change the below codes, masterCallback =0;

const lpi2c_master_user_config_t lpi2c1_MasterConfig0 = {
  .slaveAddress = 127U,
  .is10bitAddr = false,
  .operatingMode = LPI2C_STANDARD_MODE,
  .baudRate = 100000U,
  .baudRateHS = 0U,
  .masterCode = 0U,
  .transferType = LPI2C_USING_INTERRUPTS,
  .masterCallback = 0,//lpi2c1_MasterCallback0,
  .callbackParam = NULL,
};

     Thanks a lot!

0 Kudos
3,226 Views
raresvasile
NXP Employee
NXP Employee

Hi,

Assuming that you want to read a value from an address, in your case 0x8C, you need to modify the code to perform a repeated start instead of a stop-start sequence when writing the code. 

while(1)
{
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = i;
}
buffer[0]=0x8C;
/* Send a packet of data to the bus slave */
LPI2C_DRV_MasterSendDataBlocking(FSL_LPI2C1,buffer,1, false /* Do not send stop after the transfer */, OSIF_WAIT_FOREVER);

/* Clear the buffer to prepare it for the next operation */

/* Request data from the bus slave */
LPI2C_DRV_MasterReceiveDataBlocking(FSL_LPI2C1, buffer, 3, true, OSIF_WAIT_FOREVER);

for(i=0;i<9999;i++);

}

Here is a snip with a read operation of some IC registers(I can confirm the validity of the data, since reading the WHO_AM_I register returned the expected data):

pastedImage_3.png

As for the callback name generation, you should replace in the lpi2c component lpi2c1_MasterCallback0 with NULL to avoid modifying it at every code generation.

Hope that this helps.

Best regards,

Rares

0 Kudos
3,227 Views
huaping
Contributor III

Hi,Rares:

     The project was ok in DS V1.2, now we upgrade to V1.3, and find it is error when compile, then we find it is the reason when add the below code:

 LPI2C_DRV_MasterInit(FSL_LPI2C1, &lpi2c1_MasterConfig0,&lpi2c1MasterState);

     but this is necessary to do initial.

     Would you pls help check my project as attached?

     Thanks!

0 Kudos
3,227 Views
raresvasile
NXP Employee
NXP Employee

Hi Huaping,

Can you attach the log of the failed build?

Best regards,

Rares

0 Kudos
3,227 Views
huaping
Contributor III

Dear Rares:

         May I know what version of DS you are using? V1.2 or V1.3?

         I change masterCallback = NULL, it is ok to compile, but the code always return back at the below codes:

lpi2c_master_state_t *master = g_lpi2cMasterStatePtr[instance];      // I can't find it where is used
if (master == NULL)
{
return LPI2C_STATUS_FAIL;           // it return for here
}

/* mark transfer as blocking */
master->blocking = true;

retVal = LPI2C_DRV_MasterSendData(instance, txBuff, txSize, sendStop);   // can't run here, if I delete the below codes, it will jump to ISR interrupt.

I don't know how to upload the project again, can't find it.

3,227 Views
raresvasile
NXP Employee
NXP Employee

Hi Huaping,

I suggest using S32 DS V1.3 as it is improved.

Are you calling the init function prior to using LPI2C_DRV_MasterSendDataBlocking? It seems that the driver is not initialized(g_lpi2cMasterStatePtr[instance] is configured in Init function).

You can attach the project by clicking on "Use advanced editor" on top-right corner when replying.

Best regards,

Rares

0 Kudos
3,228 Views
huaping
Contributor III

Dear Rares:

         Pls help check my project!

         thanks a lot!


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
3,227 Views
raresvasile
NXP Employee
NXP Employee

Hi Huaping,

Please find attached the project which was updated to fix the reported issues.

I had found the following issues which triggered the unwanted behaviour:

 1)   System OSC source was configured in Clock Manager to use External Reference. If you are using the DEVKIT, the source should be Internal Oscillator, as the input for the clock is retrieved from a crystal oscillator on PTB6 and PTB7 pins.

  2)   Functional clock for LPI2C was configured in PCC to use SPLLDIV2 which was disabled in the Clock Manager  component. Functional clock should be selected from an Async divider which is enabled.

  3) LPI2C baud rate was configured as 0. It should be greater than 0. Also selected pins for LPI2C were PTB7 and PTB6 which are used for Crystal input. I had routed SDA and SCL to PTA2 and PTA3.

Best regards,

Rares

0 Kudos