i2c_general.c File Reference

library to communicate using I2C as master or slave (code) More...

Go to the source code of this file.

## Macros

#define | I2C_GENERAL_I2C 2
| I2C peripheral.
#define | I2C_GENERAL_TIMER 3
| timer peripheral
#define | I2C_GENERAL_TIMEOUT 4
| timeout factor (compared to expected time)

## Functions

void | i2c_general_setup_master (bool fast)
| setup I2C peripheral More...
bool | i2c_general_check (void)
| check if SDA and SCL signals are high More...
bool | i2c_general_start (void)
| send start condition More...
bool | i2c_general_select_slave (uint8_t slave, bool write)
| select slave device More...
bool | i2c_general_read (uint8_t *data, size_t data_size)
| read data More...
bool | i2c_general_write (const uint8_t *data, size_t data_size)
| write data More...
void | i2c_general_stop (void)
| sent stop condition

## Detailed Description

library to communicate using I2C as master or slave (code)

Author
  King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info

Date
  2017-2018

Note
  peripherals used: I2C I2C peripheral used to communicate, timer timer peripheral used for timeouts

Definition in file i2c_general.c.

## Function Documentation

## i2c_general_check()

bool i2c_general_check | ( | void |  | ) |

check if SDA and SCL signals are high

Returns
  SDA and SCL signals are high

Definition at line 97 of file i2c_general.c.

## i2c_general_read()

bool i2c_general_read | ( | uint8_t * | data,
|  | size_t | data_size
| ) |  |

read data

Warning
  the slave device must be selected before this operation

Parameters

  [out] | data | array to store bytes read
  [in] | data_size | number of bytes to read

Definition at line 157 of file i2c_general.c.

## i2c_general_select_slave()

bool i2c_general_select_slave | ( | uint8_t | slave,
|  | bool | write
| ) |  |

select slave device

Warning
  a start condition should be sent before this operation

Parameters

  [in] | slave | 7-bit I2C address of slave device to select
  [in] | write | this transaction will be followed by a read (false) or write (true) operation

Returns
  if slave was selected successfully (true) or error occurred (false)

Definition at line 122 of file i2c_general.c.

## i2c_general_setup_master()

void i2c_general_setup_master | ( | bool | fast | ) |

setup I2C peripheral

Parameters

  [in] | fast | use standard (100 kHz) or fast (400 kHz) mode

Definition at line 50 of file i2c_general.c.

## i2c_general_start()

bool i2c_general_start | ( | void |  | ) |

send start condition

Returns
  if start condition was sent successfully (true) or error occurred (false)

Definition at line 102 of file i2c_general.c.

## i2c_general_write()

bool i2c_general_write | ( | const uint8_t * | data,
|  | size_t | data_size
| ) |  |

write data

Warning
  the slave device must be selected before this operation

Parameters

  [in] | data | array of byte to write to slave
  [in] | data_size | number of bytes to write

Definition at line 193 of file i2c_general.c.