50 lines
817 B
C
50 lines
817 B
C
/*
|
|
* i2c.h
|
|
*
|
|
* Created on: 18.01.2016
|
|
* Author: BlexTw11
|
|
*/
|
|
|
|
#ifndef INCLUDE_I2C_H_
|
|
#define INCLUDE_I2C_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#define STAT_START 0x08
|
|
#define STAT_START_REP 0x10
|
|
#define STAT_SLAVE_W_ACK 0x18
|
|
#define STAT_SLAVE_W_NACK 0x20
|
|
#define STAT_DATA_W_ACK 0x28
|
|
#define STAT_DATA_W_NACK 0x30
|
|
#define STAT_ARBITE_LOST 0x38
|
|
|
|
#define STAT_SLAVE_R_ACK 0x40
|
|
#define STAT_SLAVE_R_NACK 0x48
|
|
#define STAT_DATA_R_ACK 0x50
|
|
#define STAT_DATA_R_NACK 0x58
|
|
|
|
#define MODE_WRITE 0
|
|
#define MODE_READ 1
|
|
|
|
#define GET_STATUS (TWSR & 0xF8)
|
|
|
|
|
|
void I2C_init(void);
|
|
|
|
void I2C_start(void);
|
|
|
|
void I2C_stop(void);
|
|
|
|
void I2C_write(uint8_t data);
|
|
|
|
uint8_t I2C_read_ACK(void);
|
|
|
|
uint8_t I2C_read_NACK(void);
|
|
|
|
uint8_t I2C_status(void);
|
|
|
|
|
|
#endif /* INCLUDE_I2C_H_ */
|
|
|
|
|