Gast
#1156753
Hallo Leute, ich wollte jetzt mal die SPI-SChnittstelle in Gang bringen
und habe ein kleines Testprogramm aus meinem Projekt extrahiert. Es soll
einfach permanent ein Byte (0x95) per SPI senden. Der Code compiliert
aber zu 0 Byte - warum?
//Bibliotheken
#include <avr/io.h>
#include <stdint.h> // damit man uint8_t verwenden kann
//für SPI:
#define DDR_SPI DDRB
#define PORT_SPI PORTB
#define MOSI 2
#define MISO 3
#define SCK 1
#define SS 4 // eigentlich 0, aber ich will es selbst steuern
//Variable
static uint8_t dummy;
//Funktionen
int main(void);
static uint8_t SPI_Transfer(uint8_t sByte);
static void SPI_MasterInit(void);
//Hauptprogramm
int main(void)
{
SPI_MasterInit();
while(1)
{
dummy=SPI_Transfer(0x95);
}
}
void SPI_MasterInit(void)
{
// Set MOSI, SCK and SS output, MISO Input
DDR_SPI |= (1<<MOSI)|(1<<SCK)|(1<<SS);
DDR_SPI &= ~(1<<MISO);
//from datasheet
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}
uint8_t SPI_Transfer(uint8_t sByte)
{
SPDR = sByte;
while(!(SPSR & (1<<SPIF)));
return SPDR;
}