完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。我尝试用XC16编译器在PIC24HJ128GP202微控制器中实现I2C模块。在用MPLAB X中的调试器跳过I2C打开函数后,程序计数器在设置允许位高之后丢失。这是我在调试器控制台中得到的错误:在当前的PC 0x218中没有找到源代码行。如有任何帮助,将不胜感激。PIC配置:I2C init:
以上来自于百度翻译 以下为原文 Hello, all. I'm trying to enable the i2c module in the pic24hj128gp202 microcontroller with xc16 compiler. After stepping through my i2c open function with the debugger in MPLAB X, the program counter gets lost after I set the enable bit high. This is the error I get in the debugger console: No source code lines were found at current PC 0x218. Any help would be greatly appreciated. Cheers. PIC config: // PIC configuration. _FGS(GCP_OFF & GWRP_OFF) _FOSCSEL(FNOSC_PRI & IESO_ON) _FOSC(FCKSM_CSDCMD & IOL1WAY_ON & OSCIOFNC_OFF & POSCMD_HS) _FWDT(FWDTEN_ON & WINDIS_OFF & WDTPRE_PR32 & WDTPOST_PS32768) _FPOR(ALTI2C_ON) _FICD(JTAGEN_OFF & ICS_PGD3) I2C Init: void I2C1_Open(unsigned int config, unsigned int divider) { I2C1BRG = divider; I2C1CON = 0x1200; I2C1RCV = 0x0000; I2C1TRN = 0x0000; CNEN2 = 0x0000; //I2C1CON = config; // Debug code. I2C1CONbits.I2CEN = 1; } |
|
相关推荐
5个回答
|
|
这听起来像是中断了I2C模块的中断,没有匹配的中断服务例程。但是,您所发布的代码没有显示启用的中断。你能在别处的代码中这样做吗?(这就是为什么一个小的、完整的程序来说明你的问题比只发布代码片段更好)。
以上来自于百度翻译 以下为原文 This sounds suspiciously like interrupts for the I2C module have been enabled, with no matching Interrupt Service Routine. However, the code you posted does not show interrupts being enabled. Could you be doing it elsewhere in code you did not post? (That is why a small, COMPLETE program to illustrate your problem is preferable to just posting snippets of code.) |
|
|
|
I2C1CON= 0x1200;这意味着什么?(很好地评论你设置或使用宏的比特),即T1CONN= T1CONYN-TCKPS0A掩码* T1CONYN-TCKPS1A掩码和T1CONYNN掩码;
以上来自于百度翻译 以下为原文 I2C1CON = 0x1200; That means what? ( Good idea to comment the bits you set or use the macros ) i.e. T1CON=_T1CON_TCKPS0_MASK|_T1CON_TCKPS1_MASK|_T1CON_TON_MASK; |
|
|
|
谢谢你们的回复。QHB,我同意它听起来像一个中断,但我似乎找不到任何会与I2C碰撞。我仍然相对较新的PIC发展,所以原谅我,如果它是显而易见的。当我调试时,我的程序计数器永远不会从初始化()返回。在执行I2C1OPEN()的最后一个指令后,它会丢失。因此,如果它是一个引起问题的中断,那么在I2C1OPEN之前是否必须启用它?以下是我的主要内容:
以上来自于百度翻译 以下为原文 Thank you both for your replies. qhb, I agree it does sound like an interrupt, but I can't seem to find any that would collide with the i2c. I am still relatively new to pic development, so forgive me if it's obvious. When I'm debugging, my program counter never returns from InitIO(). It gets lost after executing the last instruction of I2C1_Open(). So if it is an interrupt that is causing the issue, wouldn't it have to be enabled before I2C1_Open? Here is my main: int main(void) { ClrWdt(); // Init the application's io. InitIO(); InitAin((AIN_CHANNELS*) &Channels, 0x80E4, 0x6000, 0x1F05, 0x0000); // Initialize serial comm. Raise the priority level to 5 for the receive. UART1_Init(ReceiveBuffer, sizeof(ReceiveBuffer), TransmitBuffer, sizeof(TransmitBuffer), BAUDRATEREG1); IPC2bits.U1RXIP = 5; INTCON1bits.NSTDIS = 0; // Set spi for approx 1.8MHz for clock of 14.7456 MHz. wdspi1_Init(0, 0, 0, 0, 0x1, 0x7); wdspi2_Init(1, 0, 0, 1, 0x2, 0x6); // // Init the timer subsystem to operate at 800 Hz with sysclk of 14.7456 MHz. // Freq = (fosc / 2) / prescaler / modulo. // InitTimers(0x0, 9216); // (14.7456M / 2) / 1 / 9216 = 800 Hz. ControlTimer = CreateTimer(ONESECOND / 200L); //TimerCallback(ControlMachine, ControlTimer); DebugTimer = CreateTimer(0L); DAirInputTimer = CreateTimer(0L); RTC_Timer = CreateTimer(0L); // Initialize the non-volatile memory. Depends on timers being initialized. nv_Init(); // Clear diff air channel select SelectChannel(CHANNEL_NONE); // Main loop. while(1) { ClrWdt(); if(GetTimer(RTC_Timer) == 0) { RTC_Day = RTC_ReadDay(); SetTimer(RTC_Timer, ONESECOND/5L); } // Check serial port. CheckComm(); } I2C1_Close(); return(0); } InitIO(): void InitIO(void) { // UART1. LATBbits.LATB11 = 1; UART1_TX_TRIS = 0; UART1_RX_TRIS = 1; //////////// Map io for PIC's digital modules. /////////// // UART1 inputs. RPINR18bits.U1RXR = 10; // U1RX to RP10. // UART1 outputs. RPOR5bits.RP11R = U1TX_IO; // U1TX to RP11. //I2C I2C_SDA_TRIS = 1; I2C_SCL = 1; I2C_SCL_TRIS = 0; I2C1_Open(0x9000, I2C_CLOCK_DIVIDER); // SPI inputs. RPINR20bits.SDI1R = 3; // SPIDIN to RP3. // SPI outputs. RPOR2bits.RP4R = SCK1OUT_IO; // SPI1CLK to RP4. RPOR3bits.RP7R = SDO1_IO; // SPI1DOUT to RP7. // 4-20 SPI outputs. RPOR0bits.RP1R = SCK2OUT_IO; RPOR1bits.RP2R = SDO2_IO; } |
|
|
|
在“打开”之前,模块不会被启用,所以它不会是这样。你可以在你的Func和透明标志上设置一个标志。我注意到你和其他人:RPNR18BITS U1RXR=10;//U1RX到RP10。PIN映射必须被解锁,设置PPS然后锁定。
以上来自于百度翻译 以下为原文 Before "open" the module would not be enabled so it wouldn't be that. You could set a flag in your open func and clear flag on close. I just noticed that you have and others: RPINR18bits.U1RXR = 10; // U1RX to RP10. Pin mapping must be unlocked, set pps then locked. |
|
|
|
再次感谢你们的洞察力。我发现这个问题是在我的PIC配置。ALTI2C位被打开,导致引脚映射错误。我现在把它修好了,可以通过我的i2c init而不用挂断。到下一个…干杯。
以上来自于百度翻译 以下为原文 Thank you both again for your insight. I found the issue was in my pic configuration. The ALTI2C bit was turned on, causing the pins to be mapped wrong. I have it fixed now and can step through my i2c init without any hang up. On to the next one.. Cheers. |
|
|
|
只有小组成员才能发言,加入小组>>
5250 浏览 9 评论
2037 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3218 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2266 浏览 5 评论
788浏览 1评论
680浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
609浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
685浏览 0评论
582浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-28 18:50 , Processed in 1.325521 second(s), Total 56, Slave 50 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号