Skip to content
Snippets Groups Projects
Commit ed0c9e21 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

blinkenrocket i2c: Add optional no-interrupt I2C

parent f4b31b88
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
inline void await_twint(unsigned char twcr_values) inline void await_twint(unsigned char twcr_values)
{ {
#if 1
TWCR = twcr_values | _BV(TWINT) | _BV(TWIE); TWCR = twcr_values | _BV(TWINT) | _BV(TWIE);
while (!(TWCR & _BV(TWINT))) { while (!(TWCR & _BV(TWINT))) {
arch.idle(); arch.idle();
} }
#endif
#if 0
TWCR = twcr_values | _BV(TWINT);
while (!(TWCR & _BV(TWINT))) ;
#endif
} }
/* /*
...@@ -21,8 +27,8 @@ static signed char i2c_start_read(unsigned char addr) ...@@ -21,8 +27,8 @@ static signed char i2c_start_read(unsigned char addr)
if (!(TWSR & 0x18)) // 0x08 == START ok, 0x10 == RESTART ok if (!(TWSR & 0x18)) // 0x08 == START ok, 0x10 == RESTART ok
return -1; return -1;
// Note: The R byte ("... | 1") causes the TWI momodule to switch to // Note: An adress with read bit set ("... | 1") causes the TWI momodule
// Master Receive mode // to switch to Master Receive mode
TWDR = (addr << 1) | 1; TWDR = (addr << 1) | 1;
await_twint(_BV(TWEN)); await_twint(_BV(TWEN));
if (TWSR != 0x40) // 0x40 == SLA+R transmitted, ACK receveid if (TWSR != 0x40) // 0x40 == SLA+R transmitted, ACK receveid
...@@ -55,6 +61,7 @@ static signed char i2c_start_write(unsigned char addr) ...@@ -55,6 +61,7 @@ static signed char i2c_start_write(unsigned char addr)
static signed char i2c_stop() static signed char i2c_stop()
{ {
TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN); TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN);
return 0;
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment