Hello, I am trying to transfer 192 bytes at a time over i2c but for some reason after 98 bytes the rest are just totally misconstrued to the second arduino. Did I make an error or is there some kind of workaround? Here are the essentials of my code:
Master:
#include <Wire.h>
byte rgb[192]; //pretend these are declared
void setup(){
Wire.begin();
}
void loop(){
Wire.beginTransmission(0x40);
Wire.write(rgb,192);
Wire.endTransmission();
}
Sorry for the cross post, I was going to delete my old topic since this one was more concise and I was able to isolate the problem, but then I realized I couldn't delete it.
If the limits 32 why am i getting like triple that? Is there any workaround?
I originally changed it to 98 a few weeks back while following a tutorial. I changed the size in Wire.h and twi.h, changing to 98 had no problems it seems, but when I try to do 192 the program doesn't work at all so I'm assuming 192 is more than the Arduino can handle...There's gotta be something that can be done...
EDIT so apparently SPI may be better for this application...however I am using those pins on my Arduino to read from an SD card..is there a workaround for this?
Sovereignty:
I originally changed it to 98 a few weeks back while following a tutorial. I changed the size in Wire.h and twi.h, changing to 98 had no problems it seems, but when I try to do 192 the program doesn't work at all so I'm assuming 192 is more than the Arduino can handle...There's gotta be something that can be done...
EDIT so apparently SPI may be better for this application...however I am using those pins on my Arduino to read from an SD card..is there a workaround for this?
You could be running out of RAM. The Wire library allocates five arrays the size of the buffer length. 192 * 5 = 960 bytes, so that's nearly half the 2K bytes SRAM for an Uno. The core uses maybe a couple hundred, plus whatever your code uses, any idea how much that might be?
Like I2C, SPI is a bus, multiple devices can be connected, they just cannot be accessed simultaneously. So yes, an SD card and something else can be connected to the SPI pins. A slave select pin will be needed for each device.
I think the RAM is the issue, so if I can't get SPI working I guess I'll just use a MEGA for this project. I'd prefer to use SPI because I understand it is about 30x faster, but I am having some issues. The SPI library doesn't seem to have slave mode support and I can't really find anything I could use. The slave device is a Rainbowduino which has the atmega328 but is meant for driving LEDS, so I have to use the ISP header on there. I can figure out the code from the master, but I don't understand how I can tell the slave to receive the bytes and then use them.
Grumpy_Mike:
You can get a 254 byte limit if you switch to the master I2C libary.
I wasn't aware of that library, looks interesting, I think this is it:
The SPI library does only operate as the master. SPI is fairly simple, not sure how hard it might be to write slave code. I might Google around a bit, chances are that someone has already.