Код: Выделить всё
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_usart.h"
void send_to_uart(uint8_t data)
{
while(!USART_GetFlagStatus(USART2, USART_FLAG_TC));
UART4->DR=data;
}
void send_str(char * string)
{
uint8_t i=0;
while(string[i])
{
send_to_uart(string[i]);
i++;
}
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStr;
GPIO_InitTypeDef GPIO_5_InitStr;
USART_InitTypeDef USART_InitStr;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_APB1Periph_USART2, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_InitStr.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStr.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStr.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStr.GPIO_OType = GPIO_OType_PP;
GPIO_InitStr.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStr);
GPIO_5_InitStr.GPIO_Pin = GPIO_Pin_5;
GPIO_5_InitStr.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_5_InitStr.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(GPIOA, &GPIO_5_InitStr);
USART_InitStr.USART_BaudRate = 9600;
USART_InitStr.USART_WordLength = USART_WordLength_8b;
USART_InitStr.USART_StopBits = USART_StopBits_1;
USART_InitStr.USART_Parity = USART_Parity_No;
USART_InitStr.USART_Mode = USART_Mode_Tx;
USART_InitStr.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART2, &USART_InitStr);
USART_Cmd(USART2, ENABLE);
while(1)
{
//send_str("Fucking USART!!!");
if(!USART_GetFlagStatus(USART2, USART_FLAG_TC))
{
GPIO_SetBits(GPIOA, GPIO_Pin_5);
}
}
}

