Forum: Mikrocontroller und Digitale Elektronik SPI will gar nicht beim AT Mega 16


von Patrick K (Gast)


Lesenswert?

Hallo,

ich bin jetzt mal total ratlos.
Ich hab eigentlich nur ein total simplen test machen wollen aber da geht 
nix. Folgender Code:
1
#define DD_MOSI    PINB5
2
#define DD_MISO    PINB6
3
#define DD_SCK    PINB7
4
5
//overwrite PortB with SPI
6
#define DDR_SPI    DDRB
7
8
9
10
void SPI_MasterInit(void) {
11
  // Set MOSI and SCKK output, all others input
12
  DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);  
13
  
14
  //Set SS as output (SS= PB4)
15
  DDRB|=(1<<PB4);  
16
17
  //Enable SPI, Master, set clock rated fclk/16
18
  SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0) |(1<<SPR1) ;
19
}
20
21
void SPI_MasterTransmit (char cData){
22
    
23
  //Start Transmission
24
  SPDR = cData;
25
26
  //wait for transmission complete
27
  while (!(SPSR & (1<<SPIF)));
28
}
29
30
int main(){ 
31
32
  SPI_MasterInit();
33
  SPI_MasterTransmit (0xAA);
34
}

jetzt muesste ich ja zumindest ein signal am SCK sehen nachdem ich reset 
gedrueckt hab. aber es passiert nichts. muss ich irgendwelche fuses 
setzen oder hab ich irgendwas vergessen??


gruss
Patrick

von Patrick K (Gast)


Lesenswert?

1
#define DD_SS    PINB4
2
void SPI_MasterInit(void) {
3
  // Set MOSI SCKK and SS as output, all others input
4
  DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);  
5
  
6
  //Set SS as output (SS= PB4)
7
  //DDRB|=(1<<PB4);  
8
9
  //Enable SPI, Master, set clock rated fclk/16
10
  SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0);
11
}

ROFL

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.