cancel
Showing results for 
Search instead for 
Did you mean: 

USART + Polling

officialkesh
Associate III
Posted on May 05, 2015 at 09:24

Hello all,

I am novice to STM family.

Here is the code which I have written for USART but not working .

void UsartInit(void)

{

        USART_InitTypeDef USART_InitStructure;

        GPIO_InitTypeDef GPIO_InitStructure;        

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    

        GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2 | GPIO_Pin_3;

        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

        GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;                

        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;        

        GPIO_Init(GPIOA, &GPIO_InitStructure);

        GPIO_PinAFConfig(GPIOA, GPIO_Pin_2, GPIO_AF_USART2);

        GPIO_PinAFConfig(GPIOA, GPIO_Pin_3, GPIO_AF_USART2);

        USART_InitStructure.USART_BaudRate = 115200;

        USART_InitStructure.USART_WordLength=USART_WordLength_8b;

        USART_InitStructure.USART_StopBits = USART_StopBits_1;

        USART_InitStructure.USART_Parity= USART_Parity_No;

        USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;

        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

        USART_Init(USART2, &USART_InitStructure);        

        USART_Cmd(USART2, ENABLE);

}

int main(void)

{

    char ch='A';

    UsartInit();

    while(1)    

    {

     while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) != SET);

            

     USART_SendData(USART2, ch);

    

     Delay(0x3FFFFF);

    }

}

I have no idea what I am missing here ...

I need help to rectify the error.

I have simply connected PA2 to the receiver of MAX232.

Still I am not getting data on minicom,

#uart-+-discovery-board
2 REPLIES 2
stm322399
Senior
Posted on May 05, 2015 at 09:47

Try GPIO_PinSourceX as argument of GPIO_PinAFConfig instead of GPIO_PinX.

officialkesh
Associate III
Posted on May 05, 2015 at 11:35

thank u so much 🙂