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字节读取命令

Guru**** 2555630 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1253787/tms570ls3137-i2c-2-byte-read-command

器件型号:TMS570LS3137

你好。

(传感器为  TLE493D-A1B6)

我使用的传感器使用该协议。

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 */
}

我试图发送类似上述数据、但我认为 i2cSendByte (i2cREG1、register_address);"过程不正确。

您可以帮助我如何正确使用此协议吗?   

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fatih:

    我已开始处理您的问题、并将尝试尽快提供更新。

    --
    谢谢。此致、
    Jagadish。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fatih:

    您尝试的操作在这里是错误的:

    我的意思是、在发送 Trigger_bits +寄存器地址之前、不应发送 Slave_Address +读取。 在发送触发器位+寄存器地址之前、应发送 slave_address+write。

    我不知道您从何处获得该首款 pic、但我只是参考了 传感器 TLE493D-A2B6的一本应用手册

    高效利用第二代3D 霍尔传感器(infineon.com)

    如上面的 pic 所示、在发送 Trigger_bits+Register 地址之前、他正在发送 slave_address+write。

    --

    谢谢。此致、
    Jagadish。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、 感谢您的回答、抱歉我迟到了、我正在从事另一个项目、

    根据你分享的文件,我以前试图沟通,当我再次处理它,我看到它确实工作正常.

     逻辑分析器的结果:

    代码:

    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;
    
    }

    我应该捕获 SCL 引脚上的中断、如何将 SCL 引脚用作中断和 SCL。 请帮我解决这个问题。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fatih:

    我应该捕捉 SCL 引脚上的中断,如何使用 SCL 引脚作为中断和 SCL。 请您帮我解决这个问题。

    配置 I2C 外设后、您通常可以生成以下中断。

    但是、如果您想要某个上升沿或下降沿、或者同时为 SCL 线设置两个中断、那么您可以用其中一个 GIO 输入短接相应的 SCL。

    现在、在 GIO 模块中、您可以选择所需的中断边沿。

    另外还在 VIM 中启用 GIO 中断。

    通过这种方法、您可以配置和触发 SCL 信号的中断。

    --

    谢谢。此致、
    Jagadish。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    如何将 GIO 中断和 SCL 引脚连接在一起?

    SCL 引脚连接在这里。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Fatih:

    您必须用 GIO 引脚物理上短接 SCL 引脚、并连接到从器件。

    例如,如果要使用 GIOA[0]执行 GIO 中断:

    然后按如下方式进行连接、以触发 SCL 切换的 GIOA[0]中断。

    如果你如上所述进行连接并对 GIOA[0]中断进行必要的配置、那么你可以看到 SCL 切换所产生的中断。

    --

    谢谢。此致、
    Jagadish。