Forum: Mikrocontroller und Digitale Elektronik I2C/TWI - Bus bei ATMega32


von Balou B. (baloubaer)


Lesenswert?

Hallo zusammen,

ich habe eine Fragen bezüglich der Funktionsweise des I2C- Busses bei 
einem ATMega32 der als Slave Daten empfangen soll.

ich habe auch schon Versuche hinter mir, bei dem ich vom Master ein 
Bitmuster senden lasse und dieses auf dem Slave ausgeben lasse. Dieses 
Funktioniert!

Also, meine Fragen:

1.Ich möchte, dass der ATMega32 im Standby-Modus über den TWI - Bus 
aufgeweckt wird, jedoch weiß ich nicht wie. Könnt ihr mir da 
weiterhelfen,denn dazu finde leider nicht wirkich viele Infos im Netz 
oder Datenblatt.

2. Gibt es eine Möglichkeit, dass wenn eine Startbedingung vom Master 
gesendet wird, dass im Slave ein Interrupt ausgelöst wird, so dass er 
Daten empfangen kann? Oder läuft der Datenempfang gundsätlich im 
Hintergrund automatisch und der TWI löst selber einen Interrupt aus, 
wenn Daten empfangen wurden. Also wie z.B. bei dem AD-Wandler. Der kann 
ja nach beendigung einer Messung auch einen Interruptauslösen, in dieser 
Zeit kann ja der uC weiter Arbeiten, wenn ich nicht mit der while 
Schleife auf das Ende der Messung warten kann.

Ich bedanke mich für euere Hilfe und verbleibe

Mit freundlichen Grüßen

Balou Baer

von DerDaniel (Gast)


Lesenswert?

Datenblatt Seite 34, 176
Ich bin mal so frei und behaupte du warst zu faul die beiden Kapitel 
Power Management und Two-wire Serial Interface zu lesen. ;-)

von Balou B. (baloubaer)


Lesenswert?

DerDaniel schrieb:
> Datenblatt Seite 34, 176
> Ich bin mal so frei und behaupte du warst zu faul die beiden Kapitel
> Power Management und Two-wire Serial Interface zu lesen. ;-)

Nein, eher nicht.

Verstehe es aber nicht.

Also läuft die Bus Interface Unit im Hintergrund und somit auch die 
Address Match Unit?

Wenn ja, würde ein Interrupt ausgelöst, wenn er seine Adresse erkennt 
oder Datenempfängt?

• After the TWI has been addressed by own slave address or general call
• After the TWI has received a data byte

Wie würde das Funktionieren?
- Ich würde die Adresse im TWAR mit den TWA Bit´s 0-6 definieren und das 
TWGCE Bit würde ich nicht setzen, weil kein General Call  Richtig?
- dann würde ich das TWCR konfigurieren:  TWEN TWEA

Soweit so gut....
nun würde, wenn er Daten empfangen hat (seine Adresse) das TWINT setzen? 
Richtig?

Wie wird denn nun ein Interrupt ausgelöst, oder geht das nicht im 
Slave-Receiver Modus? Damit ich Datenempfangen kann?

Denn ich müsste die Daten aus dem TWDR doch an eine uint8_t Variable "X" 
übergeben oder?

Habe ich das soweit richtig verstanden?

Mit freundlichen Grüßen
Balou Baer

von DerDaniel (Gast)


Lesenswert?

Sorry wenn ich jetzt bisal patzig bin, ABER WILLST DU MICH VERARSCHEN?!

Seite 176, Absatz Address Match Unit
The Address Match unit checks if received address bytes match the 7-bit 
address in the TWI Address Register (TWAR). If the TWI General Call 
Recognition Enable (TWGCE) bit in the TWAR is written to one, all 
incoming address bits will also be compared against the General Call
address. Upon an address match, the Control Unit is informed, allowing 
correct action to be taken. The TWI may or may not acknowledge its 
address, depending on settings in the TWCR.
The Address Match unit is able to compare addresses even when the AVR 
MCU is in sleep mode, enabling the MCU to wake up if addressed by a 
master.

und Control Unit
The Control unit monitors the TWI bus and generates responses 
corresponding to settings in the
TWI Control Register (TWCR). When an event requiring the attention of 
the application occurs
on the TWI bus, the TWI Interrupt Flag (TWINT) is asserted. In the next 
clock cycle, the TWI Status
Register (TWSR) is updated with a status code identifying the event. The 
TWSR only
contains relevant status information when the TWI Interrupt Flag is 
asserted. At all other times,
the TWSR contains a special status code indicating that no relevant 
status information is available.
As long as the TWINT Flag is set, the SCL line is held low. This allows 
the application
software to complete its tasks before allowing the TWI transmission to 
continue.
The TWINT Flag is set in the following situations:
• After the TWI has transmitted a START/REPEATED START condition
• After the TWI has transmitted SLA+R/W
• After the TWI has transmitted an address byte
• After the TWI has lost arbitration
• After the TWI has been addressed by own slave address or general call
• After the TWI has received a data byte
• After a STOP or REPEATED START has been received while still addressed 
as a slave
• When a bus error has occurred due to an illegal START or STOP 
condition


So, jetzt Augen auf, Hirn an, lesen und verstehen was da steht.

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.