简体   繁体   English

stm32 CubeIde如何禁用接收中断命令

[英]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.我有一个程序可以启用中断接收,直到消息发送后 250 毫秒过去,并且在 250 毫秒后它应该禁用中断并且在新消息发送之前不应该接收任何消息。 I wrote somethnig like that and I think it will work if I can disable Receive_IT but couldn't find anything about it我写了这样的东西,我认为如果我可以禁用 Receive_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.第一个 stm32 将通过 CAN 向第二个 stm32 发送 8byte 数据,第二个 stm32 将通过 USART 向第一个 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 ++).如果第一个 stm32 收到消息,直到它自己的消息经过 250ms,它会检查它是否发送相同的消息然后记录它(正确的 ++ 和错误的 ++)。 But if 250ms passed and first stm32 didn't receive anyhting it says it is timeout and will start the same process again.但是如果 250 毫秒过去了,并且第一个 stm32 没有收到任何消息,它就会说它超时并且将再次启动相同的进程。 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).您在循环中调用HAL_UART_Receive_IT function (它只设置东西但不等待任何东西)。 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.将定时器中断设置为 250ms。
  2. If IT receive complete callback is fired before it expires disable the timer interrupt.如果 IT 接收到完整的回调在它到期之前被触发,则禁用定时器中断。
  3. If the timer interrupt is invoked, simply abort IT receive HAL_UART_AbortReceive_IT (which will also disable this interrupt)如果调用了定时器中断,只需中止 IT 接收HAL_UART_AbortReceive_IT (这也会禁用此中断)

The interrupts of the CAN peripheral are en-/disabled in the IE register. CAN 外设的中断在 IE 寄存器中启用/禁用。 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.您必须在参考手册中查找负责 RX 中断的位(为较新的控制器注册 FDCAN_IE)并将它们设置为 0 以禁用它们。 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:也可以使用句柄将寄存器完全设置为 0,但强烈建议使用位掩码来屏蔽所有不负责 RX 中断的位,尤其是保留位:

hcan1->Instance->IE = 0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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