Hello, I was trying to configure UART1 on STM32F303VC, using discovery board.
I use CoIDE and Standard Peripheral Library. Till now I menaged to set up clocks, blink some diodes, and use SysTick with interrupts.
No success with UART however... Tried some examples, but that code, which uses some "_eval.h" library is not written clearly for me (they have hidden almost everything in functions full of defines). Here is my code for UART init:
USART_InitTypeDef USART_InitStructure;
// TX
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_Pin_6, GPIO_AF_7);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// RX
GPIO_StructInit(&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_Pin_7, GPIO_AF_7);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
To send something for debugging purposes I just do:
USART_SendData(USART1, 0x1111);
every second in the main loop. I have tried also:
USART1->TDR = 0x0000;
without any effect.
I got high state on output all the time.
Did I forget about something important?
I know that correct implementation of UART involves either DMA or interrupts. However it should transmit ANYTHING as it is now, right?
My clock configuration is 8MHz HSE multiplied by 9 on PLL, so cpu and APB2 is at 72MHz, APB1 is at 36MHz.
If I slow down all the clocks, no changes are visible (except of slower diode-blinking frequency of course
)
I will be thankfull for someone's skilled eyes to look at my code. Thanks