I'm writing in to ask you all a question. I've been working on an I2C EEPROM Flasher using my Arduino (for the sake of being able to do it). And what I've stumbled upon is the size of the databuffer being used in the Wire library. ideally, what I would need is to be able to write page by page (64 bytes at a time), where-as the Wire.h library would only support 30 bytes at a time because the buffer is declared as a 32-byte buffer and 2 bytes end up being used as addressing.
What I've tried is the following, in my copy of Wire.h, I've made it look like this:
so that when in my Arduino sketch I #define TWI_B_OVERRIDE as 66, it would take that value and roll with it.. however, at runtime, I'm not seeing this bigger buffer being used and instead only writes the 30 bytes like it did before.
The following is at the top of my arduino sketch btw.
#define TWI_B_OVERRIDE 66
#include <Wire.h>
Any and all help will be appreciated thanks in advance.
Did you change Wire.h in the arduino distribution or did you make your own copy and put it somewhere else?
What version of arduino are you using?
Hold a 'Shift' key down and click the 'Verify' button in Arduino. It tells you what "include" directories are being used and where the output files are stored. Does the "-I" stuff show the directory in which your Wire.h is located?
top of my arduino sketch
Look at the output file named "yoursketchname.cpp" in the indicated directory.
The first lines should be something like
#define TWI_B_OVERRIDE 64
#include <Wire.h>
//
// Maybe some other stuff included in your sketch
//
#include "WProgram.h"
void setup();
void loop();
.
.
.
Bottom line: I made your indicated changes in arduino-0021/hardware/arduino/cores/arduino/Wire.h and ran the following sketch:
thanks for your reply, I changed the original Wire.h in my Arduino library.
My changes were exactly like you said, and I verified the method on a regular C compiler as well. By the way, I'm using the latest release (0021)
I'm getting the exact same output as well, but it still does not use the newer buffersize. What apparently happens is that Wire.h relies on a twi.h and twi.c that are in its corresponding utility folder. I've tried overriding the buffer there as well. But now, it still doesn't write 64 bytes but rather 30 bytes as before my changes.
Use your modified Wire.h ant put your #define TWI_BUFFER_OVERRIDE 66 at the beginning of your sketch.
Use the original Wire/twi.h and put the following after the TWI_BUFFER_OVERRIDE define statement:
Okay, so what I've done is just like you, I've created a sketch that prints out the variables I'm working with. Namely TWI_B_OVERRIDE, BUFFER_LENGTH and TWI_BUFFER_LENGTH.
my Wire.h was modified to define TWI_BUFFER_LENGTH as TWI_B_OVERRIDE in the case I was overriding stuff...
However, when I plug this into my EEPROM writer sketch and read out the EEPROM afterwards, I still have the old contents and it still puts out the a page that's been written only half (30 out of 64 bytes)...
the idea is that it writes to the EEPROM in pages of 64 bytes to reduce the time needed to burn data to the EEPROM. The EEPROM I'm working with here is a 24xx256 from Microchip (they seem to be quite nice).
What you're seeing in the output is the data as it should be and the data as it comes out (even though my tweaks are in effect). Mind you, the output was after-edited for readability.
Well, I tried to guess without actually building a sketch that used the TW_BUFFER_LENGTH from twi.h and twi.cpp.
Sorry. It does not compute.
Here's the thing:
The file <Wire/utility/twi.h> is included when twi.cpp is compiled. Since twi.cpp is compiled separately, it doesn't know what you defined in your main program (the sketch) or what is defined in Wire.h as a result of the definitions in your sketch's defined macros.
For starters, forget about all of the ifdef stuff and just define the buffer sizes to be 66 in your copies of Wire.h and twi.h
If we were compiling "from scratch" I might come up with a better way, but for now, I'm tired of fighting the Arduino helpful stuff. I don't think the library itself was tested in Arduino with compile-time options like you are trying.
Bottom line: Since you have to change the library to accommodate your requirements, I would suggest that you make simple changes instead of trying to work the #ifdef stuff through the different layers.