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.

TMS570LS3137: I2C 2-byte read command

Part Number: TMS570LS3137


Hello.

(Sensor is TLE493D-A2B6)

The sensor I'm working on works with this protocol.

static void i2c_read_data(uint8_t slave_address, uint8_t *data, uint32_t data_len)
{
    uint8_t register_address = 0x16;

    i2cSetMode(i2cREG1, I2C_MASTER);
    i2cSetCount(i2cREG1, data_len);


    i2cSetSlaveAdd(i2cREG1, slave_address >> 1);
    i2cSetDirection(i2cREG1, I2C_RECEIVER);

    i2cSetStop(i2cREG1);
    i2cSetStart(i2cREG1);


    i2cSendByte(i2cREG1, register_address);

    i2cReceive(i2cREG1, data_len, data);

    /* Wait until Bus Busy is cleared */
    while (i2cIsBusBusy(i2cREG1) == true)
    {
        asm(" nop");
    }

    /* Wait until Stop is detected */
    while (i2cIsStopDetected(i2cREG1) == 0)
    {
        asm(" nop");
    }

    i2cClearSCD(i2cREG1); /* Clear the Stop condition */
}

I tried to send data like the one above, but it didn't I think the i2cSendByte (i2cREG1, register_address); " process is not correct.

May you help me How I get this protocol right?  

  • Hi Fatih,

    I started working on your issue and will try to provide an update ASAP.

    --
    Thanks & regards,
    Jagadish.

  • Hi Fatih,

    What you are trying to do is wrong here:

    I mean you should not send Slave_Address+Read before sending the Trigger_bits+Register address. You should send slave_address+write before sending the Trigger_bits+Register address.

    I don't know from where you got that first pic but i just referred one application note of the Sensor TLE493D-A2B6

    Efficient use of the 2nd generation 3D Hall sensors (infineon.com)

    As you can see in above pic, he is sending slave_address+write before he is sending the Trigger_bits+Register address.

    --

    Thanks & regards,
    Jagadish.

  • Hi, Thank you for your answer, Sorry for my late answer, I was working on another project,

    According to the document you shared, I tried to communicate before, and when I worked on it again, I saw that it really worked correctly.

    The result from Logic Analyzer:

    The code:

    static void i2c_sent_data(uint8_t slave_address, uint8_t *data,
                              uint32_t data_len)
    {
        i2cSetMode(i2cREG1, I2C_MASTER);
        i2cSetCount(i2cREG1, data_len);
    
        i2cSetSlaveAdd(i2cREG1, slave_address >> 1);
        i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
    
        i2cSetStop(i2cREG1);
        i2cSetStart(i2cREG1);
        for (uint32_t i = 0; i < data_len; i++)
        {
            i2cSendByte(i2cREG1, data[i]);
            delay_us(5);
        }
    
        /* Wait until Bus Busy is cleared */
        while (i2cIsBusBusy(i2cREG1) == true)
        {
            asm(" nop");
        }
        /* Wait until Stop is detected */
        while (i2cIsStopDetected(i2cREG1) == 0)
        {
            asm(" nop");
        }
    
        /* Wait until master is ready*/
        while (i2cIsMasterReady(i2cREG1) == 0)
        {
            asm(" nop");
        }
    
        i2cClearSCD(i2cREG1);
    }
    
    static void i2c_read_data(uint8_t slave_address, uint8_t *data,
                              uint32_t data_len)
    {
        i2cSetMode(i2cREG1, I2C_MASTER);
        i2cSetCount(i2cREG1, data_len);
    
        i2cSetSlaveAdd(i2cREG1, slave_address >> 1);
        i2cSetDirection(i2cREG1, I2C_RECEIVER);
        i2cREG1->MDR |= I2C_REPEATMODE;
    
        i2cSetStop(i2cREG1);
        i2cSetStart(i2cREG1);
    
        i2cReceive(i2cREG1, data_len, data);
    
        /* Wait until Bus Busy is cleared */
        while (i2cIsBusBusy(i2cREG1) == true)
        {
            asm(" nop");
        }
    
        /* Wait until Stop is detected */
        while (i2cIsStopDetected(i2cREG1) == 0)
        {
            asm(" nop");
        }
    
        i2cClearSCD(i2cREG1); /* Clear the Stop condition */
    
        i2cREG1->MDR &= ~I2C_REPEATMODE;
    }
    
    static uint8_t i2c_read_register(uint8_t slave_address,
                                     uint8_t register_address)
    {
        uint8_t send_data_buffer[1] = { register_address /* , 0x10 */};
        uint8_t read_data_buffer[1] = { 0x00 };
    
        i2c_sent_data(slave_address, &send_data_buffer[0],
                      sizeof(send_data_buffer));
    
        i2c_read_data(slave_address, &read_data_buffer[0],
                      sizeof(read_data_buffer));
    
        return read_data_buffer[0];        //received_byte;
    
    }

    I should catch the interrupt on SCL pin, How can I use the SCL pin as an interrupt and SCL. May you help me about it. 

  • Hi Fatih,

    I should catch the interrupt on SCL pin, How can I use the SCL pin as an interrupt and SCL. May you help me about it.

    After configuring I2c peripheral, you can generate below interrupts generally.

    But if you want some raising edge or falling edge or both interrupts for SCL line then you can just short the corresponding SCL with one of the GIO input.

    And now in GIO module you can just select the required interrupt edge.

    And also enable GIO interrupt in VIM.

    In this way you can be able to configure and trigger the interrupts for SCL signal.

    --

    Thanks & regards,
    Jagadish.

  • How can I connect the GIO interrupt and the SCL pin together?

    SCL pin is connected here.

  • Hi Fatih,

    You have to physically short the SCL pin with GIO pin along with connecting to slave device.

    For example, if you want to use GIOA[0] for GIO interrupt:

    Then make the connection as below to trigger GIOA[0] interrupt for SCL toggling.

    If you make the connections as above and do the necessary configurations for GIOA[0] interrupt, then you can see interrupt generation for SCL toggling.

    --

    Thanks & regards,
    Jagadish.