Author Topic: Help getting STM32 Half duplex to work  (Read 3923 times)

0 Members and 1 Guest are viewing this topic.

Offline ShreeyakTopic starter

  • Newbie
  • Posts: 1
  • Country: in
Help getting STM32 Half duplex to work
« 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:
Code: [Select]
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.
« Last Edit: February 25, 2017, 09:19:31 pm by Shreeyak »
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Help getting STM32 Half duplex to work
« Reply #1 on: February 25, 2017, 09:54:40 pm »
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, with SPI rather than UART.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline branjb

  • Contributor
  • Posts: 16
  • Country: us
Re: Help getting STM32 Half duplex to work
« Reply #2 on: February 26, 2017, 01:07:09 am »
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

Code: [Select]
HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);

because the HAL code didn't include it.
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Help getting STM32 Half duplex to work
« Reply #3 on: February 26, 2017, 11:55:10 am »
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

Code: [Select]
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.:
Code: [Select]
// 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.
Nandemo wa shiranai wa yo, shitteru koto dake.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf