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 Burst write

Part Number: MSP432E401Y

Tool/software:

I need to write data in eeprom for which i can use Burst write mode. Since i dont have a eeprom right now i'm using another microcontroller as slave.

  MAP_I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, false);
  MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    while(dataIndex < 6)
    {
    
        MAP_I2CMasterDataPut(I2C2_BASE, eeprom_w[dataIndex]);

                     if( (dataIndex < 4))
                     {
                         MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
                     }
                     else if(dataIndex == 4)
                     {
                         MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

                     }
 UARTprintf("eeprom write[%d]= 0x%x\n",  dataIndex, eeprom_w[dataIndex]);
                  dataIndex++;
    }
    dataIndex=0;
                  while(MAP_I2CMasterBusBusy(I2C2_BASE))
                    {
                    }

Expected data eeprom[6] = {0xAA,0xBB,0xCC,0xDD,0xFF,0xEE};

After writing, i tried reading with Burst read mode.
eeprom read[0]= 0xaa
eeprom read[1]= 0xaa
eeprom read[2]= 0xbb
eeprom read[3]= 0xcc
eeprom read[4]= 0xdd
eeprom read[5]= 0xff

 0xaa is repeating twice and last 0xee is missing

Can you please correct me on where i'm missing.

  • Hi,

      Please change the following. I hope it will resolve your issue. 

    FROM:

                      while(MAP_I2CMasterBusBusy(I2C2_BASE))
                        {
                        }

    TO:

                      while(!MAP_I2CMasterBusBusy(I2C2_BASE)) // Add these 3 new lines everywhere where you have the original lines below
                        {
                        }

                      while(MAP_I2CMasterBusBusy(I2C2_BASE)) // You also keep these three original lines. Don't remove them. 
                        {
                        }

  • Hello Charles,

    Thanks for the reply

    I tried as you have mentioned, I see the same issue happening again. Also the code is stuck in the below line.

    while(!MAP_I2CMasterBusBusy(I2C2_BASE)) // Add these 3 new lines everywhere where you have the original lines below
                        {
                        }
  • Perhaps it is because of the UARTprintf. 

    Can you try below. 

    FROM:

    if( (dataIndex < 4))
                         {
                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
                         }
                         else if(dataIndex == 4)
                         {
                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

                         }

    TO:

    if( (dataIndex < 4))
                         {
                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

                             while(!MAP_I2CMasterBusBusy(I2C2_BASE)); // Add this line                   

                             while(MAP_I2CMasterBusBusy(I2C2_BASE)); // Keep this line.
                    

                         }
                         else if(dataIndex == 4)
                         {

                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

                             while(!MAP_I2CMasterBusBusy(I2C2_BASE)); // Add this line                   

                             while(MAP_I2CMasterBusBusy(I2C2_BASE)); // Keep this line.


                         }

  • Hello Charles,

    I tried doing the same but it is getting stuck in the below line itself. I tried to use step over as well, in the very first index itself it is getting stuck there and not coming out of this line.

       while(MAP_I2CMasterBusBusy(I2C2_BASE)); // Keep this line.

    Please guide me on this.

    May be i can share the snippet of the slave code used in other microcontroller

    uint8_t eeprom_data[6] = {0x00,0x00,0x00,0x00,0x00,0x00};

    void I2C2_IRQHandler(void)
    {
        uint32_t getIntStatus;
        uint32_t getStatus;

        // Get the interrupt status and clear the same
        getIntStatus = MAP_I2CSlaveIntStatusEx(I2C2_BASE, true);
        MAP_I2CSlaveIntClearEx(I2C2_BASE, getIntStatus);

        // Get the Status of the data direction
        getStatus = MAP_I2CSlaveStatus(I2C2_BASE);

         //Check if we have a Data Request
        if((getIntStatus & I2C_SLAVE_INT_DATA) == I2C_SLAVE_INT_DATA)
        {
           //  Process data interrupt for the Transmit Path
            if((getStatus & I2C_SLAVE_ACT_RREQ) == I2C_SLAVE_ACT_RREQ)
            {
                //dataIndex=0;
              // data = MAP_I2CSlaveDataGet(I2C2_BASE);
                eeprom_data[dataIndex++] = MAP_I2CSlaveDataGet(I2C2_BASE);

            }

             //Process data interrupt for the Transmit Path by inverting the data
             // before sending it.
            if(getStatus == I2C_SLAVE_ACT_TREQ)
            {
             
                MAP_I2CSlaveDataPut(I2C2_BASE, eeprom_data[dataIndex++]);

                //MAP_I2CSlaveDataPut(I2C2_BASE, ~(getDataBuff[dataIndex++]));
            }
        }

         //Check if we have a Stop condition on the bus
        if((getIntStatus & I2C_SLAVE_INT_STOP) == I2C_SLAVE_INT_STOP)
        {
           //  Clear the index flag
            dataIndex = 0;
        }
    }

    Burst read was working fine only burst write is making this issue.

  • Hi,

      Can you post your revised code again? Only the function that you write to the I2C device is enough. I don't need the rest of your code that is not related to I2C operation.  I want to see if anything missing. 

  • Hello Charles,

    //write to slave

    MAP_I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, false);
    MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    while(dataIndex < 6)
    {

    MAP_I2CMasterDataPut(I2C2_BASE, eeprom_w[dataIndex]);
    if( (dataIndex < 4))
    {
    MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(!MAP_I2CMasterBusBusy(I2C2_BASE));
    while(MAP_I2CMasterBusBusy(I2C2_BASE)); // code is stuck here itself and not moving forward.
    }
    else if(dataIndex == 4)
    {
    MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(!MAP_I2CMasterBusBusy(I2C2_BASE));
    while(MAP_I2CMasterBusBusy(I2C2_BASE));
    }
    UARTprintf("eeprom write[%d]= 0x%x\n", dataIndex, eeprom_w[dataIndex]);

    dataIndex++;
    }
    dataIndex=0;

     for testing purpose, I'm reading it back. Read is working fine, as i'm using this same code for other application as well.


            MAP_I2CMasterSlaveAddrSet(I2C2_BASE, SLAVE_ADDRESS, true);
                  MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
        while(dataIndex < 6)
        {
            MAP_SysCtlDelay(10000);
            eeprom_w_check[dataIndex] = MAP_I2CMasterDataGet(I2C2_BASE);
           // MAP_SysCtlDelay(10000);
                         if( (dataIndex < 4))
                         {
                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
                            // MAP_SysCtlDelay(10000000);
                         }
                         else if(dataIndex == 4)
                         {
                             MAP_I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);

                         }
                         UARTprintf("eeprom read[%d]= 0x%x\n",  dataIndex, eeprom_w_check[dataIndex]);
                      dataIndex++;
        }

    Thanks

  • Hi,

     You have the below line to loop through 6 data elements. However, your condition to call MAP_I2CMasterControl depends on if dataIndex==4 or dataIndex<4.  What happens when dataIndex is 5? 

    while(dataIndex < 6)

      If you have six elements to transmit,  shouldn't you change from dataIndex < 4 to dataIndex < 5 instead and same thing for dataIndex == 4 to dataIndex == 5.