Hi, I am quite new to TI's MSPM0G3 series MCU and abit confused about transmitting mutliple bytes (more the max number of 8 TXFIFO) data in I2C Master Controller mode with polling method. Is there any example that I can refer to for this case?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, I am quite new to TI's MSPM0G3 series MCU and abit confused about transmitting mutliple bytes (more the max number of 8 TXFIFO) data in I2C Master Controller mode with polling method. Is there any example that I can refer to for this case?
Hi, Anthony
1. i2c_controller_rw_multibyte_fifo_interrupts
This code example handle 16 bytes and 8 TXFIFOs very well.
You can have a look.
2. i2c_controller_rw_multibyte_fifo_poll
Base on this example, add some code to be compatible with multi-byte(> 8) sending function.
Just add some code after SYSCFG_DL_init(); of i2c_controller_rw_multibyte_fifo_poll.c
I didn't test this code, bug logic should be correct.
SYSCFG_DL_init();
/* Set LED to indicate start of transfer */
DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);
gTxLen = I2C_TX_PACKET_SIZE;
/*
* Fill the FIFO
* The FIFO is 8-bytes deep, and this function will return number
* of bytes written to FIFO */
gTxCount = DL_I2C_fillControllerTXFIFO(I2C_INST, &gTxPacket[0], gTxLen);
/* Wait for I2C to be Idle */
while (!(
DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_IDLE))
;
/* Send the packet to the controller.
* This function will send Start + Stop automatically.
*/
DL_I2C_startControllerTransfer(I2C_INST, I2C_TARGET_ADDRESS,
DL_I2C_CONTROLLER_DIRECTION_TX, gTxLen);
while (gTxCount < gTxLen) {
//Waiting for txfifo empty
while (!(DL_I2C_getRawInterruptStatus(I2C_INST) & DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_EMPTY));
//clear interrupt
DL_I2C_clearInterruptStatus(I2C_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_EMPTY);
//Write more data to I2C FIFO
gTxCount += DL_I2C_fillControllerTXFIFO(I2C_INST, &gTxPacket[gTxCount], gTxLen - gTxCount);
}
/* Poll until the Controller writes all bytes */
while (DL_I2C_getControllerStatus(I2C_INST) &
DL_I2C_CONTROLLER_STATUS_BUSY_BUS)
;
/* Trap if there was an error */
if (DL_I2C_getControllerStatus(I2C_INST) &
DL_I2C_CONTROLLER_STATUS_ERROR) {
/* LED will remain high if there is an error */
__BKPT(0);
}
/* Wait for I2C to be Idle */
while (!(
DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_IDLE))
;
/* Add delay between transfers */
delay_cycles(1000);
Regards,
Helic