Microchip
直播中

乔婧

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

I2c代码卡在状态

我想使用代码配置器生成的代码用于I2C,虽然它比我需要的更多,但似乎没有什么好的理由来重新创建轮子。我的代码非常贴近头文件中的示例,它看到它被STAtiON= I2C2YMasaGeJug所困扰。通过它,我看到I2C状态机在ISR中。因此,中断发生,下一个块得到处理。问题是第一个数据包。由于没有以前的数据包,所以永远不会有中断,所以我们挂断。如果我已经正确地理解了,那么我的问题是什么是最好的方法来处理这个问题?我是否应该简单地添加一些代码来初始化,直接对端口做一个哑写以强制中断,或者什么?谢谢。

以上来自于百度翻译


      以下为原文

    I'd like to use the Code Configurator's generated code for I2C, whilst it's more than I need there seems to be no good justification for re-inventing the wheel.

My code is based very closely on the example in the header file and it see it gets stuck with status==I2C2_MESSAGE_PENDING. Following it through I see that the I2C state machine is in the ISR.  So, an interrupt happens and the next block gets processed. The problem is with the very first packet.  Since there was no prior packet there will never be an interrupt so we hang.

If I have understood this correctly, then my question is what is the best way to deal with this? Should I simply add some code to initialization to do directly do a dummy write to the port to force an interrupt, or what?

Thanks.

回帖(5)

冯润生

2019-4-10 10:58:37
这个问题有点深。我添加了“启动”代码来强制在总线上进行虚拟交易。是的,我看到公共汽车是寂静的,因此仍然没有中断。虽然我还没有发现它,但是肯定有错误的MCC(3.55 BTW)产生的设置。

以上来自于百度翻译


      以下为原文

    The problem is a little deeper.  
 
I added the 'kick start' code to force a dummy transaction on the bus. Yes I see  the bus is silent and therefore still no interrupt. Although I haven't spotted it yet, there must be something wrong with the MCC (3.55 BTW) generated setup.
 
 
举报

李铭鑫

2019-4-10 11:06:42
嗨,MCC的I2C驱动程序代码中有很多bug,我已经搜索了一段时间,并发布了一些修改。你在为哪个代码创建设备?MCC有3个单独的脚本文件,用于8位PIC设备、16位PIC设备和PIC32 MX设备。没有MCC V3.55 BTW。版本号3.55是MPLAB X集成开发环境的版本号。MCC V3.262是当前可安装的MCC插件的版本号。然而,在MPLAB X.MCC中,使用不同的设备族的模板和方法库。您使用的是什么库和版本?一般来说,I2C信号线SDA和SCL必须由外部上拉电阻拉高到数字逻辑电平。在I2C驱动程序初始化之前,I/C通信用的I/O引脚应该配置为数字输入。如果I/C引脚用于I2C,可以用作模拟输入,那么ANA。对于这些引脚,必须禁用日志模式,这是通过清除ANSELx寄存器中的比特来实现的,对于大多数现代PIC器件而言,如果PIC器件具有外围引脚选择(PPS),那么I2C输入和输出必须设置为相同的引脚。在启动I2C通信之前必须启用中断处理。阳离子,通过调用I2C2MyMraveScript(…)或I2C2MigrtBiSnSert(…),这些功能将通过为I2C模块设置主中断标志来启动中断处理。如果不能自行获得正确的中断标志,则可以打包完整的问题项目,并附加消息。Er是一个工具,用于打包在一个zip文件中恢复程序项目所需的所有文件。在“Project”面板中,通常在MPLAB窗口的左上部分,指向项目树的根,点击右键并选择“包”。如果你问得很好,一些william hill官网 成员可以尝试帮助。问候,Mysil。

以上来自于百度翻译


      以下为原文

    Hi,
There are various bugs in I2C driver code generated by MCC,
I have hunted around for some time, and published modifications on some occations.
 
What device are you creating code for?
MCC have 3 separate collections of script files for 8-bit PIC devices, 16-bit PIC devices, and PIC32MX devices. 
 
