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.

MSP430FR2476: EusciB-I2c - first byte not transmitted starting from second transmission

Part Number: MSP430FR2476

Hi everyone,

thanks to Bruce's help I am progressing in my project, but I still sometime face issues which are a bit weird.

Now, the problem I am having in this moment is that for some reason, my I2C register write function stops working

properly if I call it more than once. 

I go in the details: to communicate with the device I am using (an ST25DV), I need to send on I2C the following structure

I2CADDRESS | REG_MSB | REG_LSB | DATA_1 | ... | DATA_n | STOP

Essentially, I need to transmit 2 bytes of register address and 1...n bytes of data to write in the register. So far so good.

To do so, I wrote this function based on the EUSCI_I2C driverlib

int ST25DV_register_write(uint8_t * dataBytes, uint16_t memAddress, uint8_t numberOfBytes, uint8_t device_address)
{
    //Specify slave address
    EUSCI_B_I2C_setSlaveAddress(EUSCI_B1_BASE,
        device_address
        );

    //Set in transmit mode
    EUSCI_B_I2C_setMode(EUSCI_B1_BASE,
        EUSCI_B_I2C_TRANSMIT_MODE
        );

    //Enable I2C Module to start operations
    EUSCI_B_I2C_enable(EUSCI_B1_BASE);

    __delay_cycles(1000);
    //Send single byte data.
    EUSCI_B_I2C_masterSendMultiByteStart(EUSCI_B1_BASE,
                                         memAddress >> 8);

    EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE,
                                        memAddress & 0xFF
        );
    while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0)) /*EMPTY*/; // Wait for shift register to finish

    uint8_t totalSent = 0;
    while (totalSent < numberOfBytes - 1)
    {
        EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE,
                                            dataBytes[totalSent]
            );
        totalSent++;
    }
    EUSCI_B_I2C_masterSendMultiByteNext(EUSCI_B1_BASE,
                                        dataBytes[totalSent]
        );

    while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0))
        EUSCI_B_I2C_masterSendMultiByteStop(EUSCI_B1_BASE);
    while (!EUSCI_B_I2C_getInterruptStatus (EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0))

    EUSCI_B_I2C_disable(EUSCI_B1_BASE);

    return 0;
}

The initial setup of the I2C (speed, pins etc.) is done once at the beginning.

Now, let's say I want to write "0xA0" in register 0x0000. If this is the first call to the write_register function, I obtain the correct trace reported in the screenshot below.

 

If I want to do the same operation, but AFTER I already called the write_register function to write something else, this is the trace I get

As you can see, the first byte of the address is missing. 

In a previous discussion here (

MSP430FR2476: Driverlib: Eusci_B I2C multibyte transmission not working - MSP low-power microcontroller...

e2e.ti.com
Part Number: MSP430FR2476 Hello again, I am having a pretty hard time with this I2C, I am glad this forum is so helpful. So here is my new issue. Thanks to
)

it was suggested to wait for the transmission to end before sending the next byte, and as you can see in the code this is what I am doing.

I tried different combinations of the driverlib functions (for example using a sendNextByte and then sending a Stop at the end of the transmission), 

but I obtain always the same wrong behaviour. I also tried to insert a delay_cycles before staring a new I2C transmission but again, with no luck.

Thanks in advance for the help and have a nice day!

Lorenzo

  • Hi Lorenzo,

    looking into the previous thread, I see nobody has pointed you to our application report, dedicated to debugging of serial communication. So I am sending you the link on it. Maybe it will help you not only on this instance of I2C debugging.

    Best regards

    Peter

**Attention** This is a public forum