#include "usart.h" void USART::init() { UCSR0A = _BV(U2X0); UCSR0B = _BV(RXEN0) | _BV(TXEN0); // Einstellen des Datenformats: 8 Datenbits, 1 Stoppbit UCSR0C = _BV(UCSZ00) |_BV(UCSZ01);// (1<> 8) & 0xFF; UBRR0L = ((F_CPU / (8UL * BAUDRATE))-1) & 0xFF; } void USART::flush() { uint8_t dummy; do { dummy = UDR0; _delay_us((1000000 / BAUDRATE) * 16); // Warte Übertragungszeit von 16 Bit ab } while (UCSR0A & (1<>= 8; while (!(UCSR0A & (1<>= 1; } } writeByte(crc); return readByte(); } uint8_t USART::readByte() { while (!(UCSR0A & (1< MAX_BLOCK_SIZE) len = 0; for(uint8_t k = 0; k <= len; k++) // len + 1 Durchgänge (+ crc) { uint8_t next = readByte(); crc ^= next; for (uint8_t i = 0; i < 8; i++) { if (crc & 1) crc ^= CRC7_POLY; crc >>= 1; } if(k < len) ptr[k] = next; } flush(); // leere Eingangspuffer writeByte(crc == 0 ? MSG_OK : MSG_FAIL); } while(crc != 0); }