/********************************* (C) РОТЕК *********************************** * @module buttons_api * @file buttons_api.c * @version 1.0.0 * @date XX.XX.XXXX * $brief buttons_api ******************************************************************************* * @history Version Author Comment * XX.XX.XXXX 1.0.0 Telenkov D.A. First release. ******************************************************************************* */ #include "stm32f4xx.h" #include "ports.h" #include "FreeRTOS.h" #include "task.h" char recvBufRS232[RS232_MAX_REC_LEN]; // Входной буфер для RS232 uint16_t indexRS232; /** * @brief */ void RS232_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_SetPriority (USART3_IRQn, 5); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(RS232_PORT, &USART_InitStructure); USART_Cmd(RS232_PORT, ENABLE); USART_ITConfig(RS232_PORT, USART_IT_RXNE, ENABLE); USART_ITConfig(RS232_PORT, USART_IT_TXE, DISABLE); } /** * @brief RS232 */ /*void USART3_IRQHandler(void) { char byte; if(USART_GetITStatus(RS232_PORT, USART_IT_RXNE) != RESET) { byte = (uint8_t)(RS232_PORT->DR & (uint16_t)0x01FF); recvBufRS232[indexRS232++] = byte; // Защита от выхода за границу отведенного буфера if (indexRS232 == (RS232_MAX_REC_LEN - 1)) indexRS232 = 0; } }*/ void RS232_SendByte(char byte) { while(USART_GetFlagStatus(RS232_PORT, USART_FLAG_TXE) == RESET) {} RS232_PORT->DR = (byte & (uint16_t)0x01FF); } /********************************* (C) РОТЕК **********************************/