void u8g_i2c_init(uint8_t options) { u8g_i2c_opt = options; u8g_i2c_clear_error(); if ( u8g_i2c_opt & U8G_I2C_OPT_FAST ) { i2c_delay = i2c_400KHz_delay; } else { i2c_delay = i2c_100KHz_delay; } if ( u8g_i2c_opt & U8G_I2C_OPT_DEV_1 ) { i2c_scl_pin = PIN_WIRE1_SCL; i2c_sda_pin = PIN_WIRE1_SDA; //REG_PIOA_PDR = PIO_PB12A_TWD1 | PIO_PB13A_TWCK1; } else { i2c_scl_pin = PIN_WIRE_SCL; i2c_sda_pin = PIN_WIRE_SDA; //REG_PIOA_PDR = PIO_PA17A_TWD0 | PIO_PA18A_TWCK0; } i2c_init(); }
void u8g_i2c_init(uint8_t options) { /* TWBR: bit rate register TWSR: status register (contains preselector bits) prescalar 0 1 1 4 2 16 3 64 f = F_CPU/(16+2*TWBR*prescalar) F_CPU = 16MHz TWBR = 152; TWSR = 0; --> 50KHz TWBR = 72; TWSR = 0; --> 100KHz F_CPU/(2*100000)-8 --> calculate TWBR value for 100KHz */ TWSR = 0; TWBR = F_CPU/(2*100000)-8; u8g_i2c_clear_error(); }
void u8g_i2c_init(uint8_t options) { u8g_i2c_clear_error(); u8g_i2c_opt = options; if (wiringPiSetup() == -1) { printf("wiringPi-Error\n"); exit(1); } fd = wiringPiI2CSetup(I2C_SLA); if (fd < 0) { printf ("Unable to open I2C device 0: %s\n", strerror (errno)) ; exit (1) ; } //u8g_SetPIOutput(u8g, U8G_PI_RESET); //u8g_SetPIOutput(u8g, U8G_PI_A0); }
void u8g_i2c_init(uint8_t options) { /* TWBR: bit rate register TWSR: status register (contains preselector bits) prescalar 0 1 1 4 2 16 3 64 f = F_CPU/(16+2*TWBR*prescalar) F_CPU = 16MHz TWBR = 152; TWSR = 0; --> 50KHz TWBR = 72; TWSR = 0; --> 100KHz TWBR = 12; TWSR = 0; --> 400KHz F_CPU/(2*100000)-8 --> calculate TWBR value for 100KHz */ u8g_i2c_opt = options; TWSR = 0; if ( options & U8G_I2C_OPT_FAST ) { TWBR = F_CPU/(2*400000)-8; } else { TWBR = F_CPU/(2*100000)-8; } u8g_i2c_clear_error(); }
void u8g_i2c_init(uint8_t options) { u8g_i2c_clear_error(); }