|
功能:使用I2C中断连续发送17个字符
注意:在中断中需要先对FIFO进行写入,再清除中断标志位。若先清除中断标志位将多次进入中断程序。
参考源码如下:
//******************** I2C初始化 ***********************
void I2CMInit(void)
{
//Configure GPIO Alternate Function for ADC
GPIOAfr(GPIOB,BIT02,AF2); //Set PB02 as SCL(AF2)
GPIOPuPd(GPIOB,BIT02,PULLUP); //SCL Pull Up=PB02
GPIOOTDR(GPIOB,BIT02,1,0); //SCL Open Drain=PB02
GPIOAfr(GPIOA,BIT01,AF2); //Set PA01 as SDA(AF2)
GPIOPuPd(GPIOA,BIT01,PULLUP); //SDA Pull Up=PA01
GPIOOTDR(GPIOA,BIT01,1,0); //SDA Open Drain=PA01
//Configure I2C
pI2C0Ctrl->I2C_TX_TL = 0; //配置触发中断FIFO深度
pI2C0Ctrl->I2C_IDR = I2CINTR_TXEMPTY; //禁止FIFO空中断
I2CMConfig(I2C0,I2CRATE_SS); //standard speed
}
//******************** interrupt ***********************
void I2C0_IRQHandler(void) //irq 7
{
while(1)
{
pI2C0Ctrl->I2C_DATA_CMD = gDispBuf[DisRow][TX_Count];
TX_Count ++;
if(((TX_Count % 8)==0))
{
break;
}
else if(TX_Count > 16)
{
TX_Count = 0;
pI2C0Ctrl->I2C_IDR = I2CINTR_TXEMPTY;
break;
}
}
pI2C0Ctrl->I2C_ISC = pI2C0Ctrl ->I2C_RIS;
}
//******************** main ***********************
int main(void)
{
.......
I2CMInit()
.......
pI2C0Ctrl->I2C_IER = I2CINTR_TXEMPTY; // enable TX empty interrupt
while(1);
}
|
|