]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
i2c_init update to work with atmega32a boards (#5562)
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>
Sun, 7 Apr 2019 00:30:48 +0000 (17:30 -0700)
committerDrashna Jaelre <drashna@live.com>
Sun, 7 Apr 2019 00:30:48 +0000 (17:30 -0700)
* On i2c_init, enable two wire interface, twi interrupt, and slave
address ACK along with pull up resistors.

* thanks to some testing by drashna, we know that setting TWI doesn't work for all boards. Putting the new code into an ifdef block

drivers/avr/i2c_master.c

index 0db949db4aba25ac3ff6a32cc3b9a477e69c45f9..ba6d0d1586e7660dce138cee95b066768f3c5428 100755 (executable)
 void i2c_init(void) {
   TWSR = 0; /* no prescaler */
   TWBR = (uint8_t)TWBR_val;
+
+  #ifdef __AVR_ATmega32A__
+  // set pull-up resistors on I2C bus pins
+  PORTC |= 0b11;
+
+  // enable TWI (two-wire interface)
+  TWCR |= (1 << TWEN);
+
+  // enable TWI interrupt and slave address ACK
+  TWCR |= (1 << TWIE);
+  TWCR |= (1 << TWEA);
+  #endif
 }
 
 i2c_status_t i2c_start(uint8_t address, uint16_t timeout) {