This commit is contained in:
Tom Selier 2022-11-18 18:42:34 +01:00
commit fcbcbc5973
2 changed files with 62 additions and 0 deletions

45
UART.c Normal file
View File

@ -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]);
}

17
UART.h Normal file
View File

@ -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_ */