打印

ARM CotexM4核 I2C不能进入中断的问题

[复制链接]
4623|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lm868189|  楼主 | 2012-11-10 10:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TE, ARM, I2c, ST, IO
各位高手,小弟最近碰到这样一个问题,在完成I2C配置,通过主机模式向外设发送数据,发现不能进入中断,望高手能指点一二:
首先上下代码:
首先是中断服务程序:
void I2C0MasterIntHandler(void)
{

unsigned long I2CIntFlag;
//ROM_GPIOPinWrite(GPIO_PORTG_BASE,GPIO_PIN_2,GPIO_PIN_2); //点亮LED灯,进入中断标志
I2CIntFlag = I2CMasterIntStatusEx(I2C0_MASTER_BASE,false);//读取I2C中断信号
if(I2CIntFlag == I2C_MASTER_INT_DATA)
{
  g_ulFlagData = 1;
  
           
}
else if(I2CIntFlag == I2C_MASTER_INT_TIMEOUT)
{
  g_ulFlagTimeOut = 1;
  
}
else
{
}
I2CMasterIntClear(I2C0_MASTER_BASE);
}

int
main(void)
{
//************************************************************************
//variable for I2C
//************************************************************************
unsigned char ulDataCharTx = 'I';
unsigned long ulDataCharRx;
//配置时钟
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);
//************************************************************************
//Initialization for Delay
//************************************************************************
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 2);
ROM_SysTickEnable();
//************************************************************************
//Initialization for I2C
//************************************************************************
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  //IO使能
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);   //功能使能
   
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);     //管脚配置
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);//管脚类型
  
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);//100K Rate and Set Master module
I2CIntRegister(I2C0_MASTER_BASE,I2C0MasterIntHandler);//该函数调用 IntEnalbe(INT_I2C0);
I2CMasterIntEnable(I2C0_MASTER_BASE);        //Master 模式中断使能
  
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, 0x00, false); //这是地址+读写方向
I2CMasterDataPut(I2C0_MASTER_BASE, ulDataCharTx);
//在此,小弟想问中断会在哪里触发?文档是这么说的:
//The I2C master module generates an interrupt when a transaction completes (either transmit or
//receive), when arbitration is lost, or when an error occurs during a transaction. To enable the I2C
//master interrupt, software must set the IM bit in the I2C Master Interrupt Mask (I2CMIMR) register.
//When an interrupt condition is met, software must check the ERROR and ARBLST bits in the I2C
//Master Control/Status (I2CMCS) register to verify that an error didn't occur during the last transaction
//and to ensure that arbitration has not been lost. An error condition is asserted if the last transaction
//wasn't acknowledged by the slave. If an error is not detected and the master has not lost arbitration,
//the application can proceed with the transfer. The interrupt is cleared by writing a 1 to the IC bit in
//the I2C Master Interrupt Clear (I2CMICR) register.
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND); //该函数指定这次发送一个字节数据(包含开始和结束位)
while(!g_ulFlagData) //这里是等待中断触发,不知道放在这里对不对 ?//不知道在哪里等到中断被触发?
{
}
g_ulFlagData = 0;
程序会在这里无限死循环,不能进入中断,求高手指点,本人在线等..

相关帖子

沙发
阿南| | 2012-11-10 11:11 | 只看该作者
先要查一下处理器的中断是否已经打开,和是否已经产生中断挂起标志
然后查ARM核的IRQ是否打开
再查中断向量表是否正常

使用特权

评论回复
板凳
ykkaimm| | 2012-11-10 13:58 | 只看该作者
:lol

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

0

粉丝