字节范式C库的使用

发布于 2024-12-15 06:26:05 字数 1893 浏览 2 评论 0原文

我想将 I2C C 库用于“字节范例”I2C 表达设备。这是字节范例网站中提供的示例 API。

//
// Executing I2C write transfer    
//
pDataWr[0] = 0x12;
pDataWr[1] = 0x34;
printf("\nWriting 0x%02X to address 0x%02x...\n", pDataWr[1], pDataWr[0]);
i2c_CmdBufAppend(2, 0x50, 1, 2, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                             // Address = 0x50
                                                             // AddrType = 1  : 7-bit address
                                                             // Length = 2    : 2 byte payload
                                                             // pDataWr       : buffer with 2 bytes payload (0x1234)
                                                             // STA = true    : generate start
                                                             // STO = true    : generate stop

i2c_RunMaster();
i2c_CmdBufDeleteAll();

这意味着什么?它写的是什么以及在哪里?它与下面给出的 API 有什么不同?

//
// Executing dummy write to set EEPROM address
//
printf("\nExecuting dummy write to set EEPROM address...\n");
pDataWr[0] = 0x12;
i2c_CmdBufAppend(2, 0x50, 1, 1, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                             // Address = 0x50
                                                             // AddrType = 1  : 7-bit address
                                                             // Length = 1    : 1 byte payload
                                                             // pDataWr       : buffer with 1 byte payload (0x12)
                                                             // STA = true    : generate start
                                                             // STO = true    : generate stop
i2c_RunMaster();
i2c_CmdBufDeleteAll();

我已经浏览了字节范式库文档,但那里的信息非常有限。请帮忙,提前致谢:)

I want to use I2C C library for 'byte paradigm' I2C express device. This was sample API present in byte paradigm website.

//
// Executing I2C write transfer    
//
pDataWr[0] = 0x12;
pDataWr[1] = 0x34;
printf("\nWriting 0x%02X to address 0x%02x...\n", pDataWr[1], pDataWr[0]);
i2c_CmdBufAppend(2, 0x50, 1, 2, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                             // Address = 0x50
                                                             // AddrType = 1  : 7-bit address
                                                             // Length = 2    : 2 byte payload
                                                             // pDataWr       : buffer with 2 bytes payload (0x1234)
                                                             // STA = true    : generate start
                                                             // STO = true    : generate stop

i2c_RunMaster();
i2c_CmdBufDeleteAll();

What does this mean? What and Where its writing? How it differs from the API given below?

//
// Executing dummy write to set EEPROM address
//
printf("\nExecuting dummy write to set EEPROM address...\n");
pDataWr[0] = 0x12;
i2c_CmdBufAppend(2, 0x50, 1, 1, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                             // Address = 0x50
                                                             // AddrType = 1  : 7-bit address
                                                             // Length = 1    : 1 byte payload
                                                             // pDataWr       : buffer with 1 byte payload (0x12)
                                                             // STA = true    : generate start
                                                             // STO = true    : generate stop
i2c_RunMaster();
i2c_CmdBufDeleteAll();

I have gone through the byte paradigm library documentation, but information is very limited there. Kindly help, thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南城追梦 2024-12-22 06:26:05

快速谷歌搜索 I2C 规范的结果是:
http://i2c2p.twibright.com/spec/i2c.pdf

已经很久了自从我使用 i2c 设备以来已经有一段时间了(我必须为专门的芯片组编写自己的驱动程序)。

执行代码的芯片是 I2C 主控芯片。

i2c_CmdBufAppend(2, 0x50, 1, 2, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                         // Address = 0x50
                                                         // AddrType = 1  : 7-bit address
                                                         // Length = 2    : 2 byte payload
                                                         // pDataWr       : buffer with 2 bytes payload (0x1234)
                                                         // STA = true    : generate start
                                                         // STO = true    : generate stop

我对您正在使用的库一无所知,但注释充分解释了您正在地址 0x50(使用 7 位寻址)处对设备进行寻址,并且正在写入 2 个字节的数据,并且还生成启动和停止条件。

您需要参考正在交互的 I2C 规范和 EEPROM。

一旦理解了规范,其实并不难。顺便说一下,其中有很多向 I2C 设备读取/写入数据的示例。

有些设备设置为您必须向其写入特殊值(例如寄存器或命令值),然后读回数据。这是通过先发送一个写入命令,然后发送一个读取命令来设置的,命令之间没有 STOP。

您正在交互的设备应该具有有关特殊命令等的详细信息。
I2C 库不会有这些详细信息。

A quick google search for I2C specification resulted in this:
http://i2c2p.twibright.com/spec/i2c.pdf

It's been a long time since I've played with i2c devices (I had to write my own driver for a specialized chip-set).

The chip that is executing the code is the I2C master.

i2c_CmdBufAppend(2, 0x50, 1, 2, (char *)pDataWr, true, true); // Cmd = 2       : I2C write
                                                         // Address = 0x50
                                                         // AddrType = 1  : 7-bit address
                                                         // Length = 2    : 2 byte payload
                                                         // pDataWr       : buffer with 2 bytes payload (0x1234)
                                                         // STA = true    : generate start
                                                         // STO = true    : generate stop

I don't know anything about the library you are using but the comments fully explain that you are addressing the device at address 0x50 (using 7 bit addressing) and are writing 2 bytes of data, and also generating a Start and Stop condition.

You need to refer to the I2C specification and EEPROM that you are interacting with.

It's really not difficult once you understand the specification. Which by the way has full of examples of reading / writing data to I2C devices.

Some devices are set up that you have to write a special value to them (such as a register or command value) and then read back data. This is setup by transmitting a write command and then a read command without a STOP between commands.

The device you are interacting with should have the details on special commands and such.
The library I2C library WON'T have these details.

彻夜缠绵 2024-12-22 06:26:05

添加到 Freds 帖子中

I2C 规范将为您提供物理层、启动和停止模式、ack 着陆的位置以及谁驱动线路上的内容。

要了解所依赖的协议,您通常必须查看设备本身的文档(其中通常还包括物理层的图纸)。

要理解别人的 I2C 代码,您需要您面前的设备的文档。要编写您自己的 I2C 代码,您需要当前设备的文档。如果设备是像 eeprom 这样的通用设备,例如,许多供应商都生产兼容的部件,那么最好将多个设备的文档放在您面前,以防您想要某些供应商特定的东西支持或回避。

To add to Freds post

The I2C spec is going to give you the physical layer, the start and stop patterns, where the ack lands and who drives what on the wire.

To understand the protocol that rides on that you usually have to look at the documentation for the device itself (which often also includes drawings of the physical layer).

To understand someone elses I2C code you need the documentation for the device in front of you. To write your own I2C code you need the documentation for the device in front of you. If the device is something generic like an eeprom for example that a number of vendors make compatible parts it is probably a good idea to have the documentation for several of the devices in front of you in case there are some vendor specific things that you want to support or avoid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文