Forum: Mikrocontroller und Digitale Elektronik I2C_REP_START


von Jan H. (janiiix3)


Lesenswert?

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);

von spess53 (Gast)


Lesenswert?

Hi

>dies ist doch schon eine Repeated Start Funktion oder?

Nein. Das ist ein 'normaler' Start.

Ein REPEATED START ist eine Startbedingung nach einem Start ohne 
vorheriges STOP.

MfG Spess

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.