EEVblog Electronics Community Forum
Electronics => Microcontrollers => Topic started by: Shreeyak on February 25, 2017, 08:19:17 pm
-
Hi,
I'm using a STM32f302r8 nucleo and am trying to get the half-duplex UART working with DMA and interrupts to talk to dynamixel motors. Can anyone help me out please?
Right Now, I've just got the following working:
while(1)
{
uint8_t pData[3]="hi!";
HAL_HalfDuplex_EnableTransmitter(&huart1);
HAL_UART_Transmit(&huart1, pData, 3, 500);
HAL_Delay(500);
}
But when I use DMA with Interrupts (HAL_UART_TxCpltCallback), things aren't working. I'm not sure what all information I should put in here.
-
I was writing a list of questions, with small reprimand for not providing enough information, but I see you edited your post.
One question stands, though: did you use CubeMX to set up the DMA too?
If not, show us the init code, there might be something missing.
See also a recent similar thread (https://www.eevblog.com/forum/microcontrollers/dma-spi-on-stm32f030f4/), with SPI rather than UART.
-
Did you enable the callback interrupt? Not sure if the HAL sets it up for you or not. I recently ran into an issue where the HAL didn't enable the callback IRQ for a timer in OC mode. Had to manually invoke
HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
because the HAL code didn't include it.
-
Did you enable the callback interrupt? Not sure if the HAL sets it up for you or not. I recently ran into an issue where the HAL didn't enable the callback IRQ for a timer in OC mode. Had to manually invoke
HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
because the HAL code didn't include it.
The HAL, being just an API, will not do much by itself (in this case, in others it might do an awful lot too much...), it only provides the building blocks.
But the OP mentioned CubeMX, and the code generator will insert the appropriate code to enable interrupts and link the DMA to the UART, if correctly configured, e.g.:
// In main.c
//...in main function...
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
//...
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA2_Stream7_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn);
}
// In strm32f4xx_it.c (I don't have a STMF3, not bothering to DL the right Cube)
void DMA2_Stream7_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
/* USER CODE END DMA2_Stream7_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_usart1_tx);
/* USER CODE BEGIN DMA2_Stream7_IRQn 1 */
/* USER CODE END DMA2_Stream7_IRQn 1 */
}
// etc. etc.
The DMA interrupt used, not the UART one: the HAL will translate it to the UART's callbacks.