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