What happens when num is more than 4 or less than 1? The code needs more guards in it to ensure that it's not waiting forever for a chip that doesn't send exactly the requested number of bytes. A glitch on the line or anything you didn't plan for will break this code in a very bad way (infinite loop, most probably.)
Wow great to hear that someone has success with I2C on DUE! I have 1.6.5 (so understand not the issue with 1.6.6 beta discussed here) and too much experience with I2C on ATR but on DUE can't get anything to work. Trying to use SCL1/SDA1. Have tried both scanners with modes for wire1. Updated the wire lib etc. Tried multiple external pullups to 3.3v - 2k2, 4k7, 1k, 10k. What's the trick?Thank you!
#define I2C Wire1
MrAl - bbx10node said it very well - the 2.2k resistors are needed on Due SDA1/SCL1 but the built in 1.5ks on sda/scl 20/21 seem fine. The libraries that use wire would have to be changed to use wire1 if you use sda1/scl1 but no software or hardware changes should be required if you use 20/21 instead. Wouldn't it be great if somebody with a scope could check these Bbx10node - VERY WELL SAID! I used #ifdef AVR (for uno) and #else for DUE so the UNO code would continue to work...now that I'm thinking about it there has to be a better way...MorganS - will have to try that! I'm not totally clear on exactly how to make it work with libraries that use wire but sounds great! Do you have any examples? Do you code it I2C.begin? Thanks for the suggestion! Will definitely have to try that!