Update i2c.h

add timeout and errorcodes
pull/7/head
Sylaina 6 years ago committed by GitHub
parent 977a2ab4d8
commit eee9e5f0c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
i2c.h

@ -10,13 +10,23 @@
#define i2c_h
/* TODO: setup i2c/twi */
#define F_I2C 400000UL// clock i2c
#define F_I2C 100000UL// clock i2c
#define PSC_I2C 1 // prescaler i2c
#define SET_TWBR (F_CPU/F_I2C-16UL)/(PSC_I2C*2UL)
#include <stdio.h>
#include <avr/io.h>
extern uint8_t I2C_ErrorCode; // variable for communication error at twi
// ckeck it in your code
// 0 means no error
// define bits in I2C-ErrorCode:
#define I2C_START 0 // bit 0: timeout start-condition
#define I2C_SENDADRESS 1 // bit 0: timeout device-adress
#define I2C_BYTE 2 // bit 0: timeout byte-transmission
#define I2C_READACK 3 // bit 0: timeout read acknowledge
#define I2C_READNACK 4 // bit 0: timeout read nacknowledge
void i2c_init(void); // init hw-i2c
void i2c_start(uint8_t i2c_addr); // send i2c_start_condition
void i2c_stop(void); // send i2c_stop_condition

Loading…
Cancel
Save