roverSTM  UM2 2013
Projet M1 Navarro Benjamin
 All Classes Files Functions Groups Pages
I2CDevice.h
1 /*
2  * I2CDevice.h
3  *
4  * Created on: 9 fŽvr. 2013
5  * Author: Benjamin Navarro
6  */
7 
8 #ifndef I2CDEVICE_H_
9 #define I2CDEVICE_H_
10 
11 #include <stm32f4xx.h>
12 
13 class I2CDevice {
14 public:
15  I2CDevice(I2C_TypeDef* I2C_Port, uint8_t address, uint32_t speed = 100000);
16  virtual ~I2CDevice();
17 
18 protected :
19  void WriteRegister(uint8_t reg, uint8_t value);
20  void WriteBuffer(uint8_t reg, uint8_t* buffer, uint8_t length);
21  uint8_t ReadRegister(uint8_t reg);
22  void ReadBuffer(uint8_t reg, uint8_t* buffer, uint8_t length);
23 
24 private:
25  void start(uint8_t direction);
26  void write(uint8_t data);
27  uint8_t readAck();
28  uint8_t readNack();
29  void stop();
30 
31 
32  I2C_TypeDef* I2C;
33  uint8_t slaveAddress;
34 };
35 
36 #endif /* I2CDEVICE_H_ */