The code below runs on an Arduino Pro Mini (8MHz 328p) sending temperature readings using an inexpensive ASK transmitter. I use OneWire to read the DS18B20s, and RadioHead to manage the radio.
The original problem was the send() calls at the top of the loop always worked, but the send() call in the temperature-reading loop never did.
The fix was to insert a call to setModeTx() ahead of the send() call. I'm pleased it works, but it's a hollow victory because I can't figure out why it works.
OneWire uses no timers and no interrupts. I wait for the temperature conversion using _delay_ms() which is a spin delay.
I've read and re-read the OneWire and RH_ASK code and am still puzzled. Can anyone explain?
Many thanks
Here's the gist of the code…
RH_ASK radio(1024, 0, 10, 0, false);
OneWire ow(2);
void loop()
{
radio.send(/* build info /); // always works
radio.send(/ battery health */); // always works
ow.reset_search();
while (ow.search(addr))
{
read_thermometer(addr);
// the following send() works ONLY
// when preceded by setModeTx()
// It *never* works without it
radio.setModeTx();
radio.send(/* one temp reading */);
}
}
UPDATE
@timemage was correct in that there are also calls to Serial (which resolve to HardwareSerial) interspersed. I'm no closer to solving it; however, by rearranging calls I can get the failure to happen more- or less often.
In a way this highlights the distinction between diagnosis and repair. I may in the end discover an ordering of the calls that makes the failure exceedingly rare, and in this case the problem will have been repaired; though not diagnosed.

