I2C Network program AVR 1-seriese

I2C

Inter-Integrated Circuit by Philips.

TWI

Two-Wire Serial Interface by Microchip is compatible with Philips I2C protocol.

Board

hello.t412.echo board

ATtiny3216 board

Pin out


Connection

ATtiny412

  • SDA:PA1(as used FTDI RX)
  • SCL:PA2(as used FTDI TX)

ATtiny3216

  • SDA:PB1
  • SCL:PB0

or

  • SDA:PA1
  • SCL:PA2

Alternate location can be selected in Arduino IDE.

Power Supply

Each Board needs 5V power supply to VCC pin and GND to GND pin.

Pull-UP Resistor

I2C required pull-up resistor whichever external or internal.
If pull-up by external resistor, connention and resistor value is…

  • SDL to VCC by 4.7kΩ
  • SCL to VCC by 4.7kΩ

twi.c which is related will set internal pull-up “enable” if master node, so that external pull-up resistor may not necessary.
ref.Arduino同士でI2C通信する方法

If you want to controll internal pull-up, add them and take out “//” as you like.

//pinMode(SCL,INPUT_PULLUP);//内部プルアップ有効:公式ライブラリなら有効になるので、しなくていい
//pinMode(SDA,INPUT_PULLUP);//enable internal pullup:<Wier.h> already sets it enable

//pinMode(SCL,INPUT);内部プルアップ無効:外部プルアップ抵抗を使用した時
//pinMode(SDA,INPUT);disable internal pullup:need this when external pullup resistor is used

Code and Result