先上代码
#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也重装了,就出现这个问题,是设置的问题吗?