There is no MCC v3.55 BTW.
Version number 3.55 is version number of MPLAB X Integrated Development Environment.
MCC v3.26.2 is version number of the current MCC plugin that may be installed in MPLAB X.
MCC however, use a library of templates and methods that is different for different families of devices.
What library and version are you using?
 
In general, I2C signal lines SDA and SCL must be pulled up to High digital logic level, by external pull-up resistors.
I/O pins to be used for I2C communcation should be configured as Digital Inputs before I2C driver is initialized.
If I/O pins to be used for I2C may be used as Analog input, then analog mode must be disabled for these pins, 
this is done by clearing bits in ANSELx register, for most modern PIC devices.
If the PIC device have  Peripheral Pin Select, (PPS), then I2C Inputs and Outputs must be set to the same pins.
 
Interrupt processing must be enabled before trying to start I2C communcation,
by calling I2C2_MasterWrite(...), or I2C2_MasterTRBInsert(...).
These functions will initiate interrupt processing by setting master interrupt flag for the I2C module.
 
If you cannot get it correct by yourself, you may package a complete problem project, and attach with a message.
In MPLAB X, there is a tool to package all files needed to restore a program project, in a zipfile.
In 'Projects' panel, usually in the upper left part of MPLAB window, point to root of the project tree,
click righthand button and select 'Package'.
If you ask nicely, some forum member may try to help.
 
Regards,
   Mysil
举报

冯润生

2019-4-10 11:16:04
感谢MysIL的回应。最有用的。版本和其他信息:MPLA3.5XC8 1.41目标PIC18F26K22MCC 3.62.驱动程序版本:2.00我不确定你指的是哪一个库,但它可能是学术的…我已经修复了两个问题。一个,感谢你,是PIN被设置为输出-一个MCC错误。我已经阅读了有关TIS设置的数据表中的部分,但声明缺乏清晰性,我愚蠢地认为MCC是正确的。由此导致的缺乏活动是隐藏第二个错误,这是一个很容易解决的中断死锁。所以现在我在公共汽车上有交通,地址很好,但是奴隶在生气。这是一个硬件问题,所以我会深入研究。你提到你有一些错误修复的驱动程序。我在哪里可以找到这些?再次感谢。

以上来自于百度翻译


      以下为原文

    Thanks Mysil for your response. Most helpful.
 
Version and other info:
MPLAB 3.55
XC8 1.41
Target PIC18F26K22
MCC 3.6.2
Driver Version : 2.00
 
I'm not sure which library you are referring to, but it may be academic...
 
I've fixed two issues. One, thanks to you, was the pins were set to outputs - an MCC bug.  I had read the part in the datasheet about TRIS settings but the statement lacked clarity and I foolishly assumed that MCC was correct. The consequent lack of activity was hiding a second bug which was an interrupt deadlock that was easily solved.
 
So now I have traffic on the bus, address is good but the slave is sulking.  This is a hardware issue now so I'll dig into that.
 
You mentioned that you have some bug fixes for the driver. Where can I find these?
 
Thanks again.
 
 
 
 
举报

李铭鑫

2019-4-10 11:25:28
嗨,When MCC在MPLAB X中打开,可用的MCC模板库,它们的版本号显示在MPLAB窗口的左下面板:版本。你可以看看这个线程:HTTP://www. McCHIP.COM/FoMss/FunPt/982222修订的I2C驱动程序代码在LATES中的示例代码中。Pix18F26K22在ZIPFILE中有配置和示例代码,但是代码是为I2C1配置的,所以你必须做一些搜索和替换来使用I2C2的驱动程序。在线程、示例代码、驱动头文件和Soul中都有一些描述。问候,Mysil

以上来自于百度翻译


      以下为原文

    Hi,
When MCC is open in MPLAB X, available MCC template libraries and their version numbers are displayed in the lower lefthand panel of MPLAB window: Versions.
 
You may look at this thread: http://www.microchip.com/forums/FindPost/978822
Revised I2C driver code is inside the example codes in the latest posts in the thread.
There is configuration and example code for PIC18F26K22 in the zipfile, 
but code is configured for I2C1, so you will have to do some search and replace to use the driver for I2C2.
There is some description in the thread, in example code, and in the driver header file, and in source.
 
Regards,
   Mysil
举报

更多回帖

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