Forum: Mikrocontroller und Digitale Elektronik I2C Problem geht nur manchmal


von Stefan G. (steg13)


Lesenswert?

Die Kommunikation über I2C funktioniert nur manchmal.
Ich benutze das Programm von Peter Fleury
In main wird i2c_start_wait aufgerufen
Aus der while Schleife über Ende kommt er nicht mehr raus.
Die beiden Widerstände 4,7k sind drin.
Könnte das ein HW-Problem sein?

in main:
  i2c_init();
  i2c_start_wait(DS1621+I2C_WRITE);   // set device address and write
...

In Twimaster von Peter Fleury:
void i2c_start_wait(unsigned char address)
{
    uint8_t   twst;
    while ( 1 )
    {
  // send START condition
     TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);

      // wait until transmission completed
         while(!(TWCR & (1<<TWINT)));
#########Ende#########

In Doku:
• Bit 7 – TWINT: TWI Interrupt Flag
This bit is set by hardware when the TWI has finished its current job 
and expects application software response. If the I-bit in SREG and TWIE 
in TWCR are set, the MCU will jump to the TWI Interrupt Vector. While 
the TWINT Flag is set, the SCL low period is stretched. The TWINT Flag 
must be cleared by software by writing a logic one to it. Note that this 
flag is not automatically cleared by hardware when executing the 
interrupt routine.
Also note that clearing this flag starts the operation of the TWI, so 
all accesses to the TWI Address Register (TWAR), TWI Status Register 
(TWSR), and TWI Data Register (TWDR) must be complete before clearing 
this flag.

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.