完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我在PIC18LF24K40芯片上工作,在编写I2C程序时遇到了问题,尽管遵循了数据表中的指令,但是我在SCL和SDA线上得到了一个很高的波形,而不是像预期的波形。PS:我对PIC是新的,但是对AVR芯片有一定的经验。因此,我不是一个完整的初学者。
以上来自于百度翻译 以下为原文 Hello, Im working with PIC18LF24K40 chip and i have a problem while writing an I2C program, in spite of following the instructions in Datasheet, i get a HIGH on SCL and SDA lines instead of a Waveform as expected. void I2C_Inititalise() { RC3PPS = 0x0E; RC4PPS = 0x0D; SSP1CON1 = 0x28; //I2C Mode SSP1CON2 = 0x00; SSP1STAT = 0x00; SSP1ADD = 0x04; // Clock 400KHz } void send_start() { while(SSP1STATbits.RW); // wait for write to complete SSP1CON2bits.SEN=1; //set start enable bit if(PIR3bits.BCLIF==1) PIR3bits.BCLIF =0; //Clear collision bit in PIR register while(SSP1CON2bits.SEN); //waits to get cleared by hardware } void main(void) { TRISCbits.TRISC2=0; init_oscillator(); I2C_Inititalise(); while(check_for_bus_free_iic()); send_start(); write_to_bus(0x2A<<1); //Address of slave + bit 0 (W) while(1){ LATCbits.LATC2 ^= 1; PORTCbits.RC2 ^= 1; } return; } PS: I am new to PIC but have some experience with AVR chips. Therefore im not a complete beginner. |
|
相关推荐
4个回答
|
|
对于SCK和SDA,需要输入和输出PPS都配置相同。RC3 PPS输入默认为CLK,RC4默认为SDA。您已经将输出设置为相反。您应该明确地设置输入,而不是依赖默认值。
以上来自于百度翻译 以下为原文 For SCK and SDA you need to have both input and output PPS configured the same. RC3 PPS input defaults to CLK, and RC4 defaults to SDA. You have set the outputs to opposite. You should probably explicitly set the inputs, rather than rely on defaults. |
|
|
|
谢谢,这是我的错误,用相反的值填写这些寄存器。所以现在我把I2CII初始化例程改成了下面的内容。
以上来自于百度翻译 以下为原文 Thank you it was my mistake to fill those registers with the opposite values. So now i changed the I2C_initialize routine to the following. void I2C_Inititalise() { RC3PPS = 0x0D; //PPS OUTPUT CLK RC4PPS = 0x0E; //PPS OUTPUT SDA SSP1CLKPPS = 0x13; //PPS INPUT CLK SSP1DATPPS = 0x14; //PPS INPUT SDA SSP1CON1 = 0x28; //I2C Mode SSP1CON2 = 0x00; SSP1STAT = 0x00; SSP1ADD = 0x04; } It still does not seem to make a difference on the SCL and SDA lines. |
|
|
|
现在它工作了,我必须明确地清除相关的信息。在配置UJART模块的TJHE接收中断时,我偶然发现了它。通过添加这个,我可以看到总线上的CLLCK和数据。令人惊叹的。非常感谢你的帮助!
以上来自于百度翻译 以下为原文 Its working now, I had to explicitly clear the relevant ANSELCbits. I discovered it by accident while configuring tjhe receive interrupt for USART module. By adding this i can see cloclk and data on the bus. Awesome. :) ANSELCbits.ANSELC3 =0; ANSELCbits.ANSELC4 =0; Thanks so much for your help! |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
772浏览 1评论
663浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
590浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
672浏览 0评论
572浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 16:41 , Processed in 1.408040 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号