I use MSP432 to communicate with a touchpad by I2C. If the write operation is not the first time, I have to write twice to complete a byte write. My code is as follows:
// I2C initialization MAP_I2C_initMaster(TP_I2C_MODULE,&TPConfig); MAP_I2C_setSlaveAddress(TP_I2C_MODULE,0x20); MAP_I2C_setMode(TP_I2C_MODULE,EUSCI_B_I2C_TRANSMIT_MODE); MAP_I2C_enableModule(TP_I2C_MODULE); MAP_I2C_clearInterruptFlag(TP_I2C_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_Interrupt_enableInterrupt(INT_PORT1); MAP_I2C_masterSendMultiByteStartWithTimeout(TP_I2C_MODULE, 0xFF, 10000u); // 1# MAP_I2C_masterSendMultiByteNextWithTimeout(TP_I2C_MODULE, 0x00, 10000u); // 2# MAP_I2C_masterSendMultiByteStopWithTimeout(TP_I2C_MODULE, 10000u); MAP_I2C_masterSendMultiByteStartWithTimeout(TP_I2C_MODULE, 0x34, 10000u); // 3# MAP_I2C_masterSendMultiByteNextWithTimeout(TP_I2C_MODULE, 0x04, 10000u); // 4# MAP_I2C_masterSendMultiByteStopWithTimeout(TP_I2C_MODULE, 10000u);
From the first oscilloscope screenshot, I can see the slave address 0x20, the 1# byte 0xFF and the 2# byte 0x00. But in the second screenshot, I can just see the slave address 0x20 and the 4# byte 0x04. The 3# byte 0x34 is lost. I change the 3# byte to many other values, and the result is still the same. It seems that when I invoke MAP_I2C_masterSendMultiByteStartWithTimeout twice, I will always lose the first byte in the second invoke.
However, if I add MAP_I2C_masterSendMultiByteNextWithTimeout(TP_I2C_MODULE, 0x34, 10000u); after MAP_I2C_masterSendMultiByteStartWithTimeout(TP_I2C_MODULE, 0x34, 10000u);, then I can get the right result. See the sceenshot:
How can that happen?