完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我一直在我的PIC16F15355上运行I2C作为一个奴隶,一段时间没有问题。我切开并粘贴了一个我找到的司机,把它清理干净了。我现在写了一个I2C引导加载程序,我不能得到I2C的所有响应。与我其他代码的主要区别在于,在引导加载程序中没有中断。我只是轮询并寻找中断的SSP1IF标志。我可以用我的PICtiT3加载引导加载程序,并在轮询循环上中断。但是没有设置SSP1IF标志。我的范围显示了起始位和地址字节,但是没有PIC的ACK。信号看起来完全一样,如果没有PIC根本。这是我的主要…和我的I2C代码看起来像这样…任何帮助都将被赞赏…
以上来自于百度翻译 以下为原文 I have been running I2C as a slave on my PIC16F15355 for some time with no problem. I cut and pasted a driver I found and cleaned it up a bunch. I have now written an I2C bootloader and I can't get the I2C to respond at all. The major difference from my other code is that there are no interrupts in the bootloader. I'm just polling and looking for the SSP1IF flag with interrupts off. I can load the bootloader with my pickit3 and break on the polling loop. But the SSP1IF flag is not being set. My scope shows the start bit and address byte but there is no ack from the PIC. The signals look exactly the same as if there was no PIC at all. Here is my main ... // I2C bootloader for PIC16LF15355 // code used with the bootloader should offset the code by 0x200 // search xc8 user manual for --CODEOFFSET and --ROM #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINT32 // Power-up default value for COSC bits (HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled) #pragma config MCLRE = ON // Master Clear Enable bit (MCLR pin is Master Clear function) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled) #pragma config BOREN = ON // Brown-out reset enable bits (Brown-out Reset Enabled, SBOREN bit is ignored) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices) #pragma config ZCD = OFF // Zero-cross detect disable (Zero-cross detect circuit is disabled at POR.) #pragma config PPS1WAY = ON // Peripheral Pin Select one-way control (The PPSLOCK bit can be cleared and set only once in software) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will cause a reset) #pragma config WDTCPS = WDTCPS_31 // WDT Period Select bits (Divider ratio 1:0x10000; software control of WDTPS) #pragma config WDTE = OFF // WDT operating mode (WDT enabled regardless of sleep; SWDTEN ignored) #pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits (window always open (100%); software control; keyed access not required) #pragma config WDTCCS = SC // WDT input clock selector (Software Control) #pragma config BBSIZE = BB512 // (512 char boot block size) #pragma config BBEN = ON // (Boot Block enabled) #pragma config SAFEN = OFF // (SAF disabled) #pragma config WRTAPP = OFF // (Application Block not write protected) #pragma config WRTB = OFF // (Boot Block not write protected) #pragma config WRTC = OFF // (Configuration Register not write protected) #pragma config WRTSAF = OFF // (SAF not write protected) #pragma config LVP = OFF // Low Voltage Programming Enable bit (High Voltage on MCLR/Vpp must be used for programming) #pragma config CP = OFF // UserNVM Program memory code protection bit (UserNVM code protection disabled) #include #include "main.h" #include "i2c.h" #include "flash.h" #define _str(x) #x #define str(x) _str(x) void interrupt service_isr() { asm ("pagesel " str (NEW_INTERRUPT_VECTOR)); asm ("goto " str (NEW_INTERRUPT_VECTOR)); } void main(void) { if(haveApp()) { // jump to app STKPTR = 0x1F; asm ("pagesel " str(NEW_RESET_VECTOR)); asm ("goto " str(NEW_RESET_VECTOR)); } // run bootloader i2cInit(); while(1) chkI2c(); } And my I2C code looks like this ... #include #include "i2c.h" #include "flash.h" void i2cInit() { SSP1CLKPPS = 0x13; // RC3 => SCL in SSP1DATPPS = 0x14; // RC4 => SDA in RC3PPS = 0x15; // SCL => RC3 out RC4PPS = 0x16; // SDA => RC4 out SSP1MSK = 0xe7; // matches addr 4 and/or 8 SSP1ADD = 0; // all but 4 and 8 must be zero SSP1CON1bits.SSPM = 6; // I2C Slave, 7-bit address SSP1CON1bits.WCOL = 1; // Write Collision detect SSP1CON1bits.CKP = 1; // Zero holds clock low (clock stretch) SSP1CON1bits.SSPEN = 1; // Serial Port Enable bit SSP1CON1bits.WCOL = 0; // clr flag to allow bytes to be received // SSP1CON1 = 0b10110110; SSP1CON2bits.SEN = 1; // Stretch Enable SSP1CON2bits.GCEN = 0; // General Call Enable // SSP1CON2 = 0b00000001; SSP1CON3bits.SCIE = 0; // Start Condition Interrupt Enable SSP1CON3bits.PCIE = 0; // Stop Condition Interrupt Enable SSP1CON3bits.BOEN = 1; // Buffer Overwrite Detect Enable SSP1CON3bits.SBCDE = 1; // Bus Collision Detect Enable SSP1CON3bits.AHEN = 0; // Address Hold Enable for software ack/nak SSP1CON3bits.DHEN = 0; // Data Hold Enable for software ack/nak // SSP1CON3 = 0b00010100; SSP1IF = 0; // clear I2C int flag, is used without interrupts } // ---- SNIP ---- void chkI2c() { if(!SSP1IF) return; // int flag used without interrupts SSP1IF = 0; // <<<< A BREAK HERE NEVER HAPPENS // ---- SNIP ---- } Any help would be appreciated... |
|
相关推荐
12个回答
|
|
以上来自于百度翻译 以下为原文 SSP1CON1bits.SSPM = 6; // I2C Slave, 7-bit address Doesnt look right..... |
|
|
|
为什么不呢?6是0B110,这是为“I2C从模式,7位地址”指定的模式。
以上来自于百度翻译 以下为原文 Why not? 6 is 0b110, which is the pattern specified for "I2C Slave mode, 7-bit address". |
|
|
|
谢谢您的详细回复。地址0和4是为了特殊目的而保留的。地址4是特殊的吗?数据表上没有关于那件事。我试着用8而不是4在我的测试中没有运气。&如果我错了,我宁愿设置SSP1Addix0x18纠正我,但是那些不是被我的0x7屏蔽忽略的吗?顺便说一下,我甚至尝试过一个零的掩码,它应该接受所有的地址。我执行了你所有的建议。它们都有道理。然而,仍然没有欢乐。自从我运行了另一个I2C代码后,我的电路板断了一个很小的机会,所以我回去测试一下。再次感谢。我会感谢你尝试我的代码后,我重新检查板。我知道这是一项很大的工作。我希望你付出了所有的努力。-)
以上来自于百度翻译 以下为原文 Thank you for the detailed response. > Addresses 0 and 4 are reserved for special purposes. Address 4 is special? There was nothing in the datasheet about that. I tried using 8 instead of 4 in my test with no luck. > I would rather set SSP1ADD 0x18 Correct me if I'm wrong, but aren't those bits ignored by my 0xe7 mask? BTW, I've even tried a mask of zero which should accept *all* addresses. I implemented all your suggestions. They all make sense. However there is still no joy. There is a slim chance my board broke since I ran my other I2C code so I am going back and testing that. Thanks again. I would appreciate you trying my code after I recheck the board. I know that is a lot of work. I hope you are getting paid for all your effort. :-) |
|
|
|
FWW,完整的引导加载程序是AthTPS://Github. COM/MARK-HAHN/XY-BOOT。
以上来自于百度翻译 以下为原文 FWIW, the complete bootloader is at https://github.com/mark-hahn/xy-boot. |
|
|
|
http://www. McCHIP.COM/PROSP/8BIT-BOOTILTER http://www. McCHIP.COM/WavaPabeSe/AppNo.ASPX?AppNeNo.En56181
以上来自于百度翻译 以下为原文 http://www.microchip.com/promo/8-bit-bootloader http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en546181 |
|
|
|
@NKurzman感谢链接,但是第一个链接不适用,因为MCC 8位引导加载程序生成器不生成I2C代码,至少对于我的芯片是这样。您对应用程序说明的第二个链接是我尝试过的代码,但它需要对我的PIC进行大量修改,并且代码编写得非常糟糕(向作者道歉),所以我从头开始重写了它。我从UART版本和APP注释版本中盗取了代码片段。我之前从头开始编写的第一个基于I2C中断的代码没有任何问题,所以我认为重写引导加载程序是微不足道的。PIC HW似乎除了地址零之外没有任何特殊的东西。我应该尊重标准,但这与我的问题无关。无论如何,感谢您对规范的参考。这对我来说是个新闻。>所有的0X地址都被保留了。谢谢。我将遵循这个规则,即使我从来没有在任何系统文档中看到过它被引用。EDIT:根据这个规范,在127个可能的地址中只有14个地址没有被保留。这有点荒谬。该规范还提到,如果不需要,则不必保留这些内容。换句话说,如果需要的话,应该使用它们,但它们可以用于其他普通地址。-看下面的帖子。
以上来自于百度翻译 以下为原文 @NKurzman Thanks for the links but the first doesn't apply because the MCC 8-bit boot loader generator doesn't produce I2C code, at least for my chip. Your second link to the app note is code that I tried but it required so much modification for my PIC, and the code was so poorly written (apologies to author), that I rewrote it from scratch. I stole fragments of code from the uart version and the app note version. I had no problem with the first I2C interrupt-based code I wrote from scratch before so I thought the boot loader rewrite would be trivial. @qhb I meant the PIC datasheet. The PIC HW doesn't seem to have anything special other than address zero. I should probably respect the standard but that has nothing to do with my problem. In any case thanks for the reference to the spec. That was news to me. > All the 0X addresses are reserved. Thanks. I will follow that rule even though I've never seen it referenced in any system doc. EDIT: According to that spec there are only 14 addresses out of 127 possible that aren't reserved. That is kind of ridiculous. That spec also mentions that those don't have to be reserved if not needed. In other words they should be used if you need that purpose but they can be used for other plain addresses. EDIT EDIT: Most of what I said in the last edit is wrong. :-) See following posts. |
|
|
|
大多数I2C兼容设备的制造商假定您已经阅读了规范。我同意,保留地址的使用不是您的直接问题,但是遵守完整的规范是一个好主意。您在哪里读到的?我引用的表只说前8个,最后8个是保留的。剩下112。
以上来自于百度翻译 以下为原文 Most manufacturers of I2C compatible devices assume you have read the specification. I agree, use of the reserved addresses is not your immediate problem, but it's a good idea to abide by the full spec. Where do you read that? The table I quoted only says the first 8 and the last 8 are reserved. That leaves 112. |
|
|
|
在这两个例子中,你可以看到I2C从站的设置,你可以比较一下他们的设置。之后,如果主站发送了一个开始和一个地址,你应该看到设置了标志。我只记得它起作用了。要小心保留的意思。例如,0xA0是预留的EEPROM,但您可以使用它不是硬件预留。也要注意地址符号。有些写地址在一个作用域上读7位的其他8位。(高7位)
以上来自于百度翻译 以下为原文 You can look at the setup for the I2C Slave in both examples you compare your set up to theirs. After that if the Master sends a start and an address you should see the flags set. The I used that App note years ago. I just remember it worked. Be careful with the meaning of reserved. for example 0xA0 is reserved for EEPROM, But you could use it in is not Hardware reserved. Also be careful of the address notation. Some write the address a 7 bits other 8bits as read on a scope. (high 7 bits) |
|
|
|
只是说前8个和最后8个是保留的,是的。我改正了。但它后来说,保留它们是可选的,这取决于你的系统。正如我之前说过的,我会遵循这些建议。
以上来自于百度翻译 以下为原文 > only says the first 8 and the last 8 are reserved Yes it says that. I stand corrected. But it still said later that reserving them was optional depending on your system. As I said before, I will follow those suggestions. |
|
|
|
这里没有冒犯。我只是做了一个实践,指出错误的断言很快,因为误解常常是问题的原因。
以上来自于百度翻译 以下为原文 No offence taken here. I just make a practice of pointing out incorrect assertions quickly, as a misunderstanding can often be the cause of the problem. |
|
|
|
一个误解常常是问题的原因,并增加了网络上的大量错误信息。-我不能告诉你我在阅读这件事和其他事情时读了多少错误的东西。
以上来自于百度翻译 以下为原文 > a misunderstanding can often be the cause of the problem. And add to the plethora of misinformation on the web. :-) I can't tell you how many wrong things I've read while googling this and everything else. |
|
|
|
嗨,我发现的主要问题是数字输入缓冲器的I2C信号引脚未启用:问候,Mysil
以上来自于百度翻译 以下为原文 Hi, The main problem I found was Digital Input buffers for I2C signal pins not enabled: ANSELCbits.ANSC3 = 0; /* Enable Digital Input buffer for SCL signal. */ ANSELCbits.ANSC4 = 0; /* Enable SDA. */ Regards, Mysil Attachment(s) I2C_BootloadMSSP.zip (8.80 KB) - downloaded 47 times |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
777浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
676浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 00:58 , Processed in 1.333048 second(s), Total 99, Slave 82 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号