Microchip
直播中

宫昊

7年用户 237经验值
私信 关注
[问答]

如何使用与I2C和GPIO相同的引脚?

嗨,因为我不了解IO端口和PPS文档,也没有找到这方面的线程,所以我想在这里直接询问。我使用的是PIC32MX795F512L,我想做以下功能:1。初始化I2C1模块,进行I2C通信。2。禁用/去初始化I2C模块。3。现在使用与GPIO相同的引脚并进行IO操作。4。再次执行步骤1。或重复步骤3。

以上来自于百度翻译


      以下为原文

    Hi,
Since I don't understood the IO port and PPS documentation also no thread found for this, I prefer to ask here directly.

I am using PIC32MX795F512L and I want to do following functionality:
1. Initialise I2C1 module and do I2C communication.
2. Disable/Deinitialize I2C module.
3. Now use same pins as GPIO and make IO operations.
4. Again do step 1. or step 3 repeatedly.

回帖(7)

张娜

2019-6-18 11:51:55
应该工作,是的。不确定如果这些引脚是PPS在您的照片,在这种情况下,一些额外的照顾可能适用。

以上来自于百度翻译


      以下为原文

    Should work, yes. Not sure if those pins are PPS on your PIC, in which case some extra care may apply.
举报

李雨晨

2019-6-18 12:20:15
你的照片好像没有PPS。你的步骤1…4看起来还可以,所以在使用之后只需要注意启用和禁用PIC内部i2c模块(I2CxCON位15),但是不清楚您想要实现什么。如果您在I2C使用和I/O使用之间物理地连接/分离硬件,这可能是有意义的。不过,你提到了一个“循环”,这让我觉得你想分享引脚。通常你有一个或多个I2C奴隶连接到你的巴士,你需要上拉电阻器的SDA和SCL。你的I/O可能不喜欢弹出,而你的I2C奴隶可能不喜欢你的I2C总线。有时候,您想用I/O来驱动SDA线路,那么从机可能会驱动SDA线路。除非您有充分的理由这样做,否则我不会这样做。

以上来自于百度翻译


      以下为原文

    Your PIC doesn't seem to have PPS.
Your steps 1 .. 4 seem ok, so just take care to enable and later disable the PIC internal i2c module after use ( I2CxCON  bit 15),
However it is unclear what you are trying to achieve.  If you physically attach/detach hardware between i2c usage and I/O usage that might make sense. However you mention a "loop" around this, which lets me think you you want to share the pins. Usually you have one or multiple i2c slave attached to your bus, and you need pullup resistors for SDA and SCL.  Your I/O might not like the pullups and your i2c slave might not like your bit-banging of the i2c bus lines.  The slave might drive the SDA line at times you want to drive them with your I/O. 
 
I would not do that unless you have a good reason to do so.
 
举报

李雨晨

2019-6-18 12:37:25
也许你应该谷歌的I2C和开放排水SCL和SDA线是“开放排放”的驱动程序。这意味着芯片可以驱动它的输出低,但它不能驱动它高。为了使线路能够达到高电平,您必须提供上拉电阻。您也可以将GPIO配置为与此兼容的开放漏极,但是您必须理解i2c要求,并且知道您正在做什么。

以上来自于百度翻译


      以下为原文

    May be you should google for i2c and open drain
 
Both SCL and SDA lines are "open drain" drivers. What this means is that the chip can drive its output low, but it cannot drive it high. For the line to be able to go high you must provide pull-up resistors
 
You might also configure your GPIO as open drain to be compatible with that, but you must understand i2c requirements and know what you are doing.
举报

李铭鑫

2019-6-18 12:48:42
您好,即使I2C控制器使用端口引脚,您也可以一直读取通用I/O端口寄存器。设置I2CxCON.ON=1;/*I2C控制器现在将控制SDAx和SCLx引脚。*/…I2CXCON.ON=0;/*IO引脚现在由IO端口寄存器控制。*/请注意,NXP在I2C文档中精心设计和指定了“开路漏极”驱动器,以避免I2C信号线上出现任何可能的短路情况。如果禁用I2C控制器并将管脚驱动到高逻辑电平,则会破坏I2C信号规则,如上面的rodims所解释的I2C规范在NXP网站上:Mysil NXP.COM/Dopunts/UsRyMualAl/UM10204.PDF,

以上来自于百度翻译


      以下为原文

    Hi,
You can always Read the general I/O Port register even when I2C controller is using the port pins.
Set
    I2CxCON.ON = 1;  /* I2C controller will now control  SDAx and SCLx pins. */
...
    I2CxCON.ON = 0;  /* IO pins are now controlled by IO port registers. */
 
Be aware that the "open drain" drivers are carefully designed and specified in I2C document by NXP, 
in order to avoid any possible short circuit condition on I2C signal lines.
If you disable I2C controller and drive the pin to High logic level, you break I2C signalling rules,
as rodims explain above.
 
I2C specification is on NXP website: www.nxp.com/documents/user_manual/UM10204.pdf
 
Regards,
   Mysil
举报

更多回帖

发帖
×
20
完善资料,
赚取积分