/*************************************************************************************** ** ÎļþÃû³Æ: ** ¹¦ÄÜÃèÊö: ** ×÷ÕߣºYY ** ʱ¼ä£º2014Äê Ô ÈÕ ****************************************************************************************/
/*----Includes--------------------------------------------------------------------------*/ #include "TM4C123_conf.h" #include "TM4C123_lib.h"
/*----Function declaration------------------------------------------------------------------------*/ #define ulong unsigned long #define uchar unsigned char #define STATE_IDLE 0 #define STATE_WRITE_ONE 1 static int I2C_state = STATE_IDLE; /*************************************************************************************** ** º¯ÊýÃû³Æ: ** ¹¦ÄÜÃèÊö£º ****************************************************************************************/
void Delays (ulong dly) { int i,j; for (; dly>0; dly--) { for (i=0; i<150; i++) for (j=0; j<255; j++); } } /*************************************************************************************** ** º¯ÊýÃû³Æ: ** ¹¦ÄÜÃèÊö£º ****************************************************************************************/ int I2C1_Init(ulong speed,uchar priority) { if((speed==400000)||(speed==100000)) { SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_6|GPIO_PIN_7); if(speed==400000) I2CMasterInit(I2C1_MASTER_BASE,true); else I2CMasterInit(I2C1_MASTER_BASE,false); IntPrioritySet(INT_I2C1,(priority << 2)); I2CMasterEnable(I2C1_MASTER_BASE); I2CMasterIntEnable(I2C1_MASTER_BASE); IntEnable(INT_I2C1); IntMasterEnable(); return(true); } else return(false); } /*************************************************************************************** ** º¯ÊýÃû³Æ: ** ¹¦ÄÜÃèÊö£º ****************************************************************************************/ int I2C1_SendByte(uchar slave,uchar c) { uchar *p; slave >>= 1; p = &c; I2C_state = STATE_WRITE_ONE; I2CMasterSlaveAddrSet(I2C1_MASTER_BASE,slave,false); I2CMasterDataPut(I2C1_MASTER_BASE,*p); I2CMasterControl(I2C1_MASTER_BASE,I2C_MASTER_CMD_SINGLE_SEND); while(I2C_state != STATE_IDLE); if(I2CMasterBusy(I2C1_MASTER_BASE))return(false); else return(true); } /*************************************************************************************** ** º¯ÊýÃû³Æ: ** ¹¦ÄÜÃèÊö£º ****************************************************************************************/ int I2C1_IRcvByte(uchar slave, uchar *c) { uchar temp; slave >>= 1; I2C_state = STATE_IDLE; I2CMasterSlaveAddrSet(I2C1_MASTER_BASE,slave,true); I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);// Æô¶¯µ¥´Î¶ÁÈ¡ temp=I2CMasterDataGet(I2C1_MASTER_BASE); c = &temp; while(I2C_state != STATE_IDLE); if(I2CMasterBusy(I2C1_MASTER_BASE))return(false); else return(true); } /*************************************************************************************** ** º¯ÊýÃû³Æ: ** ¹¦ÄÜÃèÊö£º ****************************************************************************************/ void I2C1_INT(void) { GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_7,GPIO_PIN_7); I2CMasterIntClear(I2C1_MASTER_BASE); I2C_state = STATE_IDLE; } /*----end of file----------------------------------------------------------------------*/
为什么不能进入中断呢?