I2C: no need to initialise with an address in master mode.

This commit is contained in:
Markus Hitter 2016-04-03 22:23:20 +02:00
parent 194e5d5b98
commit 61ab29e6b6
2 changed files with 9 additions and 3 deletions

10
i2c.c
View File

@ -89,9 +89,14 @@ uint8_t i2c_byte_count;
#endif /* I2C_SLAVE_MODE */
void i2c_init(uint8_t address) {
/**
Inititalise the I2C/TWI subsystem.
i2c_address = address;
\param address Address the system should listen to in slave mode, unused
when configured for master mode. In master mode, receiver
address is given to the send command.
*/
void i2c_init(uint8_t address) {
#ifdef I2C_MASTER_MODE
#ifdef I2C_ENABLE_PULLUPS
@ -117,6 +122,7 @@ void i2c_init(uint8_t address) {
#endif /* I2C_MASTER_MODE */
#ifdef I2C_SLAVE_MODE
i2c_address = address;
TWAR = i2c_address; // We listen to broadcasts if lowest bit is set.
TWCR = (0<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(1<<TWEN)|(1<<TWIE);
#endif

View File

@ -96,7 +96,7 @@ void init(void) {
#endif
#ifdef I2C
i2c_init(DISPLAY_I2C_ADDRESS);
i2c_init(0);
#endif
// set up timers