9 years, 8 months ago.

DS1820 library with mbed-rtos

Hi Erik,

I've tried the DS1820 library on a small LPC1768 Dev board several weeks ago. I've then design my own pcb based on the schematic of that board, and those past days I've assembled it after receiving the prototype. During my tests, I figured out that DS1820 wasn't initialized properly, sometime not seeing devices, and when it does, most of the time, it returns -1000oC temperatures, and sometimes it is even freezing the whole CPU. After spending several hours of debugging, I figured out that this behavior was happening only when things were done from an RTOS thread, but everything works well if done in the main thread. Do you have any idea why ?

Martin.

Question relating to:

DS1820 Hello World

1 Answer

9 years, 8 months ago.

First of all, if you have mulitple devices you need to make sure you use the latest version, 12 days ago I fixed a bug regarding usage of multiple DS1820s.

I haven't tried it with RTOS myself, but I assume it is because it bitbangs a timesensitive protocol: The moment RTOS switches to another thread it will break the transmission. When using DS1820 code either completely disable interrupts:

__disable_irq();
__enable_irq();

Or set (temporarily) the thread which reads temperature to the highest priorty, I believe it is something called realtime, and make sure there are no others with that priority. This should prevent other threads from interrupting it.

I would assume that solves it, but if not, then I wouldn't know either.

Accepted Answer

Hi again Erik, Yes, that was it ! Thanks for the hint ! Do you think that the irq disable/enabled would be better located in the library ? Regards, Martin.

posted by Martin Ayotte 13 Mar 2015

It might be, but then I got to check out what kind of interruptions would be allowable otherwise (to see if it would be possible for some interrupts to function without breaking the transmission), and how long in total it blocks interrupts.

For example USB also needs interrupts, and you might prefer a wrong temperature conversion over your USB connection failing.

posted by Erik - 13 Mar 2015