// Ausgabe auf Debug-Terminal #include "usart2.h" #include "stdlib.h" #include "stdio.h" #include "stm32f446xx.h" // private Funktionen void usart2_write(char data) { while((USART2->SR & 128) == 0); // warten, bis Buffer frei ist USART2->DR = data; } char usart2_read(void) { while((USART2->SR & 32) == 0); // warten auf Zeichen return (char)(USART2->DR); } /***************************************************/ void usart2_put(const char* text) { while(*text != 0) { usart2_write(*text); text = text + 1; } usart2_write(13); usart2_write(10); } void usart2_put(const int value) { char buffer[12]; sprintf(buffer, "%i", value); usart2_put(buffer); } // String einlesen, return Länge der empfangenen Zeichenkette, max. 40 Zeichen int usart2_get(char *text) { int len = 0; char c = 0; while((c != 13) && (len < 40)) { c = usart2_read(); *text = c; text = text + 1; len = len + 1; } text = text - 1; *text = 0; // Stringende return len - 1; // Länge ohne Nullzeichen } // Integer lesen int usart2_get(void) { char buffer[40]; usart2_get(buffer); return atoi(buffer); }