Hello,
I am just testing a project I am working on. I have 10 boards, each with an I2C device or two on each board, connected over a backbone with Adum1250ARZ I2C isolation chips on each board.
I have a main processor board, and then the other 7 boards are slave boards (the remaining boards are not smart boards, PSU board etc).
The main processor board is running a AtMega1284P running at 18.432Mhz, and all the other boards (where they have processors) are running Atmega328P's running at 16mhz. I have one with a MCP23017 to control relays, and an analog input board running a Max127 which talks I2C.
The main processor is programmed via a bootloader, the other processors are programmed over ICSP.
The question and problem I have is around the I2C speed and optimising it.
When I edited twi.h and changed the TWI_FREQ from 100000L to 400000L, I had stability issues. So I have it currently set at 100000L. It would run for a few seconds, and then lock up.
I have put in TWBR = 12 in the setup, after the wire.begin() statement, and I2C stopped completely.
By default, TWBR is 84 with the CPU freq of 18.432Mhz and TWI Freq of 100000Hz.
I tried halving it so TWBR was 42, and same result - dead.
I calculated the default for 16Mhz, thinking that the slaves may be the problem, and that came out to be 72. I put TWBR = 72, and it runs fine.
I have external pull ups. I ideally wanted to put 2.2k's on, however I didnt have any that size and forgot to order, so they are 1.5k's.
Each board has the Adum1250ARZ isolation chips on them, and you put pullup resistors on both wires on both sides of the chip.
Is there any further suggestions as to what I should do?
Would the TWI Freq of 400000 be unstable due to pull ups do you think?
Why would TWBR of 12 not run at all?
My code is just test code at the moment. I have some basic code on each slave, responding to requests from the master and sending the required number of bytes of data back. The master has the concept of 'blink without delay' to request data from each of the slave boards, currently every 100ms.
Here is an example of comms to 1 of the boards:
if(millis() > LastOpto)
{
Wire.beginTransmission(1);
Wire.requestFrom(1, 2); // request 2 bytes from slave device #1
i = 0;
if(Wire.available())
{
while(Wire.available()) // slave may send less than requested
{
data[i] = Wire.receive(); // receive a byte as character
i++;
}
OptoAddress = data[0];
OptoInput1 = bitRead(data[1], 0);
OptoInput2 = bitRead(data[1], 1);
OptoInput3 = bitRead(data[1], 2);
OptoInput4 = bitRead(data[1], 3);
OptoInput5 = bitRead(data[1], 4);
OptoInput6 = bitRead(data[1], 5);
OptoInput7 = bitRead(data[1], 6);
OptoInput8 = bitRead(data[1], 7);
}
Wire.endTransmission();
LastOpto = millis() + 100; //0.1 seconds
}
I do not have all 10 boards connected at this stage, I am just testing with 4 - including the master. I havent finished soldering the rest together yet.
The slaves connected are a high speed counter with a 328P, an Opto Isolated Input board, also with a 328P, and a sensor board which talks to a Temp/Humidity Sensor and Barometric sensor - also with a 328P. And the master, as mentioned is a 1284P.
Any help would be appreciated.
Regards
James