F28377D使用硬件IIC读取MPU6050的值,无法进入中断,中断向量有注册,也有使能PIE8.1和CPU INT8,找不到原因,导致I2cMsgOut1.MsgStatus一直不会等于 I2C_MSGSTAT_INACTIVE,程序如下,求帮忙:
I2C初始化程序:
void I2CA_Init(void)
{
I2caRegs.I2CMDR.all = 0x0000;
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO32=0;
GpioCtrlRegs.GPBQSEL1.bit.GPIO32=3;
GpioCtrlRegs.GPBMUX1.bit.GPIO32=1;
GpioCtrlRegs.GPBPUD.bit.GPIO33=0;
GpioCtrlRegs.GPBQSEL1.bit.GPIO33=3;
GpioCtrlRegs.GPBMUX1.bit.GPIO33=1;
EDIS;
//复位FIFO寄存器
I2caRegs.I2CFFTX.all = 0x0000; // Disable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x0040; // Disable RXFIFO, clear RXFFINT,
// I2caRegs.I2CSAR.all =MPU60xx_Address; // Slave address - EEPROM control code
I2caRegs.I2CPSC.all = 6; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
I2caRegs.I2CIER.all = 0x24; // Enable SCD & ARDY __interrupts
I2caRegs.I2CMDR.all = 0x0020; // Take I2C out of reset
// Stop I2C when suspended
I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
return;
}
main函数for循环里的程序如下:
I2caRegs.I2CFFRX.bit.RXFFIENA=1; //允许I2C中断
if(I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)
{
DELAY_US(100000); //延时约700us,等待总线稳定
MPU_Initial(); //初始化MPU6050
} // end of write section
if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE)
{
// Check incoming message status.
if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)//无停止位发送
{
// MPU address setup portion
while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS) //读数据失败
{
}
CurrentMsgPtr = &I2cMsgIn1; //消息指针指向输入数据
I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY;
}
else if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_RESTART)
{
DELAY_US(100000);
for(i=0;i<14;i+=1)
{
databuffer[i]= I2cMsgIn1.MsgBuffer[i]; //get the Byte DATA from MPU
}
i=0;
while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)
{
}
//end of while;
// Update current message pointer and message status
CurrentMsgPtr = &I2cMsgIn1; //指定要读取的数据
I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY; //总线修改为读繁忙状态
}
} // end of read section
}
MPU_Init程序如下:
void MPU_Initial()
{
Uint16 Wnum,i,PTR,CONTENT;
Wnum=sizeof(Wparam)/2;
for(i=0;i<Wnum;i++)
{
PTR=Wparam[i][1];
CONTENT=Wparam[i][0];
WriteData(&I2cMsgOut1,&PTR,CONTENT,1);
}
}
WriteData程序如下:
void WriteData(struct I2CMSG *msg,Uint16 *MsgBuffer,Uint16 MemoryAdd,Uint16 NumOfBytes)
{
Uint16 i,Error;
for(i = 0; i < I2C_RNUMBYTES; i++)
{
msg->MsgBuffer[i] = MsgBuffer[i]; //将数据传送至结构体的附加数组
}
//msg->MemoryHighAddr = MemoryAdd >> 8;
msg->MemoryLowAddr = MemoryAdd & 0xff; //取低8位
msg->NumOfBytes = NumOfBytes; //写几个字节
Error = I2CA_WriteData(&I2cMsgOut1); //调用I2CA_WriteData
if (Error == I2C_SUCCESS)
{
CurrentMsgPtr = &I2cMsgOut1; //需传送的数据指针指向I2cMsgOut1
I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;
}
while(I2cMsgOut1.MsgStatus != I2C_MSGSTAT_INACTIVE);
DELAY_US(1000);
}
程序会一直在Write_Data最后的while里面循环,出不来,没进入中断。