完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
这里是我写的一些代码,因为我真的需要一个具有多功能多主支持的主接口,并且以全总线速度工作,没有任何延迟,降低了传输速度。提供了一个I2C“驱动程序”,但它仍然“alpha”,并没有在多主机环境中进行测试。与直接访问I2C寄存器相比,使用PLIB进行编程没有附加值,而且如果需要,源代码也不太难调试。因此我编写了直接使用I2C寄存器播放的代码,因为硬件很好并且易于管理。我在PIC32MX795F512L和PIC32MX270F256D上测试了它,但是它没有任何保证。对于i2c_read()和i2c_write():-offsetcount参数是向设备发送offset参数所需的字节数。偏移参数可以是用于诸如传感器的设备的寄存器编号,或者用于诸如EEPROM之类的存储设备的偏移。OffStCube通常为1,但对于16位的设备(例如,大于24LC16的EEPROM)需要2。使用0作为偏移计数,完全不发送任何偏移量,并且直接读取或写入设备。-当针对另一主机的仲裁丢失时,或者当没有设备响应(实际上没有设备或EEPROM设备仍然忙于存储先前的数据)时,由代码执行一些重试。还为每个总线提供一个信号量,以防止由于多个任务访问同一总线而导致访问中断。注意:由于论坛不接受.h文件进行上传,请将文件i2c.h.c重命名为i2c.h。
I2C.C(10.67 KB)-下载182次 以上来自于百度翻译 以下为原文 Here is some code I wrote because I really needed a master interface with a functional multimaster support, and working at full bus speed without any delay reducing the transfers speed. It has been designed to run with FreeRTOS but could be used without with some simple modifications. HARMony 1.08.01 provided an I2C "driver" but it wad still "alpha" and had not been tested in a multimaster environment. Programming using PLIB had no added value compared to a direct access to I2C registers, and the source code was not available so hard to debug if needed. So I wrote the code playing directly with the I2C registers, as the hardware is nice and easy to manage this way. I tested it on PIC32MX795F512L and PIC32MX270F256D, however it is supplied without any warranty of any kind. To use it : - call i2c_bus_init() for each bus to use - then use i2c_read() or i2c_write(). For i2c_read() and i2c_write() : - the offsetcount parameter is the number of bytes needed to send the offset parameter to the device. The offset parameter may be a register number for a device such as a sensor, or an offset for a memory device such as an EEPROM. offsetcount is usually 1, but 2 is needed for devices addressed on 16 bits (EEPROMs bigger than 24LC16 for example). Use 0 as offsetcount to not send any offset at all and directly read or write the device. - some retries are performed by the code when the arbitration is lost against another master, or when no device is responding (really no device or EEPROM device still busy storing the data that has been previously sent) - a semaphore is also impelemented for each bus to prevent broken accesses due to multiple tasks accessing the same bus. NOTE : Please rename the file i2c.h.c to i2c.h as the forum does not accept .h files for uploads Attachment(s) i2c.h.c (1.00 KB) - downloaded 89 times i2c.c (10.67 KB) - downloaded 182 times |
|
相关推荐
1个回答
|
|
这个看起来不错,我试试看。我编写了自己的多主驱动程序用于FreeRTOS,但是这绝对是一个比我想象的要好的实现。
以上来自于百度翻译 以下为原文 This looks great, I will give it a try. I wrote my own multi-master driver to be used in FreeRTOS, but this is definitely a much nice implementation then what I came up with. |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
729浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
628浏览 0评论
526浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 15:23 , Processed in 1.287183 second(s), Total 77, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号