cancel
Showing results for 
Search instead for 
Did you mean: 

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

ag n.1
Associate II

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');

}

}

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

7 REPLIES 7

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
Up vote any posts that you find helpful, it shows what's working..
ag n.1
Associate II

sir can you plz explain I am not able get you

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
Up vote any posts that you find helpful, it shows what's working..
ag n.1
Associate II

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

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

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
Up vote any posts that you find helpful, it shows what's working..

this its working sir thank you :D .

sir after this i tried sending a string it worked and now i am trying to receive string

i am facing issue could you plz help