Skip to content

julian-fuchs/esp8266-i2c-implementation

 
 

Repository files navigation

Table of Contents

  1. Chip
  2. Electrical connections
    1. UART
    2. I2C
    3. User interface
    4. Role select
  3. Explanation of the I2C protocol
    1. Differences between this implementation and the actual protocol
  4. Example Setup

Chip

The software is written for the ESP8266 microchip, produced by Espressif Systems.

More information about how to control the hardware of a ESP8266: Technical Reference
Specification of the chip: Datasheet

Electrical connections

UART

Atmega2560 D17/TX2 5V (no converter required >3.0V is read as high):
    esp8266_B GPIO04/D2 3.3V
Atmega2560 D16/RX2 5V (with voltage divider to reduce below 3.6V):
    esp8266_B GPIO05/D1 3.3V

I2C

SCL:
    esp8266_A GPIO14/D5 <-> esp8266_B GPIO14/D5
SDA:
    esp8266_A GPIO12/D6 <-> esp8266_B GPIO12/D6

User interface

Potentiometer (0V - 3.3V):
    esp8266_A ADC0/A0
Button "Right" (normally open, connected to GND):
    esp8266_A GPIO05/D1
Button "Left" (normally open, connected to GND):
    esp8266_A GPIO04/D2
Button "Home" (normally open, connected to GND):
    esp8266_A GPIO00/D3
LED "Error" (through resistor):
    esp8266_A GPIO13/D7
LED "Ready" (through resistor):
    esp8266_A GPIO15/D8

Role select

Role (master/slave) is determined by reading D7 during boot. This allows both microcontrollers to be flashed with identical software.

GND (reading: LOW):
    esp8266_B GPIO13/D7
GND, through led and resistor (reading: HIGH due to internal pull-up):
    esp8266_A GPIO13/D7

Explanation of the I2C protocol

I²C sends data in different messages. One message can consist of multiple data frames, each consisting of exactly one byte / 8 bit.
Each data frame is followed by an acknowledgement (ACK) bit.
A 7-Bit long address is sent at the beginning of each message to indicate which device is being communicated to.
A message starts with a start symbol and ends with a stop symbol.

I2C Protocol

  1. Start symbol
  2. Address (7-Bit)
  3. Read-Write-Bit
  4. Acknowledgement bit
  5. Data frame
  6. Acknowledgement bit
    .
    .    [Step 5 and 6 can repeat]
    .
  7. Stop symbol

Differences between this implementation and the actual protocol

Following features are not yet implemented:

  • no repeated start
  • no fast mode
  • no master-to-master connection

Example Setup

The master is located on the right side and the slave on the left.

Setup

About

Project Work for Course "Systems Programming" at DHBW Mannheim

Resources

License

Stars

Watchers

Forks

Languages

  • C 96.9%
  • Makefile 2.3%
  • Python 0.8%