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.

MSP432E401Y: I2C going into illegal state after sending BURST_START command

Part Number: MSP432E401Y

We have a sensor attached to I2C bus, and we have programmed I2CMSA register with slave address of the sensor. When we are trying to communicate to slave we are sending BURST_START command but in the registers we are getting START, ERROR, STOP and ADRACK all of them set at once while I2C_MCS_RUN remains 0, BUS_IDLE is also 1 (image attached).

Another thing is even after executing MAP_I2CMasterDataPut(I2C2_BASE, data); it is not writing data to I2CMDR register. DMA operation is also disabled.

Please let us know where we are missing.

Thanks and Regards

Raj Johri

  • Hi Raj,

    Can you share a little bit of your code that configures the I2C operation?

  • Hi Dennis,

    I am sharing the initialization and send functions for I2C0 as below, please let me know whats making the bus to go into illegal state and why I2CMDR register is not initialized with the data to be sent. The code has been taken from the examples provided in the SDK. Even we tried to execute the SDK code directly without any modification but the bus goes into illegal state immediately after sending BURST_START command.

    void iot_i2c_init()
    {

    uint32_t systemClock;

    /* Configure the system clock for 120 MHz */
    systemClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
    SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
    120000000);

    /* Enable clocks to GPIO Port B and configure pins as Output */
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)))
    {
    }

    /* Enable clocks to GPIO Port B and configure pins as I2C */
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)))
    {
    }

    MAP_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    MAP_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    MAP_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    MAP_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

    /* Since there are no board pull up's we shall enable the weak internal
    * pull up */
    GPIOB->PUR |= (GPIO_PIN_3 | GPIO_PIN_2);

    /* Initialize the slave address with default transmit mode */
    //MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS|I2C_WR_MODE, false);

    /* Enable the clock to I2C-0 module and configure the I2C Master */
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0)))
    {
    }

    /* Configure the I2C Master in standard mode and enable interrupt for Data
    * completion, NAK and Stop condition on the bus */
    MAP_I2CMasterInitExpClk(I2C0_BASE, systemClock, false);
    MAP_I2CMasterIntEnableEx(I2C0_BASE, I2C_MASTER_INT_NACK |
    I2C_MASTER_INT_STOP |
    I2C_MASTER_INT_DATA);

    /* Initialize the state of the I2C Master */
    setI2CState = I2C_MASTER_IDLE;

    }

    void i2c_send(uint8_t data)
    {

    uint32_t int_status = 0;

    /* Enable I2C-0 master controller */
    MAP_I2CMasterEnable(I2C0_BASE);

    /* initialize the slave address with transmit mode */
    MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS>>1, false);

    /* write data to buffer */
    MAP_I2CMasterDataPut(I2C0_BASE, data);

    /* generate start condition and wait for the bus */
    MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    /* wait until bus is free */
    while(MAP_I2CMasterBusy(I2C0_BASE));

    /* force stop and wait for the condition */
    MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    do {
    int_status = MAP_I2CMasterIntStatus(I2C0_BASE, true);
    }while((int_status & I2C_MASTER_INT_STOP) == I2C_MASTER_INT_STOP);

    /* clear all interrupt flags */
    MAP_I2CMasterIntClearEx(I2C0_BASE, int_status);

    /* disable the master */
    MAP_I2CMasterDisable(I2C0_BASE);

    }

  • Please anybody help on this issue its urgent for our project. Why I2C bus is not working? Is there any issue with the code?

    We have tried to checked with two MSPs also one as master and another as slave as given in the SDK which is also not working and bus is going into illegal state.

    Please help...

  • Hi Raj,

    I really apologize for the delay.  I had to order an MSP432E401 launchpad in order to follow along with what you are seeing.  I receive it tomorrow.

    In the mean time do you have a logic probe or oscilloscope and capture an image of the I2C bus traffic when you see the failure?

  • Hi Dennis,

    Thanks for the reply, the issue has been diagnosed the issue. However I do not know how that happened. These are the modifications we did:

    1. I commented this line to disable the internal pullup:

    GPIOB->PUR |= (GPIO_PIN_3 | GPIO_PIN_2);

    However the bus kept stalling with this also.

    2. I removed bit manipulations wherever in the slave address and changed this line:

    MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS>>1, false); to

    MAP_I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false);

    Now the bus is working fine.

    Thanks and Regards

    Raj Johri

  • Excellent news!

    I'm glad you were able to solve your issue.