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.

调试TM4C123GH6PZ一进入子程序就转到错误中断FaultISR



先上代码

#include <stdint.h>

#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverLib/gpio.h"
#include "driverLib/sysctl.h"
#include "driverLib/I2C.h"
#include "inc/hw_I2C.h"
#include "math.h"
#include "driverLib/pin_map.h"

//#define

float tempture=0.;
float altiture=0.;

void wenhai0(void);

int main(void)
{
SysCtlClockSet( SYSCTL_SYSDIV_20 | SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ ); 
SysCtlDelay(1500);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE,GPIO_PIN_3);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
I2CMasterEnable(I2C0_BASE); 
I2CSlaveIntClear(I2C0_BASE);
while(1)
{
wenhai0();
}

}

void wenhai0(void)
{

unsigned char tematt[4]={0x00,0x00,0x00,0x00};
int32_t temp;
int32_t press;

I2CMasterSlaveAddrSet(I2C0_BASE, 0x78, true);
I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);//主机突发接收起始
while(I2CMasterBusy(I2C0_BASE)); // 等待主机传输
tematt[0]=I2CMasterDataGet(I2C0_BASE);

I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);//主机突发接收继续 
while(I2CMasterBusy(I2C0_BASE));
tematt[1]=I2CMasterDataGet(I2C0_BASE);

I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);//主机突发接收继续
while(I2CMasterBusy(I2C0_BASE));
tematt[2]=I2CMasterDataGet(I2C0_BASE);

I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_BASE));
tematt[3]=I2CMasterDataGet(I2C0_BASE);

press=(tematt[0]<<8)+tematt[1];
temp=(tematt[2]<<8)+tematt[3];


//tempture=(temp-11370)*0.00238;
//altiture=(101300-press*5)*0.0787;
}

在重装了一次keil之后,不知道是哪里设置的问题,已进入i2c通讯的子程序就跳到FaultISR中,后来发现屏蔽子函数中最后面的两句就可以了,这是什么原因呢?

之前运行的没什么问题,最近电脑出了点小毛病重装了,keil也重装了,就出现这个问题,是设置的问题吗?

  • 是不是没有开启浮点型的运算引起的呢?

  • 使能TI M4浮点运算单元。

    //tempture=(temp-11370)*0.00238;

    //altiture=(101300-press*5)*0.0787;

    temp press 是int32_t 

    建议此值赋给float 变量先,然后用浮点变量参与运算。

    feng liu10 说:

    先上代码

    #include <stdint.h>

    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_sysctl.h"
    #include "driverLib/gpio.h"
    #include "driverLib/sysctl.h"
    #include "driverLib/I2C.h"
    #include "inc/hw_I2C.h"
    #include "math.h"
    #include "driverLib/pin_map.h"

    //#define

    float tempture=0.;
    float altiture=0.;

    void wenhai0(void);

    int main(void)
    {
    SysCtlClockSet( SYSCTL_SYSDIV_20 | SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ ); 
    SysCtlDelay(1500);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2C(GPIO_PORTB_BASE,GPIO_PIN_3);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
    I2CMasterEnable(I2C0_BASE); 
    I2CSlaveIntClear(I2C0_BASE);
    while(1)
    {
    wenhai0();
    }

    }

    void wenhai0(void)
    {

    unsigned char tematt[4]={0x00,0x00,0x00,0x00};
    int32_t temp;
    int32_t press;

    I2CMasterSlaveAddrSet(I2C0_BASE, 0x78, true);
    I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);//主机突发接收起始
    while(I2CMasterBusy(I2C0_BASE)); // 等待主机传输
    tematt[0]=I2CMasterDataGet(I2C0_BASE);

    I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);//主机突发接收继续 
    while(I2CMasterBusy(I2C0_BASE));
    tematt[1]=I2CMasterDataGet(I2C0_BASE);

    I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);//主机突发接收继续
    while(I2CMasterBusy(I2C0_BASE));
    tematt[2]=I2CMasterDataGet(I2C0_BASE);

    I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
    while(I2CMasterBusy(I2C0_BASE));
    tematt[3]=I2CMasterDataGet(I2C0_BASE);

    press=(tematt[0]<<8)+tematt[1];
    temp=(tematt[2]<<8)+tematt[3];


    //tempture=(temp-11370)*0.00238;
    //altiture=(101300-press*5)*0.0787;
    }

    在重装了一次keil之后,不知道是哪里设置的问题,已进入i2c通讯的子程序就跳到FaultISR中,后来发现屏蔽子函数中最后面的两句就可以了,这是什么原因呢?

    之前运行的没什么问题,最近电脑出了点小毛病重装了,keil也重装了,就出现这个问题,是设置的问题吗?

  • 嗯,是的,在设置里勾选了使用浮点单元,但是代码里没有加,后来查了下,要使用两个宏函数,一个是FPUEnable,一个是FPULazyStackingEnable,后一个函数的作用是什么呢

  • 后一个函数是开启浮点上下文的怠惰状态保存。