Forum: Mikrocontroller und Digitale Elektronik Problem mit Schieberegister


von Donni D. (Gast)


Lesenswert?

Hey Leute,
Ich hab ein kleines Problem mit meinem Schieberegister (74HC595).
Als Controller benutze ich ein Atmega 328p (Vom Arduino Uno).
So, nun möchte ich Daten per SPI an das Schieberegister geben was auch 
einmal gut funktioniert. Sobald ich das zweite Byte reinschieben will 
passiert nichts mehr, die LED bleibt einfach an :/
Hab die Verkabelung schon paar mal überprüft, sollte eigentlich alles 
stimmen.. Wo könnte ich einen Fehler gemacht haben?
Hier noch der Code:
1
#include <avr/io.h>
2
3
#define F_CPU 16000000UL
4
5
// SPI
6
#define DDR_SPI DDRB
7
#define DD_MOSI DDB3
8
#define DD_SCK DDB5
9
#define DD_SS DDB2
10
11
#include <util/delay.h>
12
13
void SPI_MasterInit(void);
14
void SPI_MasterTransmit(char cData);
15
16
int main(void)
17
{
18
  SPI_MasterInit();
19
  
20
    while(1)
21
    {
22
    // Alle an
23
    SPI_MasterTransmit((char) 0b00000000);
24
    _delay_ms(1000);
25
    
26
    // Alle aus
27
    SPI_MasterTransmit((char) 0b11111111);
28
    _delay_ms(1000);
29
    }
30
}
31
32
void SPI_MasterInit( void )
33
{
34
  /* Set MOSI, SS and SCK output, all others input */
35
  DDR_SPI = (1<<DD_MOSI)|(1<<DD_SS)|(1<<DD_SCK);
36
  /* Enable SPI, Master, set clock rate fck/2 */
37
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPI2X);
38
}
39
40
void SPI_MasterTransmit( char cData )
41
{
42
  PORTB |= (0<<DD_SS);
43
  /* Start transmission */
44
  SPDR = cData;
45
  /* Wait for transmission complete */
46
  while(!(SPSR & (1<<SPIF)));
47
  PORTB |= (1<<DD_SS);
48
}

von hp-freund (Gast)


Lesenswert?

Donni Donis schrieb:
> PORTB |= (0<<DD_SS);

???

von Timmo H. (masterfx)


Lesenswert?

PORTB &= ~(1<<DD_SS);
anstatt
> PORTB |= (0<<DD_SS);

von Donni D. (Gast)


Lesenswert?

Argh, danke Leute :/
Hatte die Zeile nur kopiert und dann einfach ne null eingesetzt.
Hatte nicht nachgedacht :D Jetzt geht es aufjedenfall :)

Vielen Dank!

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.