0
\$\begingroup\$

HAL_UART_Transmit_DMA call in timer interrupt handler to check the output for just now. The output is came but this is not proper output. this method for just call in to the interrupt handler output is continuously came for five bytes data. I need a output for 500 millisec once Five Bytes data transmit. so you told method doesn't get the proper output for me. I includeenter image description here the output for picture and code. please tell what can I do for next step. I need a output for third picture. But I have transmit five byte data and UART DMA transmit only two Bytes data or continuously. enter image description hereenter image description here enter image description here

#include "main.h"

TIM_HandleTypeDef htim3;

UART_HandleTypeDef huart2; DMA_HandleTypeDef hdma_usart2_tx;

/* USER CODE BEGIN PV */

uint16_t tim=0;

uint8_t tx_buf[5]= {0x01,0x02,0x03,0x04,0x05};

/* USER CODE END PV */

void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_DMA_Init(void); static void MX_USART2_UART_Init(void); static void MX_TIM3_Init(void);

int main(void) {

HAL_Init();

SystemClock_Config();

MX_GPIO_Init(); MX_DMA_Init(); MX_USART2_UART_Init(); MX_TIM3_Init(); /* USER CODE BEGIN 2 */

HAL_TIM_Base_Start_IT(&htim3);
HAL_UART_Transmit_DMA(&huart2, tx_buf, sizeof(tx_buf));  // 500 msec once

/* USER CODE END 2 */

while (1) {

} }

void TIM3_IRQHandler(void) { /* USER CODE BEGIN TIM3_IRQn 0 */

/* USER CODE END TIM3_IRQn 0 / HAL_TIM_IRQHandler(&htim3); / USER CODE BEGIN TIM3_IRQn 1 */ tim++;

 if(tim==500)
 {
    __HAL_DMA_ENABLE(huart2.hdmatx);
     tx_buf[0] = 0x01;
     tx_buf[1] = 0x02;
     tx_buf[2] = 0x03;
     tx_buf[3] = 0x04;
     tx_buf[4] = 0x05;
        tim=0;  
    __HAL_DMA_DISABLE(huart2.hdmatx);
 }

/* USER CODE END TIM3_IRQn 1 */ }

\$\endgroup\$
4
  • \$\begingroup\$ Which MCU do you use? I assume during the execution of the useless code between HAL_DMA_ENABLE and HAL_DMA_DISABLE the DMA can only write two bytes to the serial interface, shift register and holding register. This is the wrong way to use a DMA service. You must provide the data before you start a DMA transfer, not while it is running already. You should not stop a DMA transfer before it has done the job (if at all). Enabling and disabling the DMA hardware is not the way to invoke a transfer. Try to find a proper demo code as template. \$\endgroup\$ Commented Jun 6, 2023 at 19:54
  • \$\begingroup\$ I am using STM32G030K6T6 MCU. \$\endgroup\$ Commented Jun 7, 2023 at 5:01
  • \$\begingroup\$ problem solved.... , Thank you so much your response. \$\endgroup\$ Commented Jun 13, 2023 at 5:09
  • \$\begingroup\$ Does this answer your question? How to transmit five byte data in using UART with DMA? \$\endgroup\$ Commented Jun 13, 2023 at 6:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.