<<<<<<<=Go Back To Home <<<<<=Previous Week || Next Week>>>>>

Week 14 : Embedded Networking and Communications



Objectives

  • Design and build a wired and/or wireless network connecting at least two processors.
  • Inter - Integrated Circuit Serial Protocol

  • Referred to as IIC or I2C
  • Also called as Two Wire Interface (TWI)

  • Only two wires are used as physical connection lines between the devices
  • SDA which is Serial Data line and SCL which is Serial Clock line

  • There is a Master and one or more Slaves

  • Functions of Master are
    Initiate Communication
    Generate Clock
    Terminate Communication

  • Function of Slave
    Follow Master

  • Master can communicate with different slaves as each Slave have a unique address(manufacturer given 7-10 bit address) which is called Slave Address (SLA)
  • Baud rate in I2C protocal vary from minimu of 100kbps to 4mbps data transfer

  • master-slave

  • I2C is bidirectional, open drain bus
  • Device pulls down , resistos pull up
  • More flexible than SPI communication but slower compared to it.
  • I decided to take my Atmega 328P board from Input Week to be the master.
    And take the new Attiny44 board for my final project ( See Details) as the Slave.

    The boards must be programmed individually and then connected to each other to verify that one of the boards is receiving and the other to be sent.

    Different Steps of the Journey
    Communicating with LED
    ATiny as master, Atmega 328P as Slave and vice versa

    Assignment 1

    I decided to use LEDs on both boards to know they are transferring and recieving the data

    For programming the I2C communication, i used the additional AVR library Wire.h

    The Master code for the Atmega 328p is below

    master1

  • Wire.begin() command intiates the I2C bus and makes the MCU as a master or slave.
  • Wire.beginTransmission(address) command begins a transmission to the I2C slave device with the given address.
    Subsequently, queue bytes for transmission with the write() function and transmit them by calling endTransmission().
  • Wire.write() command Writes data from a slave device in response to a request from a master (here (B00000001) is sending 1 byte),
    or queues bytes for transmission from a master to slave device (in-between calls to beginTransmission() and endTransmission()).
  • Wire.endTransmission() command Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write().
  • LED is on D4 pin of Atmega 328P

    The Slave Code for Attiny 44 board is below

    slave1

    Download Program Files Click Here

    LED1 on PA7 and LED2 on PA6 of Attiny 44 Board

    Connecting the boards

    I made a picture representing all the wires involving my board connections to make things simpler, see below image

    networkingiic

    The SCL and SDA pins of Atmega 328p are A5 and A4 pins whereas the SCL and SDa pins of ATtiny 44 are Pins 4 and 6 (SCK and MOSI pins).
    There should be VCC and GND connections to both boards.
    I have shown the serial monitor connection to the master for my next assignments to give and take readings from the boards( connecting servo and PIR sensor )

    See below video showing my boards communicating

    Assignment 2

    I decided to make ATtiny 44 as the master and Atmega 328p as the slave. It was quite easynow as

    The Master code for the Atmega 328p is below

    master2

    The Slave Code for Attiny 44 board is below

    slave2

    Download File Click Here

    See below video showing my boards communicating


    This one shows Attiny 44 as master and Atmega 328P as Slave

    Creative Commons License

    This work by Aby Michael is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.