I'm new to I2C and am trying to get two ATtiny85 to talk to each other.
- I have Arduino IDE 1.8.0
- I used this link (damellis) to install the ATtiny board in the IDE
- I use an Arduino nano to program the ATtiny85.
- I use this TinyWire library from lucullusTheOnly.
The ATtiny has to be able of being both master and slave. I based my code on this example of lucullusTheOnly.
I have a very simple program (see below) that sends one character on the bus, but I get an error 0x0C USI_TWI_ARBITRATION_LOST
.
I reduced my setup to only the master on the breadboard with 5kOhm pullups on the two I2C wires (2x10kOhm in parallel) to 5V to eliminate all other traffic. But the error remains. Really nothing else on the board.
ATtiny pin usage
3 --> 1kOhm --> LED --> GND (for flashing out error-code)
4 --> GND
5 --> Pullup 5kOhm --> 5v
6 --> Pullup 5kOhm --> 5v
8 --> 5V
I have no scope at hand to monitor traffic on the bus. I can go to a lab next week, but that's long waiting ;-/
In Arduino IDE, I have the Clock speed of the ATtiny set to 1Mhz (was default). Could that be the problem? Should I increase that? Can I simply change that in the Tools>Clock menu? I thought I read somewhere that I had to burn the bootloader too.
Test program:
#include <TinyWire.h>
int error_led_pin = 3; // == physical pin 2 on attiny
byte own_address = 10;
byte slave_address = 11;
void setup() {
// config error_led_pi as Output for driving an LED
pinMode(error_led_pin, OUTPUT);
// config TinyWire library for I2C slave functionality
TinyWire.begin( own_address );
TinyWire.beginTransmission( slave_address );
// fill the send buffer
TinyWire.send('b');
// execute the master sending and check for an error
// returns 0 if there was no error (otherwise you can find the different error code definitions in TinyWire.h)
int errorCode = TinyWire.endTransmission();
if(errorCode!=0) {
// turn on the error LED, if there was an error
handleError(errorCode);
}
}
void loop() {
}
void handleError(int code) {
if (code != 0) {
// *** ERROR ***
// errors defined at https://github.com/lucullusTheOnly/TinyWire/blob/master/TinyWire.h
digitalWrite(error_led_pin, LOW); // TODO: remove!
delay(500);
// blink resultCode number of times // TODO: should be led at pin 2 = push button
for (int i = 0; i <= code; i++) {
digitalWrite(error_led_pin, HIGH);
delay(500);
digitalWrite(error_led_pin, LOW);
delay(500);
}
}
}
Any thoughts on finding why I get USI_TWI_ARBITRATION_LOST ?