XMegaForArduino / libraries

libraries directory tree, intended to be placed in sketchbook/libraries (or similar), for xmega-specific versions of Arduino libraries
6 stars 4 forks source link

Wire.write slow, millis wrong #5

Open zdjurisic opened 7 years ago

zdjurisic commented 7 years ago

Writing to a 7-segment display on I2c run 100 writes full speed in just under 8 seconds (timed by stopwatch in my hand). Timed by millis, returned 78 milliseconds. The same display, same code, just Wire instead of XWire, in the first line, on Mega2560 run in 33 milliseconds, and was, as expected, too quick to be timed by stopwatch.

Here's Arduino code:

`#include

void setup() { Serial.begin(57600); Wire.begin();

I2CWrite(0x00, 0x0C, 0x01); // AS1115 is in shutdown on power-up. Wake up & reset feature register. I2CWrite(0x00, 0x0B, 0x06); // Set scan limit to display 6 digits (no digit 7 on this display unit). I2CWrite(0x00, 0x09, B11111111); // Set all digits to "HEX decode"

unsigned long timeStart = millis(); for (byte j=0; j<10; j++) { for (byte i=0; i<10; i++) { Wire.beginTransmission(0x00); Wire.write(7); Wire.write(i); // This is teh address of the display digit we are writing to Wire.endTransmission(); } } unsigned long timeEnd = millis(); Serial.println(timeEnd-timeStart); }

void loop() {}`

bombasticbob commented 7 years ago

thanks, I'll have a look and see why it might be messing up the millis counter. it might be missing an interrupt [which means re-prioritizing them, probably].