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.

[参考译文] PROCESSOR-SDK-AM62X:I2C 测试

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

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1193445/processor-sdk-am62x-i2c-test

器件型号:PROCESSOR-SDK-AM62X

您好!

我正在尝试在 am62x 上测试 i2c 读取和写入。

这是我正在使用的代码。

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>

#define I2C_SLAVE     0x51
typedef struct {
	/*
	 * The I2C Bus number that the device is connected to
	 */
	int bus;
	/*
	 * The slave address of the I2C device
	 */
	unsigned int slave_addr;
	/*
	 * The address of the register we want to access
	 */
	char *reg;
	/*
	 * Number of bytes in the register address
	 */
	int reg_size;
	/*
	 * Data buffer to transfer with the register
	 */
	char *buf;
	/*
	 * Number of data bytes to transfer
	 */
	int buf_size;
} i2c_test_st;


int main(int argc, char **argv)
{
        i2c_test_st i2c_test;
        int i2c_file;
        char reg[1];
        char buf[2];
        int fail = 0;

        printf("\nI2C test!\n");

        i2c_file = open("/dev/i2c-0", O_RDWR);
        if (i2c_file < 0) {
                printf("Open failed\n");
                exit(-1);
        }

        /* Enable the CSI clock */
        ioctl(i2c_file, 3, &i2c_test);

        i2c_test.bus = 0;
        i2c_test.slave_addr = 0x51;

        printf("Slave address=0x%x\n\n", i2c_test.slave_addr);

        reg[0] = (0x100 >> 8) & 0xff;
        reg[1] = 0x100 & 0xff;
        buf[1] = 0x4;
        buf[0] = 0x0;
        i2c_test.reg = reg;
        i2c_test.reg_size = 2;
        i2c_test.buf = buf;
        i2c_test.buf_size = 2;

        printf("Data write: buf[0]=%x, buf[1]=%x to reg[0]=%x reg[1]=%x\n", buf[0], buf[1], reg[0], reg[1]);
        ioctl(i2c_file, 2, &i2c_test);

        buf[0] = 0;
        buf[1] = 0;
        i2c_test.buf = buf;
        ioctl(i2c_file, 1, &i2c_test);

        if (i2c_test.buf[0] != 0x0) {
                fail = 1;
        }

        if ((i2c_test.buf[1] & 0x4)!= 0x4) {
                fail = 1;
        }
        printf("Data read: buf[0]=%x, buf[1]=%x from reg=%x\n", buf[0], buf[1], reg[0]);

        if (fail == 1) {
                printf("\nI2C TEST FAILED\n\n");
        } else {
                printf("\nI2C TEST PASSED\n\n");
        }

        /* Disable the CSI clock */
        ioctl(i2c_file, 4, &i2c_test);

        close(i2c_file);

        return 0;
}

但是、当我回读时、我一直得到0。

所有内核配置都是正确的、因为我已经使用 shell 脚本进行了测试、并且能够回读。

以下是脚本。

address=0x01
address2=4
temp=0
data=0x01
bus=0
eeprom=0x51
#Loop through the addresses

for (( i=0; i<10; i++ ))
do
#Increment the address by 1

int_value=$address2
int_value=$((int_value + 1))
address2=$int_value
temp=$(printf "%x" $int_value)

i2cset -y $bus $eeprom $address 0x$temp $data i

i2ctransfer -y 0 w2@0x51 $address 0x$temp r1 >/dev/null

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

    是否有任何更新?

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

    您好、Cyra、

    感谢您的 Ping 操作。 今天我没有时间查看您的帖子、但我想确保您在本周结束前收到回复。 如果我在周五早上没有回复、请再次 ping 通该主题、以确保这一点再次出现在我的雷达上。

    此致、

    Nick

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

    是否有更新?

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

    自上次更新以来、已经有几天了。

    是否有任何更新?

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

    您好、Cyra、

    在此对延迟回复表示歉意。 我已经使用命令行参数运行了测试、但一旦我们确定 I2C 正常工作、我就无法支持 Linux 用户空间应用程序开发。

    此致、

    Nick

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

    您好、Nick、

    您是否使用 c 代码而不是命令行对其进行了测试?

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

    您好、Cyra、

    否、目前我还没有体验过 I2C 的任何应用开发。

    此致、

    Nick