Hallo,
dies ist doch schon eine Repeated Start Funktion oder?
1 | uint8_t i2c_start(uint8_t address)
|
2 | {
|
3 | // reset TWI control register
|
4 | TWCR = 0;
|
5 | // transmit START condition
|
6 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|
7 | // wait for end of transmission
|
8 | while( !(TWCR & (1<<TWINT)) );
|
9 |
|
10 | // check if the start condition was successfully transmitted
|
11 | if((TWSR & 0xF8) != TW_START){ return 1; }
|
12 |
|
13 | // load slave address into data register
|
14 | TWDR = address;
|
15 | // start transmission of address
|
16 | TWCR = (1<<TWINT) | (1<<TWEN);
|
17 | // wait for end of transmission
|
18 | while( !(TWCR & (1<<TWINT)) );
|
19 |
|
20 | // check if the device has acknowledged the READ / WRITE mode
|
21 | uint8_t twst = TW_STATUS & 0xF8;
|
22 | if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return 1;
|
23 |
|
24 | return 0;
|
25 | }
|
Ist doch hier richtig eingestellt, stehe gerade auf dem Schlauch?
1 | // transmit START condition
|
2 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|