完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用PIC16LF18325与SI7000 6湿度传感器通信。在SI7000命令(0xE5)上使用一个保持主模式,我可以发送一个读命令并等待~2MS,直到数据准备好,并且当我查看一个范围时,数据显示得很好(我从范围内做了正确的数学运算)。将数据放入缓冲区。它给了我奇怪的数据。缓冲器中的第一个位置总是与前面的I2C2读字节相同的字节,然后缓冲器中的第二个位置是一些随机数。我不知道这是为什么发生的,数据是正确的,并且它是正确的时钟,信息只是不返回到缓冲器。当我在湿度传感器前后调用不同的传感器时,I2C工作得很好,我将数据读入缓冲区。下面是我正在使用的函数:空隙siWalth[Value](Unt8YT)读缓冲器[2 ];Uti88T写缓冲区[2 ];Unt88t状态=0;WrreBuffer-[0 ]=Ssi-ReliWaseRead;//0xE5 I2C2MyMrdRead(Read Effice,1,SIIAdvor,and Stand);I2C2YMistRead(Read Buffeld,2,SIX地址,和状态);UTI88T HydIdToIP=读缓冲器[0 ];UIT88t HyMIDyBooT=读缓冲器[1 ];γ-DelayuUS(200);EuStudioWrad(HythIDITOP);EuStudioWrad(HythIDyBoT);}
以上来自于百度翻译 以下为原文 I am using a PIC16LF18325 to communicate with an SI7006 humidity sensor. Using a hold-master-mode on the SI7006 command (0xE5) I am able to send a read command and wait for ~2mS till the data is ready and when I look at a scope the data is showing up perfectly (I do the bit math right from the scope) For some reason, the read buffer I am using for I2C2_MasterRead is not putting that data into the buffer. It is giving me strange data. The first location in the buffer is always the same byte as the previous I2C2 read's byte and then the second location in the buffer is some random number. I have no idea why this is happening, the data is correct and it is clocking correctly, the info just isn't getting back into the buffer. When I call different sensors before and after this humidity sensor the I2C works perfectly and I am getting the data into the read buffer. Here is the function I am using: void SiHumidity(void) { uint8_t readBuffer[2]; uint8_t writeBuffer[2]; uint8_t status = 0; writeBuffer[0] = Si_Rel_Humidity; //0xE5 I2C2_MasterWrite(writeBuffer, 1, Si_Address, &status); I2C2_MasterRead(readBuffer, 2, Si_Address, &status); uint8_t humidityTop = readBuffer[0]; uint8_t humidityBot = readBuffer[1]; __delay_us(200); EUSART_Write(humidityTop); EUSART_Write(humidityBot); } |
|
相关推荐
1个回答
|
|
为了迂腐,C89标准只支持代码块顶部的声明变量。然而,这是一种合法的选择:
以上来自于百度翻译 以下为原文 To be pedantic, it's the C89 standard that only supports declaring variables at the top of a code block. This, however, is a legal alternative: void SiHumidity(void) { uint8_t readBuffer[2]; uint8_t writeBuffer[2]; uint8_t status = 0; writeBuffer[0] = Si_Rel_Humidity; //0xE5 I2C2_MasterWrite(writeBuffer, 1, Si_Address, &status); I2C2_MasterRead(readBuffer, 2, Si_Address, &status); { uint8_t humidityTop = readBuffer[0]; uint8_t humidityBot = readBuffer[1]; __delay_us(200); EUSART_Write(humidityTop); EUSART_Write(humidityBot); } } |
|
|
|
只有小组成员才能发言,加入小组>>
5189 浏览 9 评论
2009 浏览 8 评论
1933 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3181 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2232 浏览 5 评论
743浏览 1评论
629浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
512浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
642浏览 0评论
538浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 01:05 , Processed in 1.339940 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号