Software I2C odd behaviour
Posted: Thu Jul 01, 2021 8:31 am
Hi,
I am having an issue that i cant seem to narrow down. Thought it worth posting in case anyone else has a similar issue.
I am using PIC32MX575F256L
I have several sensors on I2C bus, using software I2C. So far i have an RTCC and Pressure sensor working perfectly.
A few days ago i started coding in a temperature sensor. This is where things get odd.
I tell the sensor to take a sample, wait and then receive the data into MSB and LSB. These are stored in a string array.
I then create a 16 bit value from the MSB and LSB.
This data is all output to a terminal so i can see what data is being read and then it tells me the temperature value following conversions
This is something that i am familiar with an have done many times before.
So, the weird part.
Randomly, I read the MSB from the array as, lets say 0x6C, but it gets shifted into the 16bit variable as 0xFF. Meaning that my 16bit value is incorrect.
**So far i have tried replacing the sensor, twice. So i dont think its faulty.
**The data is read first and stored. Then data is manipulated.
**Most of the time it works as expected. Randomly the 16bit value is corrupted.
Any ideas on anything i can do to get to the bottom of this?
Is there any reason where a value in an array could be misread?
I am having an issue that i cant seem to narrow down. Thought it worth posting in case anyone else has a similar issue.
I am using PIC32MX575F256L
I have several sensors on I2C bus, using software I2C. So far i have an RTCC and Pressure sensor working perfectly.
A few days ago i started coding in a temperature sensor. This is where things get odd.
I tell the sensor to take a sample, wait and then receive the data into MSB and LSB. These are stored in a string array.
I then create a 16 bit value from the MSB and LSB.
This data is all output to a terminal so i can see what data is being read and then it tells me the temperature value following conversions
This is something that i am familiar with an have done many times before.
So, the weird part.
Randomly, I read the MSB from the array as, lets say 0x6C, but it gets shifted into the 16bit variable as 0xFF. Meaning that my 16bit value is incorrect.
**So far i have tried replacing the sensor, twice. So i dont think its faulty.
**The data is read first and stored. Then data is manipulated.
**Most of the time it works as expected. Randomly the 16bit value is corrupted.
Any ideas on anything i can do to get to the bottom of this?
Is there any reason where a value in an array could be misread?