各位高手,小弟最近碰到这样一个问题,在完成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;
程序会在这里无限死循环,不能进入中断,求高手指点,本人在线等.. |