Forum: Mikrocontroller und Digitale Elektronik [AVR] USI, fehlender /SS Pin, Software Implementation


von Mampf F. (mampf) Benutzerseite


Lesenswert?

Guten Morgen,

im Datenblatt des zB ATTiny84 heißt es:

> The USI Three-wire mode is compliant to the Serial Peripheral Interface
> (SPI) mode 0 and 1, but does not have the slave select (SS) pin
> functionality. However, this feature can be implemented in software
> if necessary. Pin names used by this mode are: DI, DO, and USCK.

Hab dann mal weiter gesucht, aber hat wohl noch niiiiiemals jemand 
gemacht ;-)

Naja, meine Lösung ist folgende:
1
uint8_t wait_for_spi_data() {
2
    USISR=(1<<USIOIF);
3
    while (!(USISR & (1<<USIOIF))) {
4
        if (!(PINA & (1<<PA7)))
5
            USISR &= ~((1<<USICNT3) | (1<<USICNT2) | (1<<USICNT1) | (1<<USICNT0));
6
    };
7
    return USIDR;
8
}

Auf Deutsch: Wenn mein CS (in dem Fall High-Aktiv) nicht gesetzt ist, 
wird der SR-Counter auf 0 gesetzt.

Ist das die übliche Vorgehensweise, wie man es machen sollte?

Viele Grüße,

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.