cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 UART Interrupt

70dbf9d7
Associate
Posted on August 05, 2015 at 14:57

Hi there,

I have a nucleo board based on the STM32F152RET6 and I'm using the STM32CubeMX.

I want to toggle the LED when a caracter is received on IT but I've tried a looooooot of things but nothing makes it work...

TX works fine.

I've tried with both CooCox, and Eclips with GCC tool ARM.

If someone knows where is the problem..

Attached the files of my project.

In the while(1) I'm sending the letter ''a'', because I wanted to test if something happened when TX and RX where wired on the board. But when I did so, the transmiting stops... And restart when I remove the wire.

Thanks in advance
3 REPLIES 3
RomainR.
ST Employee
Posted on August 05, 2015 at 16:25

Suppose you want to send a sequence of characters on UART2 when an interrupt event occurs with the USER_BUTTON.

Your program can not works (both on-ARM Keil or other compilers) because:

1- You should use the callback function for interrupts event in your main.c

See prototypes void __weak HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin) in the source file stm32l1xx_hal_gpio.c

2- I doubt that interrupt event occurs because you call the function:

HAL_UART_Transmit (& huart2 (uint8_t *) msg2, strlen (msg2) 0xFFFF);

in your main program and from GPIO_EXTI interrupts function.

This function works by polling so no interrupt UART2 can occur !!!

If you need to use interrupts for any peripherals, you should use 

UART2 HAL_UART_Transmit_IT  function.

And then

handle LED toggle by using callback  functions belows:

 

HAL_GPIO_EXTI_Callback()

and

 

HAL_UART_TxCpltCallback (UART_HandleTypeDef UartHandle *)

or

 

HAL_UART_RxCpltCallback (UART_HandleTypeDef UartHandle *)

3- You should look at the many examples of programs CubeMX and start a project with UART interrupt transmission.

These examples already exist in your C: \ Users \ username \ STM32Cube \ Repository

Good luck

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

70dbf9d7
Associate
Posted on August 07, 2015 at 11:15

Hy! Thank you for your response! I manage to run the STM32Cube UART_IT test program for my nucleo (I had to change some false configurations...).

But my question is, why do we have to use the CallBack functions?

Cant we just use theXXXX_IRQHandler()?

That sound weird for me...

I just want to go in the IRQHandler when I receive a caracter in the RX buffer and then put it in a FIFO. Juste this, not a gas factory...

But STM32 seems to be this sort of things!

Thanks!

EDIT :I've found

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/STM32Cube%20%20UART%20Receive%20Interrupt&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&currentviews=2806

I'm going to test it.

RomainR.
ST Employee
Posted on August 11, 2015 at 10:15

Strategy of

CubeMX

(

HAL_Driver

)

is precisely to

simplify

complex

coding

as

:

-

The

device configuration

(which

cause

90%

of

non-functional

applications)

-

And

the correct

handle

the

interrupt

functions

,

ie

the assertion

of

good

and

clear

flag

of

IT

.

This

is what the

Library

HAL

do.

It

remains for you to

focus on your

functionalities

using

callback functions

to receive

your

code lines

.

It's a bit

confusing at first

but you

'll find that it

greatly simplifies

things

.

If you

want to write the

character received

in a buffer

,

it simply

made

in the

callback function

:

HAL_UART_RxCpltCallback

void

(

*

UART_HandleTypeDef

UartHandle

)

And you do

not have to touch

anything

in

USARTx_IRQHandler

Good luck

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.