43 lines
2.1 KiB
C
43 lines
2.1 KiB
C
/*
|
|
* I2C.h
|
|
*
|
|
* Created on: 21 sep. 2016
|
|
* Author: len12007
|
|
*/
|
|
|
|
#ifndef DRIVERS_I2C_H_
|
|
#define DRIVERS_I2C_H_
|
|
|
|
#include "stm32f4xx.h"
|
|
|
|
/******************************************************************************
|
|
* BRIEF: Configure the I2C bus to be used *
|
|
* INFORMATION: *
|
|
******************************************************************************/
|
|
void i2c_configure(I2C_TypeDef* i2c, uint16_t sda_pin, uint16_t scl_pin, uint32_t my_address);
|
|
|
|
/******************************************************************************
|
|
* BRIEF: Get data over the I2C bus *
|
|
* INFORMATION: *
|
|
* Since this system uses a 7 bit addressing mode we send the slave address *
|
|
* in the first bytes 7 MSbs and then the LSb is set to 1 indicating that *
|
|
* it is a receive command, after that the slave responds with a 1 bit ack and *
|
|
* the data is sent one byte at a time with an acknowledge in between *
|
|
* every byte, as per the standard. Returns true if successful *
|
|
******************************************************************************/
|
|
bool i2c_receive(uint8_t slave_address, uint8_t* buffer, uint32_t length);
|
|
|
|
/******************************************************************************
|
|
* BRIEF: Send data over the I2C bus *
|
|
* INFORMATION: *
|
|
* Since this system uses a 7 bit addressing mode we send the slave address *
|
|
* in the first bytes 7 MSbs and then the LSb is set to 0 indicating that *
|
|
* it is a send command, after that the slave responds with a 1 bit ack and *
|
|
* the data is sent one byte at a time with an acknowledge in between *
|
|
* every byte, as per the standard. Returns true if successful *
|
|
******************************************************************************/
|
|
bool i2c_send(uint8_t slave_address, uint8_t* data, uint32_t length);
|
|
|
|
|
|
#endif /* DRIVERS_I2C_H_ */
|