Skip to main content
ag n.1
Associate II
Apr 11, 2022 9:48 AM UTC
Solved

I am trying to transfer a character using uart in stm32f030 to pc , done with initialization with uart config there is no errors but I am not able to see data sent .please help

void uartInit()

{

USART_InitTypeDef uartInitStruct;

GPIO_InitTypeDef gpioInitStruct;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

gpioInitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

gpioInitStruct.GPIO_Mode = GPIO_Mode_AF;

gpioInitStruct.GPIO_OType = GPIO_OType_PP;

gpioInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

gpioInitStruct.GPIO_Speed = GPIO_Speed_Level_1;

GPIO_Init(GPIOA,&gpioInitStruct);

uartInitStruct.USART_BaudRate = 9600;

uartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

uartInitStruct.USART_WordLength = USART_WordLength_8b;

uartInitStruct.USART_Parity = USART_Parity_No;

uartInitStruct.USART_StopBits = USART_StopBits_1;

uartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_Init(USART1,& uartInitStruct);

}

int main()

{

uint16_t alpha= 'A';

uartInit();

while(1)

{

USART_SendData(USART1,alpha);

USART_SendData(USART1,'\n');

}

}

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Apr 11, 2022 1:42 PM UTC

The line should spin waiting for TXE to assert

Did you copy-n-paste it properly? Perhaps you missed the semi-colon?

Alternative would be to check it's empty first

if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET)
 USART_SendData(USART1, (uint8_t)0x55);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

7 replies

Tesla DeLorean
Guru
Apr 11, 2022 11:48 AM UTC

Set the correct AF pin mux setting.

Outputs​ at CMOS levels, not RS232.

Send code not shown.​

Clear auto/local variables.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ag n.1
ag n.1Author
Associate II
Apr 11, 2022 12:38 PM UTC

sir can you plz explain I am not able get you

Tesla DeLorean
Guru
Apr 11, 2022 12:56 PM UTC

Which part?

void uartInit()

{

USART_InitTypeDef uartInitStruct = {0};

GPIO_InitTypeDef gpioInitStruct = {0};

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

gpioInitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

gpioInitStruct.GPIO_Mode = GPIO_Mode_AF;

gpioInitStruct.GPIO_OType = GPIO_OType_PP;

gpioInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

gpioInitStruct.GPIO_Speed = GPIO_Speed_Level_1;

GPIO_Init(GPIOA,&gpioInitStruct);

 /* Connect PXx to USARTx_Tx */

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);

 /* Connect PXx to USARTx_Rx */

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);

uartInitStruct.USART_BaudRate = 9600;

uartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

uartInitStruct.USART_WordLength = USART_WordLength_8b;

uartInitStruct.USART_Parity = USART_Parity_No;

uartInitStruct.USART_StopBits = USART_StopBits_1;

uartInitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_Init(USART1,& uartInitStruct);

 }

...

while(1)

{

 while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

 USART_SendData(USART1, (uint8_t)0x55);

}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ag n.1
ag n.1Author
Associate II
Apr 11, 2022 1:36 PM UTC

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

if i give USART_FLAG_TXE) == SET i am getting the data.

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Apr 11, 2022 1:42 PM UTC

The line should spin waiting for TXE to assert

Did you copy-n-paste it properly? Perhaps you missed the semi-colon?

Alternative would be to check it's empty first

if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == SET)
 USART_SendData(USART1, (uint8_t)0x55);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
ag n.1
ag n.1Author
Associate II
Apr 12, 2022 5:08 AM UTC

this its working sir thank you :D .