AnsweredAssumed Answered

I2C peripherals

Question asked by Rex Liu on Sep 2, 2019
Latest reply on Sep 10, 2019 by Omar Anguiano

I try to use i2c peripherals.  

 

MCU : LPC51U68

 

Development board : OM40005 

 

SDK : SDK_2.6.0_LPCXpresso51U68.zip

 

when i write data to eeprom and don't "stop" , then read data. it's ok.

 

code as below:

 

if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
//reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, 0x30, 1, kI2C_TransferNoStopFlag);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, 2, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
return -1;
}

//reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


}

//GPIO_PinWrite(GPIO, APP_BOARD_TEST_LED_PORT, APP_BOARD_TEST_LED_PIN, 0);
/* Wait until the slave is ready for transmit, wait time depend on user's case.
Slave devices that need some time to process received byte or are not ready yet to
send the next byte, can pull the clock low to signal to the master that it should wait.*/
for (uint32_t i = 0U; i < WAIT_TIME; i++)
{
__NOP();
}

//GPIO_PinWrite(GPIO, APP_BOARD_TEST_LED_PORT, APP_BOARD_TEST_LED_PIN, 1);

PRINTF("Receive sent data from slave :");

/* Receive blocking data from slave */
/* subAddress = 0x01, data = g_master_rxBuff - read from slave.
start + slaveaddress(w) + subAddress + repeated start + slaveaddress(r) + rx data buffer + stop */
if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
//reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, 0x30, 1, kI2C_TransferNoStopFlag);
//if (reVal != kStatus_Success)
//{
// return -1;
//}

reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, g_master_txBuff, 1, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
return -1;
}

reVal = I2C_MasterRepeatedStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Read);
if (reVal != kStatus_Success)
{
return -1;
}

reVal = I2C_MasterReadBlocking(EXAMPLE_I2C_MASTER, g_master_rxBuff, 1, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
return -1;
}

reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
if (reVal != kStatus_Success)
{
return -1;
}
}

 

 

 

 

 

but  i write data to eeprom and don't "stop" , then write data again. it's fail.

 

code as below:

 

if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
//reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, 0x30, 1, kI2C_TransferNoStopFlag);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, t_master_txBuff, 2, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
return -1;
}

//reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


}

for (uint32_t i = 0U; i < WAIT_TIME; i++)
{
__NOP();
}

if (kStatus_Success == I2C_MasterStart(EXAMPLE_I2C_MASTER, I2C_MASTER_SLAVE_ADDR_7BIT, kI2C_Write))
{
/* subAddress = 0x01, data = g_master_txBuff - write to slave.
start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/
//reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, 0x30, 1, kI2C_TransferNoStopFlag);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


reVal = I2C_MasterWriteBlocking(EXAMPLE_I2C_MASTER, r_master_txBuff, 2, kI2C_TransferDefaultFlag);
if (reVal != kStatus_Success)
{
return -1;
}

//reVal = I2C_MasterStop(EXAMPLE_I2C_MASTER);
//if (reVal != kStatus_Success)
//{
// return -1;
//}


}

for (uint32_t i = 0U; i < WAIT_TIME; i++)
{
__NOP();
}

 

 

 

 

At the beginning of each action, there is a stop command.
When the instrument is used, there is a stop condition.

However, after the experiment,
it is found that there is no stop to finish reading.
However, if there is no stop command,
the data cannot be written and written again.
I confirm the temporary The value of the register is also correct.

 

 

another one.

 

when program run to "I2C_MasterWriteBlocking" funtion. 

in this function, code will run to "base->MSTCTL = I2C_MSTCTL_MSTSTOP_MASK;"

that means it will have stop command. in the logic-analyzer, stop command can be saw.

if add  "I2C_MasterStop" function. there is twice stop command.

 

 

 

 

 

Please help 

experts.

 

Thank you

Rex Liu

 

Attachments

Outcomes