1 | void init_SPI (void) |
2 | {
|
3 | DDRB |= 0b00101111; //PB0(CS_DAC1), PB1(DAC2), PB2(CS_AD), PB3 (MOSI), PB5 (SCK) als Ausgang |
4 | clear_bit(DDRB, 4); //PB4 (MISO) als Eingang |
5 | |
6 | PORTB = 0; // Alle Pullups aus |
7 | PINB =0; |
8 | //CS_AD auf high ziehen, funzt auch
|
9 | set_bit(PORTB, CS_AD); |
10 | |
11 | |
12 | // SPI aktivieren, auf Master schalten;
|
13 | set_bit (SPCR, MSTR); |
14 | set_bit (SPCR, SPE); |
15 | |
16 | //SPI- clock select ist auf 0 -> Clock bei FCPU/4
|
17 | |
18 | // Interrupt einschalten
|
19 | set_bit(SPCR, SPIE); //<------ab hier kann ich nichts mehr an PB2 ändern, der Pin bleibt High |
20 | |
21 | } // Ende void init_SPI (void) |
22 | |
23 | ISR (TIMER1_COMPA_vect) //ISR OCR-Compare match |
24 | {
|
25 | clear_bit (PORTB, CS_AD); // CSAD aktiv<---------- geht nicht, Pin bleibt high |
26 | // 0x00 -> Channel 1 select
|
27 | SPDR = 0x00; //SPI anstoßen |
28 | set_bit(status, HIBYTE); |
29 | |
30 | //--> Highbyte speichern und Lowbyte holen macht ISR-SPI
|
31 | }
|
" When the SPI is configured as a Master (MSTR in SPCR is set), the user can determine the direction of the SS pin. If SS is configured as an output, the pin is a general output pin which does not affect the SPI system. Typically, the pin will be driving the SS pin of the SPI Slave. "