Part Number: MSPM0G1505
Tool/software:
Dear Ti teams,
I want to get some info from MSPM0G1505 through I2C.
Now I can successfully get the response from MSPM0G1505, but it seems I got the last time TX buffer.
For example, I send 0x1, I want to receive 0x1, but I receive 0x00 the first time, unless I send 0x1 again, then I receive 0x1.
Then, I send 0x2, I hope to receive 0x2 0x1 the first time, but I still receive 0x1, unless I send it again.
The same issue occurs when sending 0x1 0x2, it seems I always get the TX buffer from the last time. I want to know why and how to optimize my code.
I have uploaded the logs and some key parts of the code. Could you help to review if there are any issues?

void I2C_0_INST_IRQHandler(void)
{
static bool dataRx = false;
switch (DL_I2C_getPendingInterrupt(I2C_0_INST))
{
case DL_I2C_IIDX_TARGET_START:
// Initialize RX or TX after Start condition is received
//gTxCount = 0;
gRxCount = 0;
// Flush TX FIFO to refill it
//DL_I2C_flushTargetTXFIFO(I2C_0_INST);
break;
case DL_I2C_IIDX_TARGET_RXFIFO_TRIGGER:
// Store received data in buffer
dataRx = true;
while (DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST) != true)
{
uint8_t receivedData = DL_I2C_receiveTargetData(I2C_0_INST);
if (gRxCount < gRxLen)
{
gRxPacket[gRxCount++] = receivedData;
}
else
{
DL_I2C_receiveTargetData(I2C_0_INST);
}
}
break;
case DL_I2C_IIDX_TARGET_TXFIFO_TRIGGER:
// Fill TX FIFO if there are more bytes to send
if (gTxCount < gTxLen)
{
//gTxCount += DL_I2C_fillTargetTXFIFO(I2C_0_INST, gTxPacket, gTxLen);
gTxCount += DL_I2C_fillTargetTXFIFO(I2C_0_INST, &gTxPacket[gTxCount], (gTxLen - gTxCount));
}
else
{
//
// Fill FIFO with 0x00 if more data is requested than
// expected gTxLen
//
while (DL_I2C_transmitTargetDataCheck(I2C_0_INST, 0x00) != false);
}
break;
case DL_I2C_IIDX_TARGET_STOP:
// If data was received, echo to TX buffer
if (dataRx == true)
{
if(gRxPacket[0] == 0x1)
{
if(gRxPacket[1] == 0x2)
{
gTxPacket[0] = 0xf;
gTxPacket[1] = 0x4;
gTxLen = 2;
DL_I2C_flushTargetTXFIFO(I2C_0_INST);
}
else
{
gTxPacket[0] = 0x1;
gTxLen = 1;
DL_I2C_flushTargetTXFIFO(I2C_0_INST);
}
}
if(gRxPacket[0] == 0x2)
{
gTxPacket[0] = 0x2;
gTxPacket[1] = 0x1;
gTxLen = 2;
DL_I2C_flushTargetTXFIFO(I2C_0_INST);
}
if(gRxPacket[0] == 0x3)
{
uint16_t temp_vgs1 = 500; //500 = -3.87V
DL_Timer_setCaptureCompareValue(PWM_1_INST, temp_vgs1, GPIO_PWM_1_C1_IDX); //PWM_Vgs_PA0(10) Vgs-PA0
DL_Timer_setCaptureCompareValue(PWM_2_INST, temp_vgs1, GPIO_PWM_2_C0_IDX); //PWM_Vgs_PA1(11) Vgs-PA1
DL_Timer_setCaptureCompareValue(PWM_0_INST, temp_vgs1, GPIO_PWM_0_C3_IDX); //PWM_Vgs_PA2(14) Vgs-PA2
DL_Timer_setCaptureCompareValue(PWM_0_INST, temp_vgs1, GPIO_PWM_0_C1_IDX);
gTxPacket[0] = 0x6;
gTxLen = 1;
}
//DL_I2C_flushTargetTXFIFO(I2C_0_INST);
gTxCount = 0;
dataRx = false;
//cleanRxPacket();
}
// Toggle LED to indicate successful RX or TX
// DL_GPIO_togglePins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
break;
case DL_I2C_IIDX_TARGET_RX_DONE:
// Not used for this example
case DL_I2C_IIDX_TARGET_RXFIFO_FULL:
// Not used for this example
case DL_I2C_IIDX_TARGET_GENERAL_CALL:
// Not used for this example
case DL_I2C_IIDX_TARGET_EVENT1_DMA_DONE:
// Not used for this example
case DL_I2C_IIDX_TARGET_EVENT2_DMA_DONE:
// Not used for this example
default:
break;
}
