Author Topic: STM32F3 UART1 communication - nothing on TX  (Read 2934 times)

0 Members and 1 Guest are viewing this topic.

Offline fskyTopic starter

  • Contributor
  • Posts: 13
  • Country: 00
STM32F3 UART1 communication - nothing on TX
« on: September 11, 2015, 09:11:25 pm »
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:

Code: [Select]
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:
Code: [Select]
USART_SendData(USART1, 0x1111);
every second in the main loop. I have tried also:
Code: [Select]
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 :)
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: STM32F3 UART1 communication - nothing on TX
« Reply #1 on: September 11, 2015, 09:42:58 pm »
have you set the pin function to uart ?
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: STM32F3 UART1 communication - nothing on TX
« Reply #2 on: September 11, 2015, 09:47:38 pm »
In the PinAFConfig function, you SHOULD have GPIO_PinSource_X constant, instead of what you have there.
 

Offline fskyTopic starter

  • Contributor
  • Posts: 13
  • Country: 00
Re: STM32F3 UART1 communication - nothing on TX
« Reply #3 on: September 11, 2015, 09:59:14 pm »
In the PinAFConfig function, you SHOULD have GPIO_PinSource_X constant, instead of what you have there.

IT'S WORKING!
Thank you very much :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf