完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
试图编写一个I2C驱动程序,我在另一个文件中工作,我刚刚移植了这些函数。PIC12LF1840的后端代码是使用MCC创建的。我试图建立与MMA845 2Q加速度计的COMS。我怀疑别针是断开的,但我不完全肯定。这是MCC为PixMealth.C生成的(注意,我使用RC1作为SCL和RC2和SDA)LATA= 0x06;TrISA=0x3f;ANSELA=0x10;WPUA= 0x00;opthyRePix.NWPUEN=0x01;APFCONN=0x00;这些是正确的吗?编辑:如果我做了I2C传输,我的EuStudio写不再工作,如果我没有任何,那么EuStudioWrad将工作。这里是我实现的代码,现在只写一个:MaAdAdabess=0B011100;/7位地址到0Unt88t写缓冲区[U];Unt88t状态;WrreBuffer-[ 0 ]=MMAYCCTLL ReGy1;WrreBuff[1 ]=0B90000;//低噪声,快速读取,最快数据速率I2C.MistWrrad(Read Effice,2,MMAAAD)服饰,地位;= I2CyMasaGug完成;
以上来自于百度翻译 以下为原文 Trying to write an I2C driver that I had working in another file and I just ported over the functions. The back-end code for the PIC12LF1840 was created using MCC. I am trying to set-up coms with a MMA8452q accelerometer. I suspect the pins are off but I am not completely sure. This is what MCC generated for pin_manager.c. (note I am using RC1 as SCL and RC2 and SDA) LATA = 0x06; TRISA = 0x3F; ANSELA = 0x10; WPUA = 0x00; OPTION_REGbits.nWPUEN = 0x01; APFCON = 0x00; Are these correct? edit: If I do an I2C transmission, my EUSART_Write no longer works, and if I don't have any then EUSART_Write will work. Here is my implemented code, only doing one write for now: MMA_Address = 0b0011100; //7-bit address with SA0 pin to 0 uint8_t writeBuffer[2]; uint8_t status; writeBuffer[0] = MMA_Ctrl_Reg_1; writeBuffer[1] = 0b00000000; //low-noise, fast-read, fastest data rate I2C_MasterWrite(writeBuffer, 2, MMA_Address, &status); while(status != I2C_MESSAGE_COMPLETE); |
|
相关推荐
19个回答
|
|
|
最明显的一点是:如果你在RC*上工作,我们希望看到ANSELC、TISSC等等。
以上来自于百度翻译 以下为原文 The most obvious one: If you're working on RC*, we would like to see ANSELC, TRISC etc. The *A registers don't help. |
|
|
|
|
|
呸!我在看以前为另一个PIC编写的代码,用于同一个传感器。对于正确的程序,Pin管理器C是:LATA= 0x06;TrISA=0x3f;ANSELA=0x10;WPUA=0x00;opthyRePix.NWPUEN=0x01;APFCONN=0x00;
以上来自于百度翻译 以下为原文 Doh! I was looking at the previous code I had written for another PIC that was used to talk to this same sensor. The pin_manager.c for the CORRECT program is: LATA = 0x06; TRISA = 0x3F; ANSELA = 0x10; WPUA = 0x00; OPTION_REGbits.nWPUEN = 0x01; APFCON = 0x00; |
|
|
|
|
|
|
|
|
|
|
|
哦,伙计,我星期一早上过得很愉快。寄存器是正确的,这是我错的别针。在PIC12LF1840上没有C寄存器。对于SDA,我使用的是SLK和RA2的RA1。
以上来自于百度翻译 以下为原文 Oh man I am having a great Monday morning. The registers are right, it is the pins that I was wrong about. There is no C registers on the PIC12LF1840. I am using RA1 for SCLK and RA2 for SDA. |
|
|
|
|
|
如果这是一个I2C从机,TrISA就可以了。对于一个主机,TrISA 1和TrISA 2应该首先被清除。(Tras.2将被动态地重新配置,因为它的双向性质)弱拖动可能不够-取决于I2C速度。无论如何,只要我解释正确-没有选择(WPUA=0)。
以上来自于百度翻译 以下为原文 If this is supposed to be an I2C slave, TRISA is ok. For a master, TRISA.1 and TRISA.2 should be cleared initially. (TRISA.2 is to be dynamically reconfigured due ti its bidirectional nature.) Weak pull-ups may not be enough - depending on I2C speed. Anyway - provided I interpret correctly - none is chosen (WPUA = 0). |
|
|
|
|
|
我在时钟和数据上有10KOHM上拉电阻。所以这不应该是个问题,好像MMA845 2Q从来没有发送信息回来或什么。如果我只是在我的while循环中做一个简单的EuStudioWrutWe(),我可以在一个终端上读取它,但是当我做任何类型的I2C写时,它会被保存在那里。不知道到底出了什么问题,这些确切的驱动程序已经用于我使用的PIC16LF18325。它被困在我的代码中:这意味着I2C消息永远不会完成编辑:我发现的另一个注意点是,即使在第一次传输时,我也看不到时钟会一直走高。我用范围探测器监视时钟线,但似乎什么也没有发生。在我的第一个I2C写之前,我用了5秒的延迟,监控了PIN,但什么也没有发生。
以上来自于百度翻译 以下为原文 I have 10kohm pull-up resistors on clock and data. So that should not be a problem. It seems like the MMA8452q just never sends info back or something. If I just do a simple EUSART_Write() in my while loop I can read it on a terminal but when I do any sort of I2C write, it gets held up there. Not sure what is going wrong, these exact drivers have worked for the PIC16LF18325 I had used. It gets stuck here in my code: while(status != I2C_MESSAGE_COMPLETE); Meaning that the I2C message is never completing edit: Another note I found is that I never see the clock ever go high, even on the first transmission. I am monitoring the clock line with a scope probe and yet nothing seems to happen. I put a 5 second delay right before my first I2C write and monitored the pin and nothing happens. Any idea what is going on? |
|
|
|
|
|
我们最近有一个类似的线程-不同的PIC,但MCC和I2C建议通过一个-特别注意“地址”和“使用哪一个例程”的贡献。HTTP://www. McCHIP.COM/FUMMS/M1020538ASPX应该有助于解决你的问题。
以上来自于百度翻译 以下为原文 We had a similar thread recently - different PIC, but MCC and I2C. Suggest to go through that one - paying special attention to the "address" and "which routines to use" contributions. http://www.microchip.com/forums/m1020538.aspx Should help to get around your issue. Othwise: come back here. |
|
|
|
|
|
你好,不幸的是,线程没有给我答案。我使用MCC 2.7,我还没有修改I2C写代码。我看到的是我的SCLK线从来没有高或低(即使在第一次传输),我的SDA线总是大约1/2 VCC。我认为它与PIN分配有关,但不能确定什么是错误的。编辑:没有什么是时钟的原因是因为我已经启用了全局中断,有些东西造成了中断。但是,当我禁用互通时,我仍然没有看到SCLK。我已经切换到MCC V3.15SCLK总是高,SDA在1/2 VCC附近。
以上来自于百度翻译 以下为原文 Hello, Unfortunately that thread did not have the answer for me. I am using MCC 2.7 which and I have not modified the I2C write code. What I am seeing is that my SCLK line never goes high or low (even on first transmission) and my SDA line is always about 1/2 VCC. I think it has something to do with Pin assignment but can't figure out what is wrong. edit: The reason that nothing was clocking was because I had global interrupts enabled and something was causing an interrupt. However, when I disable interupts, I still am not seeing the SCLK. I have switched to MCC v3.15 SCLK is always high and SDA is somewhere near 1/2 VCC |
|
|
|
|
|
使用调试器可以通过什么?难道TX根本没有尝试吗?(我希望有一个同事开始插嘴。)()
以上来自于百度翻译 以下为原文 What about using the debugger to step through? Could it be there is no attempt to TX at all? (I hope one of the colleagues starts chiming in. |
|
|
|
|
|
ADTON:尝试TrISA=0x39;作为init值(我已经提到TrISA)。
以上来自于百度翻译 以下为原文 Addon: try TRISA = 0x39; as the init value (I already mentioned TRISA). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
不幸的是,这也不起作用。I2C甚至没有尝试,这真的令人费解。如果我监视时钟引脚并对其进行供电,时钟线就停留在整个时间的0。要走一步,看看发生了什么。编辑:我看到从I2C返回的状态总是I2CYMaseAgEuth-FAIL,只有在执行时才发生:I2CYObjut.TrStUST.S.Purn!=真
以上来自于百度翻译 以下为原文 Unfortunately that did not work either. I2C is not even making an attempt, which is really puzzling. If I monitor the clock pin and power it, the clock line just stays at 0 the entire time. Going to step through and see what happens. edit: I see that the status that comes back from I2C is always I2C_MESSAGE_FAIL, which only happens when this executes: i2c_object.trStatus.s.full != true |
|
|
|
|
|
如果缓冲区满了,它就不能摆脱字节。你真的在正确的线路上拉上了吗????不短????或者这些针现在开枪了吗?值得一试的东西:重置芯片!当保持在复位时,这些线必须是高的,如果一切都好的话。如果不是,请参阅我的第2行。
以上来自于百度翻译 以下为原文 If the buffer is full, it cannot get rid of the byte(s). DO YOU REALLY HAVE PULLUPS on the right lines ??? and NO SHORT ??? Or are these pins shot now ? One thing worth trying: reset the chip! While held in reset, these lines MUST be high if everything is ok. If not: see my line #2. |
|
|
|
|
|
实际上,我刚刚把上拉电阻取下来。现在我的SDA总是在GND,我的SCLK在空转。我回到我的RealStasts的默认值。TrISA=0x3f;ANSELA=0x10;LATA= 0x00;如果我启用全局和外围中断,我的代码会被挂在I2C.MistMist-IDLE中。这就是我现在所在的地方,我从来没有看到时钟或数据线移动。我在这一个损失,不能得到I2C做任何其他想法:我正在使用HF 16 MHz的内部时钟,并使用FoSC的系统时钟选项和国际证监会振荡器选择。我还启用了PLL。没有WDT。
以上来自于百度翻译 以下为原文 I actually just took off the pull-up resistors. Now my SDA is always at GND and my SCLK is idling high. I went back to default values for my registers. TRISA = 0x3F; ANSELA = 0x10; LATA = 0x00; If I enable global and peripheral interrupts my code gets hung up in I2C_MASTER_IDLE. That is where I am now, I never see the clock or data lines move at all. I am at a loss on this one, can't get I2C to do ANYTHING Other ideas: I am using HF 16 MHz on the internal clock, and use FOSC for the system clock option and INTOSC for oscillator select. I also have PLL enabled. No WDT. |
|
|
|
|
|
重新阅读自上而下的建议怎么样?还是重复一遍呢?没有拉起,你期待什么结果?那么为什么没有被拉升的DLN SCLK高?用TrISA=0x3f?你可以继续摆弄阿鲁德。你甚至可以开始阅读文件。当我们不得不告诉世界人口的时候,我们不高兴…
以上来自于百度翻译 以下为原文 What about re-reading the recommendations top-down? Following them. Or should WE repeat that ? What outcome do you expect without the pull-ups ? And why is the darn SCLK high without pull-up? and with TRISA = 0x3F? You may continue to fiddle aroudn. You may even start reading the documentation. Be we are not happy when we have to tell things for the ump-th time ... |
|
|
|
|
|
结果是,如果我用电源供电,而不是PICTIT3,它就工作了。我一直保持上拉电阻。如果我使用不带上拉电阻的PICTIT3,它仍然不工作。
以上来自于百度翻译 以下为原文 Turns out that if I power it with a power supply and not the pickit3, it works. I kept the pull-up resistors on. If I used the pickit3 without the pull-up resistors, it still doesn't work |
|
|
|
|
|
I2C上的上拉电阻?直到现在没有人告诉你,I2C上的上拉电阻是强制性的,不是可选的吗????
以上来自于百度翻译 以下为原文 The pull-up resistors on I2C? Did nobody until now tell you that the pull-up resistors on I2C are mandatory - not optional ??? |
|
|
|
|
|
我有上拉电阻,并始终有。我只是试着把它们取下来,去掉每个数据和时钟线上的1/2个VCC,看看是不是。问题在于PICTIT3。PACTIT3上的拉力必须干扰我的或类似性质的东西。还没有完全明白。
以上来自于百度翻译 以下为原文 I have the pull-up resistors on, and always have. I only tried to take them off to get rid of that 1/2 VCC on each data and clock line issue to see if that was it. The problem lies with the pickit3. The pull-ups on the pickit3 must be interfering with mine or something of that nature. Haven't completely understood it yet. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1097浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 07:45 , Processed in 1.377368 second(s), Total 110, Slave 93 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2870