完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嘿,所有的,我试图与MLX90614红外温度传感器接口,以便从RAM地址抓取物体的温度。这种接口是通过I2C完成的,因为MLX90614使用SMBus。问题是我已经尝试了许多代码,并在这个论坛也搜索。不幸的是,我不知道如何解决这个问题。传感器连接到我的PIC18F45 50的RB0和RB1,并且我在MPLABX上使用XC8和一个10MHz的外部振荡器。我使用的是4.7KLaP,传感器的VCC连接到一个分压器,使5V 3.3VS。当我发送启动位或写入传感器的地址时,SPIF标志没有被打开。这是我使用的HTTPS://PaStBi.COM/RTEA7BYU的代码。
以上来自于百度翻译 以下为原文 Hey all, I am trying to interface with an MLX90614 infrared temperature sensor in order to grab the temperature of the object from the RAM address. This interfacing is done through I2C because the MLX90614 uses an SMBUS. The problem is I have tried many codes out there and searched this forum also. unfortunately, I am not able to figure out how to solve this. The sensor is connected to RB0 and RB1 of my PIC18f4550 and I am using XC8 on MPLABx with a 10MHz external oscillator. and I am using 4.7K pull up resistor, and the VCC of the sensor is connected to a voltage divider to make the 5V 3.3V. The SSPIF flag is not being turned on when I send the Start bit or Write the address of the sensor. This is the code I am using https://pastebin.com/rTEA7byu |
|
相关推荐
19个回答
|
|
|
测试I2C之前的忙。它总是启动,它是可能失败的I2C地址。将I2C断言写为单独的函数。1。检查是否有BUBY2。开始3。即使需要一个小时来确定开始,你也不是在等待它完成。
以上来自于百度翻译 以下为原文 Test for busy before asserting i2c. It will always start, it's the i2c address that could fail. Write the i2c asserts as separate functions. _i2c_start: ;void i2c_start() busy: mov #0x1f,w0 and I2C1CON,wreg bra nz,busy bset I2C1CON,#SEN return 1. Check if busy 2. START 3. Even if it took an hour to assert START, you are not waiting for it to complete. |
|
|
|
|
|
谢谢你的回答。事实上,我对这个领域有点陌生(I2C)。你能更明确地解释一下你的答案吗?至于汇编代码,IVE以前使用XC8汇编有一个坏的经验。
以上来自于百度翻译 以下为原文 Thank you bro for your answer. Actually, I am a bit new to this field (i2c). Can you clarify your answer more please? And as for the assembly code, Ive had a bad experience using assembly with xc8 before. |
|
|
|
|
|
创建单独的函数。启动、停止重启、写入、读取伪函数来读取来自I2C设备的数据串。无效I2Ci获取(int ID2Ic,int地址,ValueDest-int Len);Stastrrid ID清除位0写入ADADESREST STARTWITRID ID设置位0::::循环LEN最后=最后一个字节?真:false data =::(最后)将数据保存到[Dist++]::Ne::LeNeX:::ListRebug等待RCEDATABAS= I2C1RCVIF,最后一个是真的设置AKDT,否则用数据清除ACKDTset ACKENreturn
以上来自于百度翻译 以下为原文 Create separate functions. START, STOP RESTART, WRITE, READ A pseudo function to read a string of data from an i2c device. void i2c_ gets(int ID_I2C, int Address, void *Dest, int Len); start write id | clear bit 0 write address restart write id | set bit 0 ::for:: loop Len last = last byte ? true : false data = ::read:: (last) save data to [Dest++] ::next:: Len stop ::read:: last RCEN wait for RCEN data = I2C1RCV if last is true set ACKDT else clear ACKDT set ACKEN return with data |
|
|
|
|
|
HTTPS://PASTBIN COM/6FTZAQHNI试图划分I2C方法。我得到空的答案。s/StastButs.s){/*检查是否开始检测最后*/返回0;/*返回0以指示开始失败*/}这是进入条件块
以上来自于百度翻译 以下为原文 https://pastebin.com/6FTzaQhn I tried to divide the I2C methods. I am getting null acks. if (!SSPSTATbits.S) { /* Check whether START detected last */ return 0; /* Return 0 to indicate start failed */ } this is entering the conditional block |
|
|
|
|
|
问题可能是因为没有设置RB0和RB1作为数字输入。
以上来自于百度翻译 以下为原文 Might the problem be due to not setting RB0 and RB1 as digital inputs |
|
|
|
|
|
是的,它可以。你必须切换模拟能力引脚到数字模式,使用他们以外的任何ADC或比较器。
以上来自于百度翻译 以下为原文 Yes it can. You must switch analog capable pins to digital mode to use them for anything other than the ADC or comparator. |
|
|
|
|
|
非常感谢,我在我的配置头文件中添加了一个“PrimaMaMatg配置pBeNe=”,它工作了一段时间,我可以读取。不幸的是,我关闭了系统,然后停止了工作。现在,我的I2CyRead()函数中的流被困在“while(bclif)”上。你认为问题是什么?HTTPS://PaSTBiN.COM/71X2AWRNTHIS是我的全部项目
以上来自于百度翻译 以下为原文 Thank you very much, I added #pragma config PBADEN = OFF to my configuration header file , it worked for a while and I was able to get readings. Unfortunately, I turned the system off and on , then its stopped working. The flow is stuck now on "while (BCLIF);" in my I2C_Ready() function. What do you think is the problem ? https://pastebin.com/71x2Awrn This is my full project |
|
|
|
|
|
为什么在主C文件中有这些行?它们只属于一个头文件文件中,这条线已经被XC.H收录了,所以你只需要做第二次。如果这些行实际上是头文件的内容,你的配置语句不应该在头文件中,它们应该在C文件中出现一次。现在在我的I2CyRead()函数中粘贴“WITH(Bclif)”。为什么在WHER()里面有它?如果发生总线冲突,它不会自行消失。如果该位已被设置,则有拉一个SDA或SCL的低电平。在你的代码开始时信号是否很高?在看到Bclif集合之前,究竟是什么工作?
以上来自于百度翻译 以下为原文 Why are these lines in your main C file? They only belong in a header file // This is a guard condition so that contents of this file are not included // more than once. #ifndef USART_HEADER_FILE_H #define USART_HEADER_FILE_H Get rid of this line: #include that has already been included by xc.h, so you are just doing it a second time. If those lines are actually the contents of a header file, your CONFIG statements should NOT be in a header file, they should occur ONCE in a C file. [quote The flow is stuck now on "while (BCLIF);" in my I2C_Ready() function. Why do you have that there inside a while()? If a bus collision occurs, it's not going to go away by itself. If that bit has got set, something is pulling one of SDA or SCL low. Do you have pullups? Are the signals high at the start of your code? What exactly does work before you see BCLIF set? |
|
|
|
|
|
谢谢你的回复。关于你提到的行,是的,它们在一个USAT头文件中。我还有另一个配置头文件。这是个好办法吗?还有,while循环是因为我从这里获得了I2C函数,这里是HTTP://www. EngICWIG.SCO/PIC/PIC18F450-I2C。实际上,我不知道这是不是正确的事情。我应该换什么?我把SCL和SDA连接到2K上拉电阻到5V。奇怪的是,它仅仅在一个小时前工作。“你的代码开始时信号高吗?”对不起,我不理解这个问题。在检查Bclif设置之前,我启动I2C并发送启动脉冲。
以上来自于百度翻译 以下为原文 Thank you for your reply. Regarding the lines you mentioned, yes they are in a USART header file. I also have another config header file. Is this a good approach? Also, the while loop is there because I took the I2C functions from here http://www.electronicwings.com/pic/pic18f4550-i2c . Actually, I don't know if this is the right thing to do. What should I change? I have the SCL and SDA connected to 2K pull up resistors to 5v. Its weird, it was just working one hour ago. "Are the signals high at the start of your code?" sorry I didnt understand this question. Before checking the BCLIF if set, I initiate the I2C and send the START pulse. |
|
|
|
|
|
不幸的是,我认为这是一个非常蹩脚的示例软件,你发现了,但没有意义的等待。看看它关于PIC18F45数据表中Bclif位的说法。(我大胆)。如果设置了那个标志,你必须清除它,它不会自行发生。个人而言,我不认为这个人。谁写的代码真的很熟悉外围设备,他们正在做很多毫无意义的事情。它把所有的干扰都混淆成一个单一的代码块。正如我所说的,配置比特不应该在头文件中。它们应该在一个C文件中。如果将它们放在头文件中,那么它们实际上会在包含该头文件的每个C文件中结束。个人而言,我认为它们属于主C文件。任何人回顾你的代码都会想看到它们,而在另一个文件中找到它们是很烦人的。我的意思是,在尝试发送启动条件之前,SDA和SCL都是高电平的吗?
以上来自于百度翻译 以下为原文 Unfortunately, I think that's pretty crappy example software you have found, exemplified but that pointless wait. Look what it says about the BCLIF bit in the PIC18F4550 datasheet. (My bolding.) If that flag is set, you have to clear it, it doesn't happen by itself. Personally, I don't think the person who wrote that code really knows the peripheral very well, they are doing lots of pointless things. It's confusing jamming all of it together into a single block of code. As I said, NO the config bits should not be in a header file. they should be in one C file. If you put them in a header file, then they effectively end up in every C file that includes that header file. Personally, I think they belong in the main C file. Anyone reviewing your code will want to see them, and it's annoying to have to go find them in another file. I mean are the SDA and SCL pins both high before you try to send the START condition? |
|
|
|
|
|
啊,我明白了。谢谢你的澄清。我应该用什么来替换这个循环呢?我将在主C文件中替换它们。实际上,在发送开始条件之前,我只配置I2C。
以上来自于百度翻译 以下为原文 Ahh, I understood. Thank you for your clarification. What should I replace this while loop with? I will replace them all in the main.c file No actually I only config I2C before I send the START condition PIE1bits.SSPIE = 0; SSPSTAT = 0xC0; /* Slew rate disabled, other bits are cleared */ SSPCON1 = 0x28; /* Enable SSP port for I2C Master mode, clock = FOSC / (4 * (SSPADD+1))*/ SSPCON2 = 0; SSPADD = 0x18; /* Clock 100 kHz */ SSPIE = 1; /* Enable SSPIF interrupt */ SSPIF = 0; |
|
|
|
|
|
事实上,在发送启动条件条件之前,我只配置I2C,而不是一次测试一次代码。配置I2C,但不要发送开始。用一个表检查这两个引脚,并确认它们都是高的。然后,添加代码只做启动。测量你的PIN,并确保它们现在都是低的。如果你有一个存储范围,观察PIN所做的事情并确保SDA在SCL之前下降。不允许你的主函数退出。在末尾添加一个无休止的循环来阻止这个。
以上来自于百度翻译 以下为原文 No actually I only config I2C before I send the START condition Try testing your code one step at a time rather than all at once. Configure I2C, but don't send the START. Check those two pins with a meter, and verify they are both high. Then, add the code to do the START only. Measure your pins, and make sure they are now both low. If you have a storage scope, watch what the pins do and make sure SDA drops before SCL. Do NOT allow your main function to ever exit. Add an endless loop at the end to stop this. |
|
|
|
|
|
事实上,我有万用表。只有初始化I2C,SCL上的电压是4.3V,在SDA 1.3V。在运行开始后,SCL上的电压是0.05V,在SDA 3.8V.谢谢,我在末尾添加了一个无限循环。
以上来自于百度翻译 以下为原文 Actually, I have a multimeter. With only initializing the I2C, Voltage at SCL is 4.3V and at SDA 1.3V. After I run the start, Voltage at SCL is 0.05V and at SDA 3.8V. Thanks, I added an infinite loop at the end. |
|
|
|
|
|
然后,你有一个问题,这是毫无意义的过程,直到你解决这个问题。直接在外围设置为I2C模式后,SDA和SCL都应该是浮动输入,所以将被外部拉高电阻拉高。你需要确定为什么SDA不高。
以上来自于百度翻译 以下为原文 Then you have a problem, and it's pointless proceeding until you fix that problem. Straight after the peripheral is set to I2C mode, both SDA and SCL should be floating inputs, so will be pulled high by your external pullup resistor. You need to determine why SDA is not high. |
|
|
|
|
|
奇怪的是,我开始为所有代码添加注释,只保留初始化。然后我检查了SDA电压和它的3.8V。但是在我没有注释所有代码之后,它也有3.8V,整个代码都在工作。我不希望系统突然停止工作,因为我有一个演示在大学里。你能帮我吗?
以上来自于百度翻译 以下为原文 Its weird, I started adding comments for all my code and only keeping the initialization. I then checked for SDA voltage and its 3.8V. But after I uncommented all the code its also 3.8V and the whole code is working now. I dont want the system to suddenly stop working because I have a demo to present at university can you help me please ? |
|
|
|
|
|
编辑:我关掉电源,回到问题,SDA卡在1.2V。怪异。
以上来自于百度翻译 以下为原文 Edit: I turned the power off then on , back to the problem and SDA is stuck at 1.2V. weird |
|
|
|
|
|
嗨,有没有连接到I2C的设备有来自其他地方的电源?无论如何,你可以切断电源到所有电源,等一分钟,再启动电源,再试一次。问候,Mysil。
以上来自于百度翻译 以下为原文 Hi, Does any of the devices connected to I2C, have power supplied from anywhere else? Anyway, you may switch off power to all devlces, wait a minute, before powering up and trying again. Regards, Mysil |
|
|
|
|
|
好的,伙计们,我想我知道这个问题,它来自这个版本的传感器。这个版本的传感器有点奇怪,当我初始化I2C,然后拔出传感器,然后插上电源和VCF脚,然后SDA和SCL,然后在SDA上电压被拉到3.8V。如果不这样做,在传感器的存在下,电压大约在1VI时,首先用ARDUNO使用这个传感器,当代码运行时,我必须做同样的事情:删除传感器,然后将其恢复,或者删除SDACCLE,然后重新填充它。同样的问题:http://fUMU.ESPURION.COM/Talkss/28063/http://FurUM.ARDUION.cc/NeXX.PHP?题目是329 14615这是一个非常奇怪的问题,我怎么解决呢?
以上来自于百度翻译 以下为原文 Ok, guys, I think I know the problem and it is from this version of the sensor. This version of the sensor is somehow weird it works when I initialize I2C then unplug the sensor then plug the power and vcc legs and then the sda and scl back after that the voltage is pulled to 3.8V at SDA. Without doing this, and with the presence of the sensor, the voltage would be around 1V I first figured this out when using this sensor with Arduino, I had to do the same thing while the code is running: remove the sensor then replug it or remove the sda cable then replug it. I think guys here had the same problem: http://forum.espruino.com/conversations/280634/ https://forum.arduino.cc/index.php?topic=329146.15 It is a very weird problem, How can I solve it ? |
|
|
|
|
|
HI,在MelxIS Melx90614的数据表中解释:这些传感器默认存在一个PWM输出。SDA引脚测量的奇怪电压不是DC,它是一个PWM信号,表示传感器所看到的温度。PWM可以被关闭,使用SMBus /I2C通信,B。在数据表第8.6章中描述的Y后续过程,第2HTTPS://www. MelxIS.COM/En/Optudit/MLX90614/Digabal-Pixel-ReloMistor to MysIL
以上来自于百度翻译 以下为原文 Hi, It is explained in Datasheet from Melexis for MLX90614: These sensors have a PWM output that is active by default. The strange voltage measured at SDA pin, is not DC, it is a PWM signal representing the temperature seen by the sensor. The PWM may be switched Off, to use SMBUS / I2C communication, by following procedure described in datasheet chapter 8.6, page 26. https://www.melexis.com/en/product/MLX90614/Digital-Plug-Play-Infrared-Thermometer-TO-Can Mysil |
|
|
|
|
只有小组成员才能发言,加入小组>>
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:37 , Processed in 1.763437 second(s), Total 108, Slave 91 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
5830