2015-08-05 05:57 AM
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 advance2015-08-05 07:25 AM
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 thenhandle 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 luckTo give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2015-08-07 02:15 AM
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 I'm going to test it.2015-08-11 01:15 AM
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.