Mercurial > public > ostc4
comparison Small_CPU/Src/uart.c @ 38:5f11787b4f42
include in ostc4 repository
| author | heinrichsweikamp |
|---|---|
| date | Sat, 28 Apr 2018 11:52:34 +0200 |
| parents | |
| children | 1b995079c045 |
comparison
equal
deleted
inserted
replaced
| 37:ccc45c0e1ea2 | 38:5f11787b4f42 |
|---|---|
| 1 /** | |
| 2 ****************************************************************************** | |
| 3 * @file uart.c | |
| 4 * @author heinrichs weikamp gmbh | |
| 5 * @version V0.0.1 | |
| 6 * @date 27-March-2014 | |
| 7 * @brief button control | |
| 8 * | |
| 9 @verbatim | |
| 10 ============================================================================== | |
| 11 ##### How to use ##### | |
| 12 ============================================================================== | |
| 13 @endverbatim | |
| 14 ****************************************************************************** | |
| 15 * @attention | |
| 16 * | |
| 17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
| 18 * | |
| 19 ****************************************************************************** | |
| 20 */ | |
| 21 /* Includes ------------------------------------------------------------------*/ | |
| 22 #include "uart.h" | |
| 23 | |
| 24 /* Private variables ---------------------------------------------------------*/ | |
| 25 | |
| 26 UART_HandleTypeDef huart2; | |
| 27 | |
| 28 | |
| 29 /* Exported functions --------------------------------------------------------*/ | |
| 30 | |
| 31 void MX_USART2_UART_Init(void) | |
| 32 { | |
| 33 /* pullup special */ | |
| 34 GPIO_InitTypeDef GPIO_InitStructure; | |
| 35 __GPIOA_CLK_ENABLE(); | |
| 36 GPIO_InitStructure.Pin = GPIO_PIN_2; | |
| 37 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | |
| 38 GPIO_InitStructure.Pull = GPIO_PULLUP; | |
| 39 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | |
| 40 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | |
| 41 | |
| 42 /* regular init */ | |
| 43 huart2.Instance = USART2; | |
| 44 huart2.Init.BaudRate = 1200; | |
| 45 huart2.Init.WordLength = UART_WORDLENGTH_8B; | |
| 46 huart2.Init.StopBits = UART_STOPBITS_1; | |
| 47 huart2.Init.Parity = UART_PARITY_NONE; | |
| 48 huart2.Init.Mode = UART_MODE_TX_RX; | |
| 49 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 50 huart2.Init.OverSampling = UART_OVERSAMPLING_16; | |
| 51 HAL_UART_Init(&huart2); | |
| 52 } | |
| 53 | |
| 54 | |
| 55 uint8_t UART_ButtonAdjust(uint8_t *array) | |
| 56 { | |
| 57 uint8_t answer[4]; | |
| 58 | |
| 59 HAL_UART_Transmit(&huart2,array,4,1000); | |
| 60 HAL_UART_Receive(&huart2,answer,4,2000); | |
| 61 if( (answer[0] == array[0]) | |
| 62 &&(answer[1] == array[1]) | |
| 63 &&(answer[2] == array[2]) | |
| 64 &&(answer[3] == array[3])) | |
| 65 return 1; | |
| 66 else | |
| 67 return 0; | |
| 68 } | |
| 69 | |
| 70 void MX_USART2_UART_DeInit(void) | |
| 71 { | |
| 72 HAL_UART_DeInit(&huart2); | |
| 73 } | |
| 74 | |
| 75 | |
| 76 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
