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.

TMS570LC4357: i2c 通讯问题

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

我在HALCOgen上面配置了i2c1 的寄存器。

/** - set i2c mode */
i2cREG1->MDR = (uint32)((uint32)0U << 15U) /* nack mode */
| (uint32)((uint32)0U << 14U) /* free running */
| (uint32)((uint32)0U << 13U) /* start condition - master mode only */
| (uint32)((uint32)1U <<11U) /* stop condition */
| (uint32)((uint32)1U <<10U) /* Master/Slave mode */
| (uint32)((uint32)I2C_TRANSMITTER) /* Transmitter/receiver */
| (uint32)((uint32)I2C_7BIT_AMODE) /* xpanded address */
| (uint32)((uint32)0U << 7U) /* repeat mode */
| (uint32)((uint32)0U << 6U) /* digital loopback */
| (uint32)((uint32)0U << 4U) /* start byte - master only */
| (uint32)((uint32)0U << 3U) /* free data format */
| (uint32)((uint32)I2C_8_BIT); /* bit count */

参照HALCoGen 的示例编写了i2c 读写接口,但是通讯的情况并不理想。

i2cSetSlaveAdd()的作用是什么?

能否提供更为详尽的i2c示例或者相关文档?

  • Hi,

    With I2C, we can connect multiple slaves to a single master, or we can have multiple masters and multiple slaves in the network. So the i2C address of target device is required in mI2C message.

    The I2C message is broken up into frames of data. Each message has an address frame that contains the binary address of the slave, and one or more data frames that contain the data being transmitted. The message also includes start and stop conditions, read/write bits, and ACK/NACK bits between each data frame.

    i2cSetSlaveAdd() function is to tell the I2C controller the address of the device it will communicate with. 

    What is the problem with your I2C communication? Can I have more details?

  • 首先,在No-FDF mode, 

    i2cREG1->MDR |= (uint32)(1 << 9 | 1 << 10); // send & master
    i2cREG1->MDR &= ~(uint32)(1 << 15); // ACK

    i2cSetStop(i2cREG1);
    i2cSetCount(i2cREG1, 1);
    i2cSetStart(i2cREG1);
    i2cSetSlaveAdd(i2cREG1, 0x38);
    i2cSendByte(i2cREG1, 0x70);

    while(!i2cIsTxReady(i2cREG1));  // 一直在这里等待, STR register = 1406

    我按照上述的代码发送, start信号之后就会发slave address字段吗? 发现没有address相应,并且i2C 波形不规范,成尖峰状,SCL这之后一致拉低

    我使用的是TMS570 LC4357 HDK 板子的B2 C3,i2c1, HDK3.3V 上拉10K电阻,你能帮我看一下可能存在的问题吗

  • 但是我把i2c速度从100khz,降到了10khz, 相应的slave address 波形正常输出了, i2c 100KHz 不能支持10K上拉电阻吗?

    另外, 为什莫寻址没有得到ACK之后, SCL总线一直拉低

  • 我按照上述的代码发送, start信号之后就会发slave address字段吗?

    i2cSetSlaveAdd(i2cREG1, 0x38); should be called before i2cSetStart().

     i2cSetStart() will transmit start bit, slave address. 

  • 但是我把i2c速度从100khz,降到了10khz, 相应的slave address 波形正常输出了, i2c 100KHz 不能支持10K上拉电阻吗?

    另外, 为什莫寻址没有得到ACK之后, SCL总线一直拉低

  • Hi,

    The maximum pullup resistance is limited by the bus capacitance (Cb ). The maximum capacitance of I2C bus is 400pF which is specified in I2C spec. The I2C signal trace on HDK and I2C pin has small capacitances. Circuit traces on a PCB with a ground and power plane will be about 1~3 pF/inch, and low capacitance cables are about 20−30 pF/ft conductor to shield. I assume the total capacitor of the I2C wire (clk and data) is 200pF. 

    The maximum pullup resistance is a function of the maximum rise time (tr ):

    Rp(max) = tR/(0.8473*Cb) 

    For standard I2C mode (100KHz), the maximum rise time is 1us (1/5 of I2CLK pulse width):

    Rp(max) = 1us/(0.8473*200pF) = 5.9 Kohms.

    The bigger the I2C load capacitance is, the smaller the Rp should be. 

    If the pull-up resistor is too large, the signals can become too slow to reach HIGH and LOW. In practice, start with something like 4.7 kΩ, and look at the I2C signals with an oscilloscope; if the rising edges are rounded off too much, you need smaller resistors. 

    https://www.ti.com/lit/an/slva689/slva689.pdf

  • 该问题已经得到解决, 出错的原因有两点, 一个是阻值太大, 改用4.7K, 还有是外接i2c设备需要使用阻值小的单芯线,而不是普通的杜邦线,以避免线路阻值的影响