#include "SD_MAX.h" #include "diskio.h" #include "integer.h" #include "pff.h" #include "pffconf.h" #include #include #include #include #include #include #include /*if ((BAUD_ERROR>10)||(BAUD_ERROR <-10)) { error "Zu hohe Baudrate"; }*/ uint16_t highByte = 0; uint16_t lowByte = 0; uint16_t wert =0; uint16_t result = 0; int T=0; int H=0; int Z=0; int E=0; //SPI-Konfiguration MAX6675 void SPI_MasterInitMAX(void){ // Set MOSI and SCK output, all others input DDR_SPI |= (1< MSB wird zuerst übertragen; SPI Modus 1 (CPHA=1, CPOL=0) } //SPI-Uebertragung MAX char SPI_MasterTransmitAndReceive(char cdata) { // Start transmission SPDR = cdata; // Wait for transmission complete while(!(SPSR & (1<out , 0 , NUM_OF_SENS * 7 ); // Speicher löschen uint8_t x; for( x = 0 ; x < NUM_OF_SENS ; x++ ) { if( sd->temp[x] > 300 || sd->temp[x] == 0 ) // Fehler ist aufgetreten { return 1; } strcat( sd->out , itoa( x + 1 , result , 10 ) ); strcat( sd->out , "#" ); itoa( sd->temp[x] , result, 10 ); strcat( sd->out + strlen( sd->out ) , result ); strcat( sd->out , " " ); } strcat( sd->out , "\r\n" ); return 0; } typedef enum { MAX6675_THREE_STATE = 1<<0, MAX6675_ID = 1<<1, MAX6675_THERMOCOUPLE_INPUT = 1<<2, }max6675_state; max6675_state max6675getState( uint8_t in ) { return ( in & ( MAX6675_THREE_STATE | MAX6675_ID ) | MAX6675_THERMOCOUPLE_INPUT ); } void calcSaveTemp( uint8_t highByte , uint8_t lowByte , uint8_t sensNum ) { uint16_t tempAD = ( uint16_t ) highByte << 5 | ( uint16_t ) lowByte >> 3; tempAD >>= 2; sd_t s; s.temp[ sensNum ] = tempAD; tempToStr( &s ); } int main(void) { FATFS fs; //FRESULT res; SPI_MasterInitMAX(); disk_initialize(); pf_mount(&fs); //mount the volume pf_open("Daten.txt"); //open a file while(1) { _delay_ms(200); //unter 200 ms sendet MAX nichts mehr PORTB &= ~(1<<2); // CS Max low _delay_ms(1); highByte = SPI_MasterTransmitAndReceive(0x03); lowByte = SPI_MasterTransmitAndReceive(0x03); PORTB |= (1<<2); // CS Max high if( max6675getState( lowByte ) & MAX6675_THERMOCOUPLE_INPUT ) { // Fühler Fehler } calcSaveTemp( highByte , lowByte , 0 ); } }