cancel
Showing results for 
Search instead for 
Did you mean: 

Uart in STM32F4

mikropart
Associate II
Posted on January 31, 2015 at 16:03

I create a program for uart interrupt receiving by cubeMX in ARM-MDK.

I want interrupt receivng from PC(when for example 0xFF received from pc by hyperterminal or docklight).

I write bellow program.

main()

{

   while (1)

   {

        if(HAL_UART_Receive_IT(&huart6, (uint8_t *)aRxBuffer, 😎 != HAL_OK)

       {

            HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_13);

            HAL_Delay(0x000000ff);

       }

        HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_12);

        HAL_Delay(0x000000ff);

    }

}

///////////////////////////////////////////////////

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

    HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);

}

but not work.Please help me.

8 REPLIES 8
Posted on February 02, 2015 at 09:40

You might want to start with reviewing and reproducing the examples contained within the Cube package.

JW
mikropart
Associate II
Posted on February 02, 2015 at 20:29

hi

I read cube example but i don't know. do you have a simple example?

Posted on February 02, 2015 at 21:28

do you have a simple example?

Not a HAL one.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
dhiry2k
Associate II
Posted on February 03, 2015 at 15:38

Check HAL example of UART. Check for F3 or F2 one's. basic concept is same in all.

pcm-lab
Associate II
Posted on February 06, 2015 at 12:04

Hi ramin!

while (1)  and  IRQ metod -  not very compatible 😉

If you want to call the reception of the cycle,

- you ned HAL function HAL_UART_Receive

 (NOT  HAL_UART_Receive_IT ! )

as example :

  while (1)

  {

    if (HAL_UART_Receive ( &huart2, aTxBuffer, 8, 5000 ) == HAL_OK)

        {

         HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);

         HAL_Delay(100);

         HAL_UART_Transmit( &huart2, aTxBuffer, 8, 5000 );

         HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);

        }

================================================

If you want to call the reception of the interrupt

-use HAL_UART_Receive_IT()

 with

void USARTx_IRQHandler(void)

{

  HAL_UART_IRQHandler(& UartHandle);

}

check whether this function in the file : stm32f4xx_it.c

and check - whether this function in the file : stm32f4xx_hal_msp.c

HAL_NVIC_EnableIRQ(USART2_IRQn);

==================================================== 

pcm-lab
Associate II
Posted on February 06, 2015 at 12:12

waclawek.jan +1

for sure!

lock in d: \ _ ST_ \ STM32Cube \ Projects \ STM32F401-Discovery \ Examples \ UART

\UART_TwoBoards_ComPolling     - a simple method

\UART_TwoBoards_ComIT             - based on interrupts

\UART_TwoBoards_ComDMA       - DMA on IRQ method

mikropart
Associate II
Posted on February 06, 2015 at 20:09

hi nazarov

I edit my code as bellow(I want use of uart interrupt driven receiving):

//------------------------------------------------------------------------

UART_HandleTypeDef  huart6;

int

main(

void

)

{

    HAL_Init();

    SystemClock_Config();

    MX_GPIO_Init();

    MX_USART6_UART_Init();

    HAL_UART_Receive_IT(&huart6, (uint8_t *)aRxBuffer, 8);

   

while

(1)

    {

        HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13,GPIO_PIN_SET);

        HAL_Delay(1000);

     }

}

void

HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,GPIO_PIN_SET);

}

and I look at  stm32f4xx_it.c

that contain bellow code:

void

USART6_IRQHandler(

void

)

{

   HAL_UART_IRQHandler(&huart6);

}

but  my

problem(

not working HAL_UART_RxCpltCallback()

) exist.

do you have any idea?

thank.

mikropart
Associate II
Posted on February 06, 2015 at 20:28

and in stm32f4xx_hal_msp.c  I find this code:

/* System interrupt init*/

    HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(USART6_IRQn);

thank