rambo / TinyWire

My modifications to TinyWire Arduino libs
284 stars 121 forks source link

How often should I call TinyWireS_stop_check()? #5

Closed klawyMarcin closed 10 years ago

klawyMarcin commented 10 years ago

Are there any calculations?

rambo commented 10 years ago

no, but supposing a normal START slave_w_addr reg_addr STOP START slave_r_addr R R STOP pattern it depends on how quickly the master is going to start the second transaction as well as the raw bus speed. Probably you will have to experiment, but I would recommend keeping especially the onreceive and onrequest handlers very short (basically just managing the register pointer and sending data) and use the pattern used by many devices where the master will trigger some long-running task by writing a register and then periodically polling another one to see if it has completed. The slave will then handle the task (some sort-of pre-emptive multitasking [or simply sprinkling those check calls in between the long running code] is possibly needed), update the data registers and set up the "data ready" flag.