Hallo Leute, ich stehe irgendwie auf dem Schlauch, die SPI-Schnittstelle an einem ATMEGA644p zum laufen zu bekommen. Eigentlich sollte das ja nicht so schwer sein - dachte ich. Diesen Programcode habe ich im Web gefunden und die Pins an den 644p angepasst. Im realen Leben läuft das aber leider nicht, im Simulator bleibt es in der while-Schleife der Transmit-Funktion hängen. Was habe ich übersehen? Vielen Dank für eure Hilfe, Gruß, DetlevT
1 | #include <avr\io.h> |
2 | |
3 | #define DD_MOSI PINB5
|
4 | #define DD_SCK PINB7
|
5 | #define DDR_SPI DDRB
|
6 | |
7 | void SPI_MasterInit(void) |
8 | {
|
9 | // Set MOSI and SCK output, all others input
|
10 | DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK); |
11 | // Enable SPI, Master, set clock rate fck/16
|
12 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); |
13 | }
|
14 | |
15 | void SPI_MasterTransmit(char cData) |
16 | {
|
17 | /* Start transmission */
|
18 | SPDR = cData; |
19 | /* Wait for transmission complete */
|
20 | while(!(SPSR & (1<<SPIF))); |
21 | }
|
22 | |
23 | int main(void) { |
24 | SPI_MasterInit(); |
25 | SPI_MasterTransmit('A'); |
26 | while(1) ; |
27 | }
|