Lesson 03 - I2C II

The lecture

This is the second of two lectures about I2C and components on the I2C bus

I2C (or wire) is a very common local network or fieldbus within robotics and controlsystems.

Today is dedicated to

  1. finalize exercises from last time

    1. remember: timing and performance

  2. Interfacing to real I2C slaves

    1. ISC based realtime clock ds1307

  3. Interfacing I2C interfaced temperatur sensor TC74

    1. tc74 data sheet

  4. Interfacing I2C interfaced audio volume potentiometer DS1807

    1. DS1807 datasheet

The lecture will be short because exercise will be of high priority today

Preparation for the lecture

  1. Finalize exercises from first I2C lecture

  2. Read litterature from last tiome with focus on slave functionallity

  3. Use datasheets for the exercises

Exercise 2 - DS1807 - digital potentiometer

  • DS1807 datasheet

  • Which commands are avilable

    • including parameters

  • Do blackboard design

  • Do real design

Exercise 2 - TC87 - temperature measurement

  • Design Master code for handling

    • TC87

    • Which commands are available

    • You r(subset) of implementation

    • Code it

Exercise 3 - DS 1307 realtime clock - EXTRA

As exercises above

Exercise 4 - you slave framework

Based on exercises from previous lecture design a framework for a generic slave

  • ID

  • ID of operations read and or write

    • how to you carry out a read from a specific register in the slave device

    • same just for write

  • Code is on your Arduino

It is an idea to have one command (read I assume) that can return status and ID from slave device
independent

Litterature and slides

Slides

Litt and data sheets

  1. ISC based realtime clock ds1307

  2. tc74 datasheet

  3. DS1807 datasheet

Repetition

Litterature from previous lecture

Movies

After today - you should (at least) be able to …

  1. Understand I2C protocol

  2. Be able to design a master slave protocol on top of I2C

  3. Code it and get it running

  4. Understand timing and performance on the I2C bus

Tips

3.3V versus 5V

Some devices like Arduino UNO, Mega,… is powered by 5V.

See more here (a practical viewpoint)
Other devices like esp32, m5stack etc is running on 3.3V

This might give problems when having a mix of 3.3V and 5V devices on the bus

You might damage 3.3V devices by having a 5V device on the canbus.

meaning you might be lucky or … not.

citing from element14.com

2C devices have open-drain drivers, which only pull the SCL and SDA lines low to 0V.
Each I2C line should have a single pull-up resistor: make sure they pull up to 3.3V and not 5V.
Also make sure that each 5V part has a reasonable Vih (Input voltage high) threshold.
Many 5V chips use TTL Vih which is 2.0V, which works.
Others may have Vih = 0.7 x 5.0 = 3.5V, which means you'll have to do something else.

A hack

  • disable internal pullup resistors in the 5V based device and use eternal pullup resistors connected to a 3.3V source. You might be lucky because


citing hackaday (link above)

3.3V TTL logic shares the 0.8V and 2V thresholds for logic 0 and logic 1 transitions with 5V TTL logic,
so a 3.3V TTL output can drive a 5V TTL input without any extra hardware required.

But I dont give any guarantee

Ground

When wiring up always start with ground so all devices has same reference

I2C recover

If your I2C locks up this code might help you lect03-i2c-recover

Some Example Code

lecti2c02-rawcode