I2C peripherals

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

I2C peripherals

1,910 Views
rex_liu
Contributor I

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.

stop.png

Please help 

experts.

Thank you

Rex Liu

 

Labels (1)
0 Kudos
Reply
3 Replies

1,799 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello Rex Liu

Can you tell which device are you using to receive?

0 Kudos
Reply

1,799 Views
rex_liu
Contributor I

Hello Omar Anguiano

Device : Atmel eeprom - AT24C02.

Thank you

Rex Liu

0 Kudos
Reply

1,799 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello rex.liu@sacsys.com.tw

I suggest you to verify the driver functioning; to do this please use other board to check if the problem persist. If you don't have any other available board you can use I2C0 to interconnect the modules inside the board.

 

Let me know if this is helpful.

Best regards,

Omar

0 Kudos
Reply