AnsweredAssumed Answered

UART STM32F030

Question asked by hakim.soni on Feb 7, 2014
Latest reply on Feb 10, 2014 by Clive One
hello all,
I want to try the UART of STM32F030 using USART1 (pinA9 Tx, pinA10 Rx). I have try to modify some code from internet to make mikro send 'A' (0100 0001)via Tx. but when I connect Tx pin (PA9) to osciloscope, output signal is just flat 1 volt. I expecting pulse signal (0100 0001). Please help me find wrong part from the code.
this is my code

#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx.h"
#include "stm32f0xx_usart.h"
 
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
 
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOA, &GPIO_InitStruct);
}
 
void USART_Configuration(void)
{
    USART_InitTypeDef USART_InitStructur;
    USART_ClockInitTypeDef USART_ClockInitStructur;
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
 
    USART_ClockInitStructur.USART_CPHA = USART_CPHA_2Edge;
    USART_ClockInitStructur.USART_CPOL = USART_CPOL_High;
    USART_ClockInitStructur.USART_Clock = USART_Clock_Disable;
    USART_ClockInitStructur.USART_LastBit = USART_LastBit_Enable;
    USART_ClockInit(USART1, &USART_ClockInitStructur);
 
    USART_InitStructur.USART_BaudRate = 9600;
    USART_InitStructur.USART_WordLength = USART_WordLength_8b;
    USART_InitStructur.USART_StopBits = USART_StopBits_1;
    USART_InitStructur.USART_Parity = USART_Parity_No;
    USART_InitStructur.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructur.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART1, &USART_InitStructur);
 
    USART_Cmd(USART1,ENABLE);
}
 
int main(void)
{
    GPIO_Configuration();
    USART_Configuration();
 
    while(1)
    {
        while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
        USART_SendData(USART1, 'A');
    }
}

thanks for your help.

Outcomes