Beispiel #1
0
static void USART3_Configuration(void)
{

	// Periph CLK Init
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

	// GPIO Pins for UART3
	USART3_GPIO_Configuration();
	// NVIC for UART3
	USART3_NVIC_Configuration();

	// --------------- USART3 configuration ---------------
	// USART1 configured as follow:
	USART_InitTypeDef USART_InitStructure;

	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;
	// Configure the USART3
	USART_Init(USART3, &USART_InitStructure);
	// Enable the USART Transmit interrupt: this interrupt is generated when the
	// USART1 transmit data register is empty
	// USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
	// Enable the USART Receive interrupt: this interrupt is generated when the
	// USART1 receive data register is not empty
	USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
	// Enable USART1
	USART_Cmd(USART3, ENABLE);

}
Beispiel #2
0
void USART3_Config(void) {
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

	USART_ClockInitTypeDef USART_ClockInitStructure;
	GPIO_InitTypeDef UARTTX;
	UARTTX.GPIO_Pin = GPIO_Pin_10;
	UARTTX.GPIO_Mode = GPIO_Mode_AF_PP;
	UARTTX.GPIO_Speed = GPIO_Speed_50MHz;

	GPIO_InitTypeDef UARTRX;
	UARTRX.GPIO_Pin = GPIO_Pin_11;
	UARTRX.GPIO_Mode = GPIO_Mode_IPU;
	UARTRX.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &UARTTX);
	GPIO_Init(GPIOB, &UARTRX);

	USART_ClockStructInit(&USART_ClockInitStructure);
	USART_ClockInit(USART3, &USART_ClockInitStructure);

	USART_InitTypeDef UART3;
	UART3.USART_BaudRate = 9600;
	UART3.USART_WordLength = USART_WordLength_8b;
	UART3.USART_StopBits = USART_StopBits_1;
	UART3.USART_Parity = USART_Parity_No;
	UART3.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	UART3.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

	USART_Init(USART3, &UART3);
	USART_Cmd(USART3, ENABLE);

	USART3_NVIC_Configuration();
}