Skip to content

i2c_init

gicking edited this page Feb 6, 2018 · 4 revisions

back to Command Reference / I2C

Description

Initialize the I2C module of the controller. Currently, only a fixed setting is used, namely:

  • I2C standard mode with 7b addresses
  • fixed speed of 100kBaud
  • no clock stretching
  • broadcast receive disabled

Inclusion

  • defined in i2c.h
  • not loaded by main_general.h
  • for custom I2C interrupts set set #define USE_I2C_ISR in config.h. The corresponding interrupt function name is I2C_ISR

Syntax

i2c_init()

Parameters

  • input:

    • none
  • output:

    • none

Returns

  • Nothing

Example Code

The below function controls a digital potentiometer AD5280. Specifically it sets the resistance between terminal A and washer to R=Rmax/255*res

#include "i2c.h"

...
void setAD5280(uint8_t addr, uint8_t res) {
  uint8_t  buf[2] = {0x00, res};
  i2c_start();
  i2c_send(addr,2,buf);
  i2c_stop();
}

setup() {
  ...
  i2c_init();
  ...
}

Relevant Tutorial

Notes and Warnings

To avoid damage

  • do not expose I/Os to voltages outside [-0.3V; Vdd+0.3V], else limit injection currents to the specificied limits
  • for OUTPUT pins assert that sink and source currents are below the specificied limits
  • do not directly connect two OUTPUT pins. If e.g. half-duplex is required, use a pull-up and OUTPUT_OPENDRAIN, instead

See also

Clone this wiki locally