ATMEL SAMR21 按键中断程序

2019-03-24 20:13发布

最近在用ATMEL的板子,但是程序写好后,中断一直产生不了,求助各位大神解决这个问题,曾经尝试过检测标志位,但是检测不到,实在查不出问题到底出在哪。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
zjw19921104
1楼-- · 2019-03-25 02:50
不好意思,程序在这

#include "sam.h"
#include "samR21G18A.h"
#define _BV(bit) (1 << (bit))
#define SW0 PORT_PA28



void EIC_Handler(void)
{
REG_EIC_INTFLAG &= ~_BV(8);        // clear interrupt flag
REG_PORT_OUTTGL0 |= _BV(19);        // toggle led. pp.391
}       

int main(void)
{       

REG_PORT_DIR0 |= _BV(19);        // configure PA19(LED0) as output
REG_PORT_OUT0 |= _BV(19);        // disable the LED0, set to high voltage (1)
REG_PORT_OUT0 &= ~_BV(19);        // enable the LED0, set to low voltage (0)
REG_PORT_OUT0 |= _BV(19);        // disable the LED0       

// PORT MUX configuration

REG_PORT_DIRCLR0 &= _BV(28);        // configure PA28 as input
REG_PORT_WRCONFIG0 = 0xCC471000;
//REG_PORT_WRCONFIG0 = PORT_WRCONFIG_PMUXEN |  PORT_WRCONFIG_PULLEN | PORT_WRCONFIG_INEN | PORT_WRCONFIG_PMUX(MUX_PA28A_EIC_EXTINT8) | PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_WRPINCFG | _BV(12) | PORT_WRCONFIG_HWSEL;

//PORT->Group[0].WRCONFIG.reg =( PORT_WRCONFIG_MASK & (PORT_WRCONFIG_PMUXEN |  PORT_WRCONFIG_PULLEN | PORT_WRCONFIG_INEN | PORT_WRCONFIG_PMUX(MUX_PA28A_EIC_EXTINT8) | PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_WRPINCFG | _BV(12) | PORT_WRCONFIG_HWSEL ));      
                          
REG_PORT_OUT0 |= _BV(28);        // disable the PA28, set to high voltage (1)
//PORT->Group[0].PMUX[13].reg = 0x0;
REG_PORT_PMUX0_13 = PORT_PMUX_PMUXE_A;
PORT->Group[0].PINCFG[28].reg = PORT_PINCFG_PMUXEN | PORT_PINCFG_PULLEN;


// power manager
REG_PM_APBBMASK |= _BV(3);        // enable CLK_PORT_APB, pp. 333        

// Generic Clock controller
REG_EIC_CTRL &= ~_BV(1);        // disable EIC
while( (REG_EIC_STATUS & (_BV(7))) == 1 );        // bit 7: check Synchronization Busy Status. pp.340

REG_EIC_CTRL |= _BV(0);        // software reset EIC
while( (REG_EIC_STATUS & (_BV(7))) == 1 );        // bit 7: check Synchronization Busy Status. pp.340

REG_PM_APBAMASK |= _BV(6);        // enable CLK_EIC_APB, pp. 333       

// the default GCLK0 (GCLK_MAIN) is used for IO
REG_GCLK_GENDIV = 0x100;        // bit 31-0: 0000 0000 0000 0000 0000 0001 0000 0000, do a 32-bit write with all configurations and the ID. pp.109
while( (REG_GCLK_STATUS & (_BV(7))) == 1 );        // bit 7: check Synchronization Busy Status. pp.100

// Bit 21: Enable Run in Standby, Bit 20: Disable Divide Selection, Bit 19: Disable Output, Bit 18: clear GCLK_IO to zero
// Bit 17: Improve Duty Cycle, Bit 16: Enable Generic Clock Generator, Bit 12-8: Select OSC8M, Bit 3-0: Select GCLKGEN0
REG_GCLK_GENCTRL = 0x00230600;        // bit 31-0: 0000 0000 0010 0011 0000 0110 0000 0000. do a 32-bit write with all configurations and the ID. pp.105
while( (REG_GCLK_STATUS & (_BV(7))) == 1 );        // bit 7: check Synchronization Busy Status. pp.100

// bit 15: Disable Lock Write, Bit 14: Enable Clock, Bit 11-8: Choose GCLKGEN5, Bit 5-0: Choose GCLK_EIC
REG_GCLK_CLKCTRL = 0x4005;        // bit 15-0: 0100 0000 0000 0101. do a 16-bit write with all configurations and the ID. pp.101
       
// EIC configuration registers
while (EIC->CTRL.bit.SWRST | EIC->STATUS.bit.SYNCBUSY);

//REG_EIC_CTRL |= _BV(1);        // enable EIC

REG_EIC_CONFIG2 |= EIC_CONFIG_FILTEN4 | EIC_CONFIG_SENSE4_BOTH;       
//REG_EIC_CONFIG2 |= _BV(19);        // bit 19 FILTEN28: enable filter of IO 28 pp. 348
//REG_EIC_CONFIG2 = (0x1 << 16);        // bit 16 - 18; Input Sense 28 Configuration -- Rising-edge detection pp. 348
//REG_EIC_CONFIG2 = (0x3 << 16);        // bit 16 - 18; Input Sense 4/pa28 Configuration -- both-edge detection pp. 348

// disable interrupt and clear interrupt flag
REG_EIC_INTENCLR |= _BV(8);        // disable interrupt 8 (EXTINT8)
REG_EIC_INTFLAG &= ~_BV(8);        // clear interrupt flag

REG_EIC_INTENSET |= EIC_INTENSET_EXTINT8;       
//REG_EIC_INTENSET |= _BV(8);        // enable interrupt 8 (EXTINT8)       


REG_EIC_CTRL |= EIC_CTRL_ENABLE;

NVIC_EnableIRQ(EIC_IRQn);



while( (REG_EIC_STATUS & (_BV(7))) == 1 );        // bit 7: check Synchronization Busy Status. pp.340

while(1)
{       

/*if ((REG_EIC_INTFLAG & (_BV(8))) == 1)
{
REG_EIC_INTFLAG &= ~_BV(8);        // clear interrupt flag
REG_PORT_OUTTGL0 |= _BV(19);        // toggle led. pp.391

}*/

}
}
dcexpert
2楼-- · 2019-03-25 06:21
试试ASF,比较一下代码的差异
zjw19921104
3楼-- · 2019-03-25 09:21
 精彩回答 2  元偷偷看……

一周热门 更多>