neuoy / OneWireArduinoSlave

An arduino library to communicate using the Dallas one-wire protocol, where the Arduino takes the role of a slave. Entirely implemented using interrupts, you can perform other tasks while communication is handled in background.
58 stars 19 forks source link

Sending to scratchpath #7

Closed Servayejc closed 7 years ago

Servayejc commented 8 years ago

How can I simulate a write to the scratchpath (0x40) In the demo program, this case is empty... (case DS18B20_WRITE_SCRATCHPAD:)

neuoy commented 7 years ago

Hi, and sorry for the late reply.

I think the demo shows enough of the library to allow users to grasp the concept and write their own code around it ; the goal is not to implement all the features of a DS18B20.

I won't answer your question with too much details now because it's probably way too late, and also not directly related to the library itself. I'll just say that you'd need to store the received bytes in some kind of buffer, and increment a counter for each byte received (i.e. each time the owReceive function is called) to know where in the buffer you need to write the next one. You need to store the current state (what you are doing), since owReceive is called again for each byte : after a reset, the first byte received is the command, then you'll receive the first scratchpad byte, then the second scratchpad byte, and so on. How you store that state, and what you do with each byte, is up to you.