2018-02-16 01:30 PM
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 clockGPIO_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.
Thanks,
Randy
Solved! Go to Solution.
2018-02-16 03:43 PM
Clive,
Thanks. I understand that various peripheral could connect to a pin. I’ve been using a another doc that list this information differently. I also realize that the other docs list the registers for this alternate function.
What I can’t find is a doc that ties these together with a good explanation.
I really do appreciate your help.
Randy
2018-02-17 03:58 AM
I’ve been using a another doc
So tell us what 'doc' that is!
Note that the complete documentation for the part is spread across two documents:
: focuses on peripheral operation, registers, etc.
You need both.
2018-02-20 12:06 PM
Andrew,
I was referencing both the reference manual, RM3016, the programming manual, PM0214, and the STM32F303x6/x8 doc. I DID miss the RM316 section 11.3.2 dealing with the AF register. Reading this section and using Clives table would have help me resolve my own problem.Thanks for everyone's help.
Randy
2018-02-20 12:08 PM
Clive,
RM316 section 11.3.2 dealing with the AF register. Reading this section clarifies the table information. Thanks for everyone's help.
Do I need to close this? If yes then how?
Randy