Hi,
Iam working on I2c communication with LP5024 LED.
K22 will be the master and need to communicate with LP5024 slave.
I2C SDK driver : downloaded from https://mcuxpresso.nxp.com/en/builder#
Iam able to Initialize I2C via I2C_MasterInit API and I2C_MasterStart, I2C_MasterTransferBlocking calls were successful
Issue is that iam not seeing clock signal in oscilloscope. Am i missing anything? Below is the code i used for I2C master. Kindly go through and advise me how to proceed with this issue.
Please suggest.
status_t result = kStatus_Success;
I2C_MemMapPtr base = I2C0_BASE_PTR;
i2c_master_config_t masterConfig = {0};
I2C_MasterGetDefaultConfig(&masterConfig);
uint8 status;
I2C_MasterInit(base, &masterConfig, 100000U);
/* Clear all status before transfer. */
I2C_MasterClearStatusFlags(base, (uint32_t)(kClearFlags));
/* Clear pending flag. */
base->S = (uint8_t)kI2C_IntPendingFlag;
result = I2C_MasterStart(base, 0x00, kI2C_Write);
if (0 != result)
{
result = kStatus_Fail;
}
/* Wait address sent out. */
if(!((status = I2C_MasterGetStatusFlags(base)) & kI2C_IntPendingFlag))
{
}
if(status & kI2C_ReceiveNakFlag)
{
}
/* Enable module interrupt. */
I2C_EnableInterrupts(base, kI2C_GlobalInterruptEnable);
result = kStatus_Success;
result = I2C_MasterWriteBlocking(base, txBuff, BUFFER_SIZE, kI2C_TransferNoStopFlag);
if (result)
{
I2C_MasterStop(base);
}
Regards,
SK
Thanks Alexis.
Issue resolved.
Regards,
Sendhil
Thanks Alexis.
Yes, i updated the Board_InitPins as below:
With some added code, iam able to see the SDA pin going low when START signal is sent from I2C_MasterStart
void BOARD_InitPins(void) { /* Port E Clock Gate Control: Clock enabled */ CLOCK_EnableClock(kCLOCK_PortE); /* PORTE24 (pin 31) is configured as I2C0_SCL */ PORT_SetPinMux(PORTE_BASE_PTR, 24U, kPORT_MuxAlt5); PORTE_BASE_PTR->PCR[24] = ((PORTE_BASE_PTR->PCR[24] & (~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_ODE_MASK | PORT_PCR_ISF_MASK))) | (uint32_t)(kPORT_PullUp) | PORT_PCR_ODE(kPORT_OpenDrainDisable)); /* PORTE25 (pin 32) is configured as I2C0_SDA */ PORT_SetPinMux(PORTE_BASE_PTR, 25U, kPORT_MuxAlt5); PORTE_BASE_PTR->PCR[25] = ((PORTE_BASE_PTR->PCR[25] & (~(PORT_PCR_PS_MASK | PORT_PCR_PE_MASK | PORT_PCR_ISF_MASK))) | (uint32_t)(kPORT_PullUp)); const port_pin_config_t porte24_pin31_config = { kPORT_PullUp, /* Internal pull-up resistor is enabled */ kPORT_FastSlewRate, /* Fast slew rate is configured */ kPORT_PassiveFilterDisable, /* Passive filter is disabled */ kPORT_OpenDrainEnable, /* Open drain is enabled */ kPORT_LowDriveStrength, /* Low drive strength is configured */ kPORT_MuxAlt5, /* Pin is configured as I2C0_SCL */ kPORT_UnlockRegister /* Pin Control Register fields [15:0] are not locked */ }; /* PORTE24 (pin 31) is configured as I2C0_SCL */ PORT_SetPinConfig(PORTE_BASE_PTR, 24U, &porte24_pin31_config); const port_pin_config_t porte25_pin32_config = { kPORT_PullUp, /* Internal pull-up resistor is enabled */ kPORT_FastSlewRate, /* Fast slew rate is configured */ kPORT_PassiveFilterDisable, /* Passive filter is disabled */ kPORT_OpenDrainEnable, /* Open drain is enabled */ kPORT_LowDriveStrength, /* Low drive strength is configured */ kPORT_MuxAlt5, /* Pin is configured as I2C0_SDA */ kPORT_UnlockRegister}; /* Pin Control Register fields [15:0] are not locked */ /* PORTE253 (pin 32) is configured as I2C0_SDA */ PORT_SetPinConfig(PORTE_BASE_PTR, 25U, &porte25_pin32_config); }
It is waiting in while loop on I2C_MasterTransferBlocking
#if I2C_WAIT_TIMEOUT ... #else /* Wait until data transfer complete. */ while (0U == (base->S & (uint8_t)kI2C_IntPendingFlag)) { } #endif
this is my main code: Kindly advise if iam missing anything
void i2c_init()
{
uint8 status;
status_t result = kStatus_Success;
I2C_MemMapPtr *i2cch = I2C0_BASE_PTR;
i2c_master_config_t masterConfig = {0};
masterConfig.baudRate_Bps = I2C_BAUDRATE;
i2c_master_transfer_t masterXfer;
BOARD_InitPins();
I2C_MasterGetDefaultConfig(&masterConfig);
I2C_MasterInit(i2cch, &masterConfig, 36864000);
I2C_Enable(i2cch, false);
I2C_Enable(i2cch, true);
/* Clear pending flag. */
i2cch->S = (uint8_t)kI2C_IntPendingFlag;
result = I2C_MasterStart(i2cch, 0x28U, kI2C_Write);
if (0 != result)
{
result = kStatus_Fail;
}
/* Wait address sent out. */
if(!((status = I2C_MasterGetStatusFlags(i2cch)) & kI2C_IntPendingFlag))
{
}
if(status & kI2C_ReceiveNakFlag)
{
}
/* Enable module interrupt.*/
I2C_EnableInterrupts(i2cch, kI2C_GlobalInterruptEnable);
result = kStatus_Success;
uint8_t g_master_txBuff[I2C_DATA_LENGTH];
memset(&g_m_handle, 0, sizeof(g_m_handle));
/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
uint8_t deviceAddress = 0x28U;
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Write;
masterXfer.subaddress = (uint32_t)deviceAddress;
masterXfer.subaddressSize = 1;
masterXfer.data = g_master_txBuff;
masterXfer.dataSize = I2C_DATA_LENGTH;
masterXfer.flags = kI2C_TransferDefaultFlag;
result = I2C_MasterTransferBlocking(i2cch, &masterXfer);
if (result)
{
I2C_MasterStop(i2cch);
}
}
Hi Sendilkumar,
The pin initialization looks good but after checking your code I saw that this sentences are repeated:
/* Clear pending flag. */
i2cch->S = (uint8_t)kI2C_IntPendingFlag;
result = I2C_MasterStart(i2cch, 0x28U, kI2C_Write);
if (0 != result)
{
result = kStatus_Fail;
}
/* Wait address sent out. */
if(!((status = I2C_MasterGetStatusFlags(i2cch)) & kI2C_IntPendingFlag))
{
}
if(status & kI2C_ReceiveNakFlag)
{
}
/* Enable module interrupt.*/
I2C_EnableInterrupts(i2cch, kI2C_GlobalInterruptEnable);
result = kStatus_Success;
This process is already done in the I2C_MasterTransferBlocking so you wouldn't need it for it.
If you want to enable the interruption I will suuggest to check the example frdmk22f_i2c_interrupt_b2b_transfer_master.
Best Regards,
Alexis Andalon
Hi Sendhilkumar,
Did you have in count the initialization of the pin? For example, in the SDK example, in the BOARD_InitPins API the I2C are initialized so I will suggest to check this function.
Also, I saw that you're using a simplified version of the I2C_MasterWriteBlocking/I2C_MasterWriteNonBlocking but you're omitting some flags that could be need it for the proper functionality of the module so I will suggest to use this two functions instead.
Let me know if this helps you.
Best Regards,
Alexis Andalon