commit fcbcbc597363293695bed3aaa439791ec980f10f Author: tomseli Date: Fri Nov 18 18:42:34 2022 +0100 Init diff --git a/UART.c b/UART.c new file mode 100644 index 0000000..c5aefdf --- /dev/null +++ b/UART.c @@ -0,0 +1,45 @@ +/* + * UART.c + * + * Created on: Nov 18, 2022 + * Author: Tom + */ + +#include "main.h" +#include "string.h" + +extern UART_HandleTypeDef huart2; + +/* + * @brief print any char to UART + * @param char to print + */ +void UART_char(unsigned char c) +{ + HAL_UART_Transmit(&huart2, &c, 1, 10); +} + + +/* + * @brief print any int to UART + * @param int to print + */ +void UART_int(unsigned int value) +{ + char text[8]; + + HAL_UART_Transmit(&huart2, (uint8_t*) text, sprintf(text, "%d", value), 100); +} + + +/* + * @brief print any string to UART + * @param char* to string + */ +void UART_string(char* s) +{ + int i = 0; + + for(; s[i]; i++) + UART_char(s[i]); +} diff --git a/UART.h b/UART.h new file mode 100644 index 0000000..1d8328a --- /dev/null +++ b/UART.h @@ -0,0 +1,17 @@ +/* + * UART.h + * + * Created on: Nov 18, 2022 + * Author: Tom + */ + +#ifndef UART_UART_H_ +#define UART_UART_H_ + +#include "stdio.h" + +void UART_char(unsigned char c); +void UART_int(unsigned int); +void UART_string(char*); + +#endif /* UART_UART_H_ */