AnsweredAssumed Answered

Need help using USUART2 on STM32F303

Question asked by Randy Nelson on Feb 16, 2018
Latest reply on Feb 20, 2018 by Randy Nelson

I'm trying to find instruction to code the usuart2 on this STM part. I using cmsis and the StdPeripheral lib. My end goal is to connect this to a virtual com port for debug. I'm using the Keil development environment.



I using the default HSI clock setup running at 8MHZ then -


RCC->AHBENR |= BIT17; //Enable portA clock
RCC->AHBENR |= BIT18; //Enable portB clock


GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOA, &GPIO_InitStructure);


RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

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;
USART_Init(USART2, &USART_InitStructure);


//send the data

USART_SendData(USART2, 0xaa);


I realize the baud may be wrong but right now I'm trying to see something on the PA2 pin 

with a scope. Nothing is changing.


I tried to make sure the tx register was empty before writing the data using:

if( ((USART2->ISR) & BIT7)) != 0) {

  USART_SendData(USART2, 0xaa);



Still nothing coming out.


Any suggestions.