GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains low level functions for I2C interaction. More...
Files | |
file | stm32f103cb_i2c.h |
Header file for stm32f103cb I2C. | |
Macros | |
#define | I2C_TIMEOUT 500000 |
The number of loop cycles to wait when polling peripheral registers. | |
#define | I2C_MY_ADDRESS 0x32 |
The address of this device. | |
Enumerations |
Functions | |
mcu_error | I2C_setup (i2c_periph peripheral) |
Initialize I2C data structure and setup port. More... | |
mcu_error | I2C_start (i2c_periph peripheral) |
Generate a start condition on the bus. More... | |
mcu_error | I2C_stop (i2c_periph peripheral) |
Generate a stop condition on the bus. More... | |
mcu_error | I2C_address (i2c_periph peripheral, uint8_t address, uint8_t operation) |
Send a seven bit address on the bus. More... | |
mcu_error | I2C_write (i2c_periph peripheral, uint8_t byte) |
Send one byte on the bus. More... | |
uint8_t | I2C_read (i2c_periph peripheral) |
Read one byte from the bus without acknowledge generation. More... | |
uint8_t | I2C_repeatRead (i2c_periph peripheral) |
Read one byte from the bus with acknowledge generation. More... | |
This module contains low level functions for I2C interaction.
The I2C peripherals are mapped to the following pins for the ports
PULLUP RESISTORS (AROUND 4.7k) ARE NEEDED ON THESE LINES
I2C_setup() sets up a peripheral port with the following:
enum i2c_periph |
I2C ports available on the MCU.
Enumerator | |
---|---|
I2C_1 |
First I2C port. |
I2C_2 |
Second I2C port. |
Definition at line 68 of file stm32f103cb_i2c.h.
mcu_error I2C_address | ( | i2c_periph | peripheral, |
uint8_t | address, | ||
uint8_t | operation | ||
) |
Send a seven bit address on the bus.
peripheral | I2C peripheral to modify. |
address | The slave address of the device |
operation | read or write operation |
Definition at line 503 of file stm32f103cb_i2c.c.
uint8_t I2C_read | ( | i2c_periph | peripheral | ) |
Read one byte from the bus without acknowledge generation.
This operation will stil return mcu_error if an error has occured. The generated error will also be streamed on the debug output stream.
This is typically used at the end of a read chain, or when only a sigle byte is read.
peripheral | I2C peripheral to modify. |
Definition at line 227 of file stm32f103cb_i2c.c.
uint8_t I2C_repeatRead | ( | i2c_periph | peripheral | ) |
Read one byte from the bus with acknowledge generation.
This operation will stil return mcu_error if an error has occured. The generated error will also be streamed on the debug output stream.
This is typically used when another read operation is to follow.
peripheral | I2C peripheral to modify. |
Definition at line 302 of file stm32f103cb_i2c.c.
mcu_error I2C_setup | ( | i2c_periph | peripheral | ) |
Initialize I2C data structure and setup port.
This must be called before any other feature is used.
peripheral | I2C peripheral to associate with the port. |
Definition at line 49 of file stm32f103cb_i2c.c.
mcu_error I2C_start | ( | i2c_periph | peripheral | ) |
Generate a start condition on the bus.
peripheral | I2C peripheral to modify. |
Definition at line 381 of file stm32f103cb_i2c.c.
mcu_error I2C_stop | ( | i2c_periph | peripheral | ) |
Generate a stop condition on the bus.
peripheral | I2C peripheral to modify. |
Definition at line 459 of file stm32f103cb_i2c.c.
mcu_error I2C_write | ( | i2c_periph | peripheral, |
uint8_t | byte | ||
) |
Send one byte on the bus.
peripheral | I2C peripheral to modify. |
byte | The byte to send. |
Definition at line 156 of file stm32f103cb_i2c.c.