1

I made an implementation of 1-wire protocol for the Raspberry Pi adapted from this book. It uses bit banging to implement the communication protocol. The function bcm2835_delayMicroseconds() from the BCM2835 library is used to produced required delays.

It works quite well, but not completely reliable: sometimes i get no response from the sensor. I used an oscilloscope to trace the problem. Here the oscilloscope screenshot with signal interpretation in green. enter image description here The red marks the fault: the bit starting low pulse got prolonged thus inserting a rogue '0'. This caused the sensor not to recognize the command and not to respond to it (subsequent '1's).

I beleive this happend because the OS preempted (switched to another task/thread/process) during transmission of this bit. So is it possible to tell the Linux not to preempt during the execution of a certain function (for writing and reading of a single bit in this case)? Or perhaps there is another solution to this problem?

Andrey Pro
  • 501
  • 1
  • 10
  • 22
  • You can try setting the priority class of your thread to real-time, `sched_setscheduler()` with `SCHED_FIFO` or `SCHED_RR`. But beware! if you consume 100% of the CPU in a real-time thread, you will not be able to kill it. – rodrigo Feb 15 '18 at 20:20
  • Also see [A realtime preemption overview](https://lwn.net/Articles/146861/) on LWN, ["TASK_UNINTERRUPTIBLE" linux](https://www.google.com/search?q="TASK_UNINTERRUPTIBLE"+linux) and [What is an uninterruptable process?](https://stackoverflow.com/q/223644/608639) on Stack Overflow. – jww Feb 16 '18 at 01:53

0 Answers0