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.

MSPM0G3507: failure to complete I2C transaction

Part Number: MSPM0G3507

Hi,

I am trying to use the LaunchPad to talk to an I2C device through I2C bus.

When sending out the slave address with a command byte, the slave acknowledged the slave address, but the clock for data byte's ACK/NACK is missing. What might be the cause?

Below is the signals of SCL and SDA on the scope when submitting the command 0x03 to the slave with address 0x57. The SDK goes low forever and the bus status goes busy and stays busy.

image.png

Any input would be helpful. Thanks!

Crane

 

 

  • I found a abnormal glitch from the waveform:

    This shouldn't comes from normal I2C operation, recommended to add timeout function in I2C module, to reset I2C if abnormal situation happens.

  • Thanks Helic for your input and reference code.

    It looks the shorter 9th clock for ACK/NACK is abnormal. As the glitch occurs at the 9th clock for ACK/NACK and everything is controlled by the I2C controller until the glitch occurs, where to add the timeout do you think would help?

    In terms or resetting I2C, as this happens all the time, I don't think it would make the next transfer work to reset I2C afterwards.

    I read the reference code and it uses the interrupt to get the bus status instead of polling the registers. The part of transferring the command byte is the same. I tried this way, and the result of sending out the command byte is the same.

    So what might cause the glitch? Is it possible that the timing from the MCU doesn't match the timing of this specific device? Or any other causes?

    Thanks!

    Crane

  • I found this. When sending only the valid slave address, the 9th clock is shortened. When sending only the invalid slave address, the 9th clock is normal, not shortened. What does this say?

    The waveform when sending valid slave address 0x57

    The waveform when sending invalid slave address 0x56

  • I tried this way, and the result of sending out the command byte is the same.
    I don't think it would make the next transfer work to reset I2C afterwards.

    Turns out this happens all the time, need to figure out root cause.

    When sending only the invalid slave address, the 9th clock is normal, not shortened. What does this say?

    I2C SCLK line will mainly controlled by controller.

    But with clock stretch feature, SCLK line will also pull to 0 by Target.

    Since only valid address' ACK/NACK bit clk will be pulldown, it seems this behavior comes from I2C target.

    Attach a normal I2c waveform as your ref

  • But by referring to following the first waveform from your side, following transmit is still ongoing, so this ACK should be valid.

    The waveform when sending valid slave address 0x57

    But somehow this kind of glitch maybe, makes M0 I2C status abnormal.

    You can try to debug the project and try to catch I2C register level info for further debug.

  • Can you post the code which starts this transaction?

    I expect you would see this result if (somehow) the transaction were started without I2C_MCTR_STOP_MASK being set. That bit is set automatically by DL_I2C_startControllerTransfer(), but not (automatically) by DL_I2C_startControllerTransferAdvanced().

    In the case of a NACK, the Stop is always issued, regardless of that bit setting.

  • Attached is the code used.

    Tried the advanced transfer function as well as reading bytes needs it. The result is the exactly the same (The bus gets stuck after the first data byte).

    static int32_t drvI2c_sendBytes(i2cHandle_type *handler, uint8_t *data, uint32_t len)
    {
        /*
         * Fill FIFO with data. This example will send a MAX of 8 bytes since it
         * doesn't handle the case where FIFO is full
         */
        while(0U != DL_I2C_fillControllerTXFIFO(handler->i2cBase, data, (uint16_t)len))
            ;
    
        /* Wait for I2C to be Idle */
        while (!(
            DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_IDLE))
            ;
    
        /* Send the packet to the controller.
         * This function will send Start + Stop automatically.
         */
        DL_I2C_startControllerTransfer(handler->i2cBase, handler->dev_addr,
            DL_I2C_CONTROLLER_DIRECTION_TX, (uint16_t)len);
        dPrintf("\r\n1. MSR 0x%X", handler->i2cBase->MASTER.MSR);
    
        /* Poll until the Controller writes all bytes */
        while (DL_I2C_getControllerStatus(handler->i2cBase) &
               DL_I2C_CONTROLLER_STATUS_BUSY_BUS)
            ;
    
        dPrintf("\r\n2. MSR 0x%X", handler->i2cBase->MASTER.MSR);
        /* Trap if there was an error */
        if (DL_I2C_getControllerStatus(handler->i2cBase) &
            DL_I2C_CONTROLLER_STATUS_ERROR) {
            dPrintf("\r\nError - MSR 0x%X", handler->i2cBase->MASTER.MSR);
            if((DL_I2C_CONTROLLER_SCL_LOW == DL_I2C_getSDAStatus(i2cHandler.i2cBase))
                    || (DL_I2C_CONTROLLER_SCL_LOW == DL_I2C_getSCLStatus(i2cHandler.i2cBase))) {
                dPrintf("\tBus error: SDA or SCL low!");
                //__BKPT(0);
                return -1;
            }
            else {  ; }
        }
    
        /* Wait for I2C to be Idle */
        while (!(
            DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_IDLE))
            ;
    
        return 0;
    }

  • When lowering the speed from 100KHz to 50KHz, it works fine to finish the transfer. The signals on the scope looks fine as below (correct data 0x33 follows the repeated start), but the RXFIFO is empty. What might cause the empty RX FIFO?

    As it seems not stable (still fails about 10% the time). I am trying to lower the speed further. For BUSCLK which is 32MHz, the lowest speed is 40K, or 30K but warned. When trying to use MFCLK instead of BUSCLK, although it is initialized as below in clock config, selecting it in I2C configuration causes the error of "not initialized":

    Why it is like this? How to lower the speed then?

    Thanks!

    Crane

  • Another possibility is that the slave is holding SDA low, i.e. it never passed SDA back to the master after the ACK cycle. (This would presumably imply a slave-side malfunction, so I didn't want to mention it first.)

    What slave device are you talking to?

  • I haven't seen a case where a properly-read byte doesn't make it into the FIFO. Are you fairly sure you're waiting for the transaction to complete?

    [Edit: More specifically: check Erratum I2C_ERR_13 [ref Errata (SLAZ742F) p. 16]. A call to dPrintf will presumably introduce enough delay, but it has to be placed properly.]

  • Reading from RX FIFO is fixed now. Probably the interrupt gets the data before polling it. Once the interrupt is disabled, reading is fine.

    The only left issue is that it occasionally fails in reading a byte which requires repeated START and very rarely fails in writing a byte. And it always fails when running from IDE. The slave device is BCM6135, a voltage converter. 

    And as long as there is a delayed clock for ACK, the next byte would not have a clock for ACK so that the bus get busy. The delayed clock for ACK could occur after slave byte, after first data byte or after repeated START and slave byte. And it is confirmed that the delayed clock is caused by the slave device.

    Any idea on what might cause this?

    Thanks!

    Crane

  • It is finally addressed by enabling clock stretching. 

    Thank you all for your help!

    Crane

  • Hello,

    The datasheet says the I2C is compliant to PMBus. 

    I suppose it includes the PMBus v1.3.1, right? Just would like to confirm.

    And if the reading shows below results in block reading:

    1. gets all 0xFF, which are not as specified in the spec;

    2. for one 18-byte block, gets first 9 bytes whose values are as specified in the spec, but the remaining 9 bytes all 0xFF, which are not as specified in the spec;

    3. gets the extra byte for PEC, which is correct according to the slave address+W, byte count and byte values;

    4. byte counts are all correct. 

    Is it possible that something might go wrong with the communication or it can be confirmed that the slave intentionally sends these data?

    Thanks!

    Crane