nimaltd / ds18b20

ds18b20 library for stm32 hal
GNU General Public License v3.0
139 stars 43 forks source link

Very long and unreliable startup, unreliable reading #8

Open sokol07 opened 2 years ago

sokol07 commented 2 years ago

Hi, I am using your code with STM32F411 (disco board) and some chinese probe based on DS18B20. I am using CubeIDE but I've modified a few places in code to let is find all definitions and I've got the code running. However, the temperature read from DS18B20 is extremely unstable and unreliable, making the sensor totally unusable. The task is called as it should be, the DS18B20 address is detected correctly (I can see the address in the debug), usually the temperature is read correctly once and then the data is not read (isValid=0) for dozen seconds (sometimes minutes). After this time the data is read once again and then is invalid again. image Sometimes the situation is even worse - I don't even get the address of the DS18B20. I lowered the update interval timeout to 1000ms but this doesn't seem to cause the issue because I have the same problems when the timeout is set to 10000ms or even 20000ms. Is there something I am missing which causes these problems? Can this be made more reliable some way?

EDIT - after some debugging I see that the issue is the CRC which is invalid (crc is not equal to data[8]). There are values within data[] are partially just series of 1s like this: image

sokol07 commented 2 years ago

Using an oscilloscope I determined that the responses from the DS18B20 were valid but for some reason not read correctly by the STM32. I moved the task so it is created first (I don't remember whether the order of task creation matters on their execution but I think I have read that they are executed subsequently as created (as long there isn't some kind of flow control) and changed its priority to higher than any other task. For now the sensor is working correctly, it is starting without problems and keeps working without invalid data with refresh rate of 450ms (I had some invalid data with lower refresh times).

I'll keep watching the device, if the problem is solved we can consider this issue closed but I suggest adding a note to library readme to point out that the task priority can be an issue.

sokol07 commented 2 years ago

Unfortunately, increasing the priority only seemed to fix the issue - it worked for some time but today the same code doesn't read the temperatures correctly (i get only one valid read in a dozen). The problem lies somewhere else and the DS18B20 is still unusable. Therefore, the issue is still open...