简体   繁体   中英

Stm32 CubeIde how to disable receive interrupt command

I have a program which enables interrupt receive until 250ms passed after message send, and after 250ms it should diable the interrupt and shouldn't receive any message until new message send. I wrote somethnig like that and I think it will work if I can disable Receive_IT but couldn't find anything about it

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
      i = rand() % 250 ;
      CAN_TxData[0] = i ;
      came = 1;
      currTime = HAL_GetTick();
      HAL_CAN_AddTxMessage(&hcan1, &CAN_TxHeader, CAN_TxData, &CAN_TxMailBox); // yollama kodu
      while((HAL_GetTick()-currTime <= 250) && came)
      {
          HAL_UART_Receive_IT(&huart2, TTL_RxData, 8);
      }
      if (HAL_GetTick()-currTime > 250)
      {
          // Here I should disable receive IT 
          timeoutted ++;
      }
  }

Since everyone complained about my solution I wanted to clarify my project.

First stm32 will send 8byte data to the second stm32 by using CAN, and second stm32 will send the same data by using USART to the first stm32.

If first stm32 receives the message until 250ms passed after its own message, it will check if its the same message it send or not then record it (correct ++ and wrong ++). But if 250ms passed and first stm32 didn't receive anyhting it says it is timeout and will start the same process again. This will continue.

This code makes no sense at all.

You call the HAL_UART_Receive_IT function in the loop (it only sets stuff but not waiting for anything). It is called hundreds (or maybe even many thousands) of times in this loop.

What you can do:

  1. Set the timer interrupt for 250ms.
  2. If IT receive complete callback is fired before it expires disable the timer interrupt.
  3. If the timer interrupt is invoked, simply abort IT receive HAL_UART_AbortReceive_IT (which will also disable this interrupt)

The interrupts of the CAN peripheral are en-/disabled in the IE register. You will have to look up which bits are responsible for the RX interrupts in the Reference manual (register FDCAN_IE for the newer controllers) and set them to 0 to disable them. The register can also be completely set to 0 by using the handle, however it is strongly advised to use a bitmask to shield all bits, which are not responsible for the RX interrupts, especially the reserved bits:

hcan1->Instance->IE = 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM