【问题标题】:Attiny204 Interrupt Flag Not Being GeneratedAttiny204 中断标志​​未生成
【发布时间】:2019-11-20 07:43:31
【问题描述】:

我正在尝试为 Attiny204 编写一个(相当)基本的软件,它在时钟输入拉高时处理中断。

当我在 Atmel Studio 的调试模拟器中运行代码并将时钟输入设置为高时,没有生成中断标志。当我手动生成中断标志时,中断确实会触发。

我尝试过使用不同的引脚,甚至是另一个端口。我似乎无法让模拟器产生中断标志。

以前我在模拟器中用过AtMega328P,代码等价,效果很好。

ISR(PORTA_PORT_vect)
{
  //In this function we must:
  //1. Shift all data up
  shiftUp();

  //2. Get new 8th bit
  bit8 = VPORTA.IN & (1 << 1);

  //3. Set Data Output Pin to bit0
  if(bit0 == 0)
    VPORTA.OUT &= ~(1 << 3);
  else
    VPORTA.OUT |= (1 << 3);

  //4. Calculate new dimValue and dimMilliseconds
  calcDim();
  calcDelay();
}

int main(void)
{
  initVariables();
  /*
    Below this, we must set the Data Direction (DD) of each pin we assigned.
  */

  //Below, set the ISC of the Zero Cross Pin and the Clock Pin to allow interrupts
  PORTA_PIN0CTRL |= 0b00000001; //Zero Cross
  //PORTA_PIN1CTRL = 0b00000000; //Data In
  //PORTA_PIN2CTRL = 0b00000000; //Data Next
  //PORTA_PIN3CTRL = 0b00000000; //Triac Control

  PORTB_PIN0CTRL |= 0b00000001; //Clock

  //VPORTB.INTFLAGS |= 0b00000001;

  //Set Port direction.
  VPORTA.DIR = 0x30;
  VPORTB.DIR = 0x00;

  /*
    Below this, we must enable interrupts.
  */
  sei();
  /* Replace with your application code */
  while (1) 
  {

  }
}

【问题讨论】:

  • 如果你想在上升沿获得 ISR,你应该将 PINCTRL 设置为 0x2 afaik。时钟输入是什么意思,PB0作为简单的GPIO?我认为您应该手动清除 ISR 标志。
  • 对不起,我只是将它标记为“时钟”,因为我正在做一个简单的同步数据传输。我会研究清除 ISR 位。

标签: interrupt avr atmelstudio isr


【解决方案1】:

您为什么要写信给VPORTAVPORTB? Tiny204 没有这个寄存器。 您在端口 A 的引脚 0 的两端启用中断(PIN0CTRL 位 0 已设置 = BOTHEDGES)并且您没有清除端口 A 的 ISR 中的中断标志。请查看数据表:

The interrupt request remains active until the interrupt flag is cleared. See the peripheral's INTFLAGSregister for details on how to clear interrupt flags.

【讨论】:

  • 你是对的,对此感到抱歉;我实际上正在使用同时具有端口 A 和端口 B 的 AtTiny214。我将不得不考虑清除 ISR 标志。谢谢!
  • 在尝试清除中断标志时,该标志永远不会触发,除非我将 ISC 标志设置为低电平感应。您认为可能是模拟器没有检测到上升沿,而只是将其视为固态?
  • 现在我在理解您的中断源方面遇到了一些麻烦。您是在尝试检测上升沿还是低电平中断?因为您为低级中断设置了标志,并且为边缘配置了中断。那是两个不同的中断。低电平不能触发边沿中断。
  • 再次抱歉,给您带来了困惑。在这一点上,我想要一个上升沿,但我只是想弄清楚为什么它不起作用。这就是我尝试使用低级中断的原因。
猜你喜欢
  • 2020-03-29
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多