完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用的是使用MCC V3.15的PIC16LF18325微芯片。我在这个项目中使用了SPI和I2C,我很高兴地说SPI部分工作得很好,而I2C则不工作。我已经将RC4设置为SCLK2和RC1,设置为SDA2(使用MSSP2),并且当我编译代码并执行masterWrite/masterRead时,没有时钟线或数据出来。看是浮动SCLK,数据很低。线路上硬件上唯一明智的就是2 10kohm上拉电阻和3个传感器(正确,我保证了三倍)。这个芯片有MCC V3.15的已知问题吗?它确实正确地设置了寄存器吗?这里它们是:LATA=0x0;LATC=0x0;LATC=0x0;WPUA=0x0;WPUC=0x0;ANSELA=0x37;ANSELA=0x37;ANSELC=0x37;ANSELC=0x5;TRISC=0x38;TRISA=0x13;TRISA=0x13;RC1PPSbits.RC1PPS位.RC1PPS=0x1PPS=0x1B;//RC1->/RC1->MSSP1;MSSP1->=RC1PPS位.RC1PPS=RC1PPS=RC1PPS=RC1PPS=0x1PPS=0x1PPS=0x1x1A;//RC4->MSSP2:SCL2;RC0PPSbits.RC0PPS=0x18;//RC0->MSSSCK1;RC2PPS比特.RC2 SCK1;RC2PPS位.RC2PPS位.RC2PPSS=0x19;//RC2->MSSP1/RC2->MSSP1:RC2RC2RC2RS2PPS位.RC2RC2PPSS=0x19;//RC2->;MSSP1:SDSP1:SDOSDO1/RC2->;MSSP1:SDSP1:SSP2DADADADADATPPSP2DATPPSP2DATPPSPSP2DATPPSSSSP2:SDA2;SSP2CLCLCLKPPSSP2CLKPPS位.SSP2CLKPPPPPPPPPSPSPSPSPSPSPSSSSSSS0=0x14;//PPSLOCK=0xAA;PPSLOCKbits.PPSLOCKED=0x01;//lock PPSGIE=state;SSP2CON1=0x28SSP2CON3=0x00SSP2ADD=0x00SSP2ADD=0x03SSP2STAT=0x00也可能是我使用I2C函数错了,这是我的实现,用于从LPS22HB接收压力数据:voidgetPres.(void){uint8_t status=0;uint8_t._top=0;uint8_t._mid=0;uint8_t._low=0;I2C2主写(LPS22_CTRL_REG1,1,LPS_地址,&状态);I2C2_主写(0b000000000100010,1,LPS_地址,&;状态);I2C2_主写(LPS22_CTRL_REG2,LPS22_CTRL_REG2,1,LPS_地址,&;状态;LPS2S22_主写(LPS22_CTRL_REG2,1,LPS_地址,&;状态;LPS22_REG2,1,LPS_地址,&;状态);I2C2_主写(LPS22_主写(LPS22_CTRL_CTRL_REG2_REG2_REG2_REG2,1_PRESS_OUT_XL,1,LPS_Address,&staI2C2_MasterRead(压力_低,1,LPS_地址,&状态);I2C2_母写I2C2_母写I2C2_母写I2C2_母写I2C2_母写母写(LPS22_PRE_PRE_PRE_OU_OU_H,1,LPS_LPS_地址,&;状态;1,LPS2S22_LPS_PRE_低压_PRESS_PRESS_PRESS_OUT_L L,1,LPS_地址,&;1,LPS_地址,&;状态);I2C2_母写I2C2_母写I母写I2C2_母写I母写I2C2(LPS22_母写LPS22_PRE1,LPS_Address,现状;
以上来自于百度翻译 以下为原文 I am using a PIC16LF18325 microchip using MCC v3.15. I am using both SPI and I2C for this project and I am happy to say the SPI part works perfectly, the I2C on the other hand does not work. I have set RC4 to SCLK2 and RC1 as SDA2 (using MSSP2) and when I compile the code and do a masterWrite/masterRead there is no clock line or data coming out, all I see is a floating SCLK and the data is low. The only things hardware wise on the line are 2 10kohm pull up resistors and 3 sensors attached (correctly, I made triple sure). Is there known issues with MCC v3.15 for this chip? Does it definitely set the registers correctly? Here they are: LATA = 0x0; LATC = 0x0; WPUA = 0x0; WPUC = 0x0; ANSELA = 0x37; ANSELC = 0x5; TRISC = 0x38; TRISA = 0x13; RC1PPSbits.RC1PPS = 0x1B; //RC1->MSSP2:SDA2; SSP1DATPPSbits.SSP1DATPPS = 0x15; //RC5->MSSP1:SDI1; RC4PPSbits.RC4PPS = 0x1A; //RC4->MSSP2:SCL2; RC0PPSbits.RC0PPS = 0x18; //RC0->MSSP1:SCK1; RC2PPSbits.RC2PPS = 0x19; //RC2->MSSP1:SDO1; SSP2DATPPSbits.SSP2DATPPS = 0x11; //RC1->MSSP2:SDA2; SSP2CLKPPSbits.SSP2CLKPPS = 0x14; //RC4->MSSP2:SCL2; RA5PPSbits.RA5PPS = 0x14; //RA5->EUSART:TX; PPSLOCK = 0x55; PPSLOCK = 0xAA; PPSLOCKbits.PPSLOCKED = 0x01; // lock PPS GIE = state; SSP2CON1 = 0x28 SSP2CON3 = 0x00 SSP2ADD = 0x03 SSP2STAT = 0x00 It could also be that I am using the I2C functions wrong, here is my implementation to receive pressure data from an LPS22HB: void getPressure(void) { uint8_t status = 0; uint8_t pressure_top = 0; uint8_t pressure_mid = 0; uint8_t pressure_low = 0; I2C2_MasterWrite(LPS22_CTRL_REG1, 1, LPS_Address, &status); I2C2_MasterWrite(0b00000010, 1, LPS_Address, &status); I2C2_MasterWrite(LPS22_CTRL_REG2, 1, LPS_Address, &status); I2C2_MasterWrite(0b00011001, 1, LPS_Address, &status); I2C2_MasterWrite(LPS22_PRESS_OUT_XL, 1, LPS_Address, &status); I2C2_MasterRead(pressure_low, 1, LPS_Address, &status); I2C2_MasterWrite(LPS22_PRESS_OUT_L, 1, LPS_Address, &status); I2C2_MasterRead(pressure_mid, 1, LPS_Address, &status); I2C2_MasterWrite(LPS22_PRESS_OUT_H, 1, LPS_Address, &status); I2C2_MasterRead(pressure_top, 1, LPS_Address, &status); |
|
相关推荐
1个回答
|
|
这似乎已经解决了这个thordHTTP://www. McCHIP.COM/FUMMS/M942552.ASPX。
以上来自于百度翻译 以下为原文 This seems to have been resolved on this thread http://www.microchip.com/forums/m942552.aspx |
|
|
|
只有小组成员才能发言,加入小组>>
5141 浏览 9 评论
1989 浏览 8 评论
1917 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3159 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2215 浏览 5 评论
708浏览 1评论
598浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
481浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
609浏览 0评论
508浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-9 08:58 , Processed in 1.404826 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号