This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

F28377D使用硬件IIC读取MPU6050值时无法进入中断



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里面循环,出不来,没进入中断。

  • 中断程序如下:

    interrupt void i2c_int1a_isr(void)
    {
    Uint16 IntSource, i;
    // ScibRegs.SCIFFTX.bit.TXFFIENA=0;
    // Read interrupt source
    IntSource = I2caRegs.I2CISRC.all;

    // Interrupt source = stop condition detected
    if(IntSource == I2C_SCD_ISRC)
    {
    // If completed message was writing data, reset msg to inactive state
    if (CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_WRITE_BUSY)
    {
    CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_INACTIVE; //将信息状态修改为繁忙
    }
    else
    {
    // If a message receives a NACK during the address setup portion of the
    // RTC read, the code further below included in the register access ready
    // interrupt source code will generate a stop condition. After the stop
    // condition is received (here), set the message status to try again.
    // User may want to limit the number of retries before generating an error.
    if(CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY)
    {
    CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_SEND_NOSTOP;
    }
    // If completed message was reading RTC data, reset msg to inactive state
    // and read data from FIFO.
    else if (CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_READ_BUSY)
    {
    CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_SEND_NOSTOP;//I2C_MSGSTAT_INACTIVE;
    for(i=0; i < CurrentMsgPtr->NumOfBytes; i++) //read 14data from MPU and save them in MsgBuffer
    {
    CurrentMsgPtr->MsgBuffer[i] = I2caRegs.I2CDRR.all; //连续读取FIFO寄存器的数据
    }
    }
    // ScibRegs.SCIFFTX.bit.TXFFIENA=1;
    }
    } // end of stop condition detected
    // Interrupt source = Register Access Ready
    // This interrupt is used to determine when the RTC address setup portion of the
    // read data communication is complete. Since no stop bit is commanded, this flag
    // tells us when the message has been sent instead of the SCD flag. If a NACK is
    // received, clear the NACK bit and command a stop. Otherwise, move on to the read
    // data portion of the communication.
    else if(IntSource == I2C_ARDY_ISRC)
    {
    if(I2caRegs.I2CSTR.bit.NACK == 1)
    {
    I2caRegs.I2CMDR.bit.STP = 1;
    I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;
    }
    else if(CurrentMsgPtr->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP_BUSY)
    {
    CurrentMsgPtr->MsgStatus = I2C_MSGSTAT_RESTART; //复位消息状态
    }
    } // end of register access ready

    else
    {
    // Generate some error due to invalid interrupt source
    asm(" ESTOP0"); //有错误的话,停止仿真,
    }

    // Enable future I2C (PIE Group 8) interrupts

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
    }

  • 有没有人用过的来探讨一下啊

  • 您好,我现在用F28335调试出现了和您同样的问题,请问您最后怎么解决的呢?

    谢谢