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

Does it work on atmega328p running on internal clock? #11

Closed lsmar closed 6 years ago

lsmar commented 7 years ago

I'm trying to use this lib with standalone atmega328p running on internal 8Mhz clock, but look like it is not working.

neuoy commented 7 years ago

I'm also using a standalone atmega328p right now, and it works fine with an external 16MHz oscillator. Do you have a reason not to use one ? It would make your chip faster, but I guess it would consume more power, and also you may want to power it with 3.3V in which case I believe you're limited to 10MHz.

About your issue, I'm afraid you have little chance to make it work ; I haven't tested but I think 8MHz is not enough to respond in time when sending bits to the master (including during ROM search). If I remember correctly, you have about 2 micro seconds before the master reads the bus state, which would leave you 16 clock cycles at 8MHz, assuming you're not already starting late due to interrupt latency, and obviously if someone blocks interrupts even for a short time that's as much cycles you'll loose. Maybe it can work, but my guess is it can't.

At the very least, you'll have to adjust timer1 registers so that timings are correct for your frequency, and also some overhead compensation constants. A digital oscilloscope is an invaluable tool for this kind of work, otherwise you have no idea of what actually happens on the wire.