I2C

Use of I2C device driver

发布于 2014-12-15 21:38:12
Ni hao,
I am working on a board based on STM32F2xx with one I2C bus and three I2C devices.
I was looking for some examples how to use the I2C framework, available in i2c_core.c and i2c_dev.c, but I couldn't find anything in the repository.

Can you help me to find some good complete examples in order to use I2C with RT-Thread?

Xie xie

Cesare

查看更多

关注者
0
被浏览
7.4k
8 个回答
bernard
bernard 2014-12-16
Hello,
Do you have IIC driver? If you have driver and already register the IIC driver to the RT-Thread device system, you can use IIC device interface to visit IIC devices.

For example:

{
rt_uint8_t reg;
rt_uint8_t buf[8];

struct rt_i2c_msg msgs[2];
struct rt_i2c_bus_device* i2c_bus = (struct rt_i2c_bus_device *)rt_device_find("your_iic");

reg = 111; // iic device's register address

msgs[0].addr = your_iic_device_addr;
msgs[0].flags = RT_I2C_WR;
msgs[0].buf = ®
msgs[0].len = 1;

msgs[1].addr = your_iic_device_addr;
msgs[1].flags = RT_I2C_RD; /* Read from slave */
msgs[1].buf = buf;
msgs[1].len = sizeof(buf);

/* to read some registers on the iic devices */
length = rt_i2c_transfer(i2c_bus, msgs, 2);
}
BubbleBobble
BubbleBobble 2014-12-16
Ni hao Bernard,
thank you for your reply, I had doubts how the I2C framework is organized in RT-Thread.

Anyway I found an example in the RealBoard4088 repository, more precisely:

RealBoard4088/software/rtthread_examples/drivers/drv_i2c.c
tells me how to write the driver and register the I2C bus, then

RealBoard4088/software/rtthread_examples/drivers/drv_uda1380.c
tells me how to write the driver for the single I2C device and register it on the bus.
I think I should be able to go on without problems.

But I have the last question: do we have a chance to get the full RT-Thread documentation in english? I really like RT-Thread and I found it quite powerful but my problem is the lack of documentation and examples.

Thank you

Cesare
bernard
bernard 2014-12-17
Recently, we will have a short guide for RT-Thread kernel. We can translate it to English. But for full book of RT-Thread programming guide, we have no enough time to translate it to English. But it's placed in github.com as markdown file. If possible, you or other guys can translate it to English.
BubbleBobble
BubbleBobble 2014-12-22
Despite english is not my native language, I might try to translate the kernel part to english using chinese => english translator. I also have chinese friends who eventually can help me. Now here it is Xmas and New Year period, once I get back from holidays I will check the repository for the translation. I let you know.

By the way, just to report to you that here in Europe the website is recently very slow and sometimes it gets stuck.

Thank you to release the RT-Thread RTOS to the public.
bernard
bernard 2014-12-23
O, I think English is your native language.

The website of "www.rt-thread.org" is placed in China, therefore, it's very slowly to be visited from Europe or US. Actually, You can visit github.com, the development activities is hosted in github:


And you can submit issue if you have question or some interesting topic etc. I'm using GMail and can receive the notification from github immediately. I will replay the github issue carefully. Hope you enjoy RT-Thread. Next year, we will go out side of China. Merry Christmas!
majianjia
majianjia 2014-12-28
[s:154] [s:154]
EU test
ralfak
ralfak 2015-12-15
I2C device in rt_thread is just a hole!
get example from
https://github.com/RT-Thread/realboard- ... tm32_i2c.c.

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友