diff options
Diffstat (limited to 'Project/src')
-rw-r--r-- | Project/src/main.c | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/Project/src/main.c b/Project/src/main.c index 2132d87..0d485bc 100644 --- a/Project/src/main.c +++ b/Project/src/main.c @@ -90,10 +90,10 @@ static void USART1Init(void) GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); @@ -108,6 +108,32 @@ static void USART1Init(void) USART_Cmd(USART1, ENABLE); } +static void USART4Init(void) +{ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE); + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); + GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4); + GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4); + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; + GPIO_Init(GPIOA, &GPIO_InitStructure); + USART_InitTypeDef usart4_init = {0}; + usart4_init.USART_BaudRate = 9600; + usart4_init.USART_WordLength = USART_WordLength_8b; + usart4_init.USART_StopBits = USART_StopBits_1; + usart4_init.USART_Parity = USART_Parity_No; + usart4_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + usart4_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_Init(USART4, &usart4_init); + USART_Cmd(USART4, ENABLE); +} + // ---------------------------------------------------------------------------- // Инициализация до создания задач // ---------------------------------------------------------------------------- @@ -115,6 +141,7 @@ void InitAll ( void ) { SystemInit(); USART1Init(); + USART4Init(); InitLTimers(); LightSensorInit(); #if 0 @@ -134,11 +161,8 @@ static void TestUart(void *arg) { (void) arg; while (1) { - if (USART1->ISR & USART_ISR_FE) { - USART1->ICR &= USART_ICR_FECF; - } - if (USART1->ISR & USART_ISR_RXNE) { - const uint16_t data = USART_ReceiveData(USART1); + if (USART4->ISR & USART_ISR_RXNE) { + const uint16_t data = USART_ReceiveData(USART4); USART_SendData(USART1, data); } } |