PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Atmega16 und SPI



tiabebo
21.06.2006, 16:36
Hi,

ich will einen 16 bits String von einem Chip ankommen. Dabei benutze ich den SPI. Danach will ich ein Teil des String in die LED´s schicken. Der Prozessor ist ein Atmega16.




#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>

#define DDR_SPI DDRB
#define DD_SS PB4
#define DD_SCK PB7
#define DD_MISO PB6



// Receive data from the MAXIM through the serial peripherical interface
// between Master : MAXIM and Slave : Atmel

void SPI_SlaveInit(void){ // Initialitation of the slave

DDR_SPI = (1<<DD_MISO);// Set MISO output, and all others input
SPCR = (1<<SPE)|(1<<SPIE); // Enable SPI and SPI Interruptions
sei();

}

char SPI_SlaveReceive(void){

while(!(SPSR & (1<<SPIF))); // Wait for reception complete
return SPDR; // Return data register

}

int main(void)
{
//Initialisierung des Controller und des Displays
DDRC = 0xff; //PORT C als Ausgänge

SPI_SlaveInit();// Initialitation of the slave

char tempbin;

while(1){
tempbin= SPI_SlaveReceive();
PORTC = 3 >> tempbin;
_delay_ms(100);

}

return 1;

}



Mfg

Peter