正在尝试DKTM4C123G板的开发,仿照QS-LOGGER的例程写了一个读取各种传感器值的程序,但是读取MPU9150的数据的时候发现只能读取一次,之后就不再触发GPIOB的中断,请各位帮忙看一下。
//This is the file dealing with ADC
//Code with the help of the acquire.c file from qs_logger example program
//Li Shiyu 2015011421
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ints.h"
#include "inc/hw_gpio.h"
#include "inc/hw_nvic.h"
#include "driverlib/debug.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/i2c.h"
#include "grlib/grlib.h"
#include "utils/ustdlib.h"
#include "sensorlib/hw_mpu9150.h"
#include "sensorlib/hw_ak8975.h"
#include "sensorlib/i2cm_drv.h"
#include "sensorlib/ak8975.h"
#include "sensorlib/mpu9150.h"
#include "sensorlib/comp_dcm.h"
#include "driverlib/pin_map.h"
#include "acquire.h"
//Define the channel of different signal
#define CHAN_EXTTEMP ADC_CTL_CH20
#define CHAN_INTTEMP ADC_CTL_TS
//*****************************************************************************
//
// Define MPU9150 I2C Address.
//
//*****************************************************************************
#define MPU9150_I2C_ADDRESS 0x69
//
// Index values for sensor data
//
#define X 0
#define Y 1
#define Z 2
//
// Floating point data from SensorLib code
//
float g_pfAccel[3];
float g_pfGyro[3];
float g_pfMag[3];
//
// 16bit values post translation from floating point
//
int16_t g_i16Accel[3];
int16_t g_i16Gyro[3];
int16_t g_i16Mag[3];
tI2CMInstance g_sI2CInst;
tMPU9150 g_sMPU9150Inst;
volatile uint_fast8_t g_vui8I2CDoneFlag;
volatile uint_fast8_t g_vui8ErrorFlag;
volatile uint_fast8_t g_vui8DataFlag;
#define NUM_ADC_CHANNELS 5
uint32_t ADC_Value[NUM_ADC_CHANNELS];
long data[NUM_ADC_CHANNELS];
//*****************************************************************************
void
MPU9150AppCallback(void *pvCallbackData, uint_fast8_t ui8Status)
{
//
if(ui8Status == I2CM_STATUS_SUCCESS)
{
g_vui8I2CDoneFlag = 1;
}
//
// Store the most recent status in case it was an error condition
//
g_vui8ErrorFlag = ui8Status;
}
void
MPU9150AppI2CWait(char *pcFilename, uint_fast32_t ui32Line)
{
while((g_vui8I2CDoneFlag == 0) && (g_vui8ErrorFlag == 0))
{
}
if(g_vui8ErrorFlag)
{
//MPU9150AppErrorHandler(pcFilename, ui32Line);
//UARTprintf("ERROR in MPU9150AppErrorHandler\n");
}
//
// clear the data flag for next use.
//
g_vui8I2CDoneFlag = 0;
}
void IntGPIOb(void)
{
unsigned long ulStatus;
ulStatus = GPIOIntStatus(GPIO_PORTB_BASE, true);
//
// Clear all the pin interrupts that are set
//
GPIOIntClear(GPIO_PORTB_BASE, ulStatus);
if(ulStatus & GPIO_PIN_2)
{
//
// MPU9150 Data is ready for retrieval and processing.
//
MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
}
}
void MPU9150I2CIntHandler(void)
{
I2CMIntHandler(&g_sI2CInst);
}
//Initialize the ADC Channels
void InitAcquire()
{
//
// Enable the ADC peripherals and the associated GPIO port
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//
// Enable I2C & associated GPIO ports
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//
// Configure I2C Pins
//
MAP_GPIOPinConfigure(GPIO_PD0_I2C3SCL);
MAP_GPIOPinConfigure(GPIO_PD1_I2C3SDA);
MAP_GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
MAP_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);
MAP_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);
MAP_IntEnable(INT_GPIOB);
//
// Configure the pins to be used as analog inputs.
//
MAP_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);
MAP_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
//
// Initialize both ADC peripherals using sequencer 0 and processor trigger.
//
MAP_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, CHAN_EXTTEMP);
MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, CHAN_INTTEMP | ADC_CTL_END | ADC_CTL_IE);
ADCHardwareOversampleConfigure(ADC0_BASE, 4);
//
// Initialize I2C3 Peripheral
//
I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff,
MAP_SysCtlClockGet());
//
// Initialize the MPU9150 Driver.
//
MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
MPU9150AppCallback, &g_sMPU9150Inst);
//
// Wait for transaction to complete
//
MPU9150AppI2CWait(__FILE__, __LINE__);
//
// Write application specifice sensor configuration such as filter settings
// and sensor range settings.
//
g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
MPU9150AppCallback, &g_sMPU9150Inst);
//
// Wait for transaction to complete
//
MPU9150AppI2CWait(__FILE__, __LINE__);
//
// Configure the data ready interrupt pin output of the MPU9150.
//
g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
MPU9150_INT_PIN_CFG_LATCH_INT_EN ;
g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
&g_sMPU9150Inst);
//
// Wait for transaction to complete
//
MPU9150AppI2CWait(__FILE__, __LINE__);
//
// Initialize the DCM system. 50 hz sample rate.
// accel weight = .2, gyro weight = .8, mag weight = .2
//
//CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);
}
void AcquireStart()
{
MAP_ADCSequenceEnable(ADC0_BASE, 0);
ADCSequenceDataGet(ADC0_BASE, 0, ADC_Value);
MAP_ADCIntClear(ADC0_BASE, 0);
MAP_ADCIntEnable(ADC0_BASE, 0);
MAP_IntEnable(INT_GPIOB);
}
void AcquireRun()
{
ADCProcessorTrigger(ADC0_BASE, 0);
while(!ADCIntStatus(ADC0_BASE, 0, false));
ADCSequenceDataGet(ADC0_BASE, 0, ADC_Value);
DataProcess();
g_vui8I2CDoneFlag = 0;
}
void DataProcess()
{
data[EXTTEMP] = (1866300 – (200000 * ADC_Value[0]) / 273) / 1169;
data[INTTEMP] = 1475 – ((2250 * ADC_Value[1]) / 4095);
MPU9150DataAccelGetFloat(&g_sMPU9150Inst, &g_pfAccel[X], &g_pfAccel[Y],
&g_pfAccel[Z]);
MPU9150DataGyroGetFloat(&g_sMPU9150Inst, &g_pfGyro[X], &g_pfGyro[Y],
&g_pfGyro[Z]);
MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, &g_pfMag[X], &g_pfMag[Y],
&g_pfMag[Z]);
g_i16Accel[0]= (int16_t) ((g_pfAccel[0] /9.81f)*100.f);
g_i16Accel[1]= (int16_t) ((g_pfAccel[1] /9.81f)*100.f);
g_i16Accel[2]= (int16_t) ((g_pfAccel[2] /9.81f)*100.f);
data[ACCELX] = g_i16Accel[0];
data[ACCELY] = g_i16Accel[1];
data[ACCELZ] = g_i16Accel[2];
}
float getData(unsigned short data_type)
{
return data[data_type];
}
下面是在主程序中的调用:
int
main(void)
{
tContext sContext;
tRectangle sRect, clearRect;
unsigned char ButtonState;
unsigned char ButtonChanged;
long ext_temp, int_temp;
long accelx, accely, accelz;
int tick_count = 1; //Delay UART
char ext_temp_char[24];
char int_temp_char[24];
char x_axis_char[24];
char y_axis_char[24];
char z_axis_char[24];
state = 1; //Start with Temp Logger
pre_state = 1;
FPUEnable();
MAP_FPULazyStackingEnable();
MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
InitAcquire();
//
// Initialize the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);
UARTprintf("This is a plain Data Logger program.\n");
ROM_IntMasterEnable();
ButtonsInit();
//
// Initialize the display driver.
//
CFAL96x64x16Init();
//
// Initialize the graphics context.
//
GrContextInit(&sContext, &g_sCFAL96x64x16);
//
// Fill the top 24 rows of the screen with blue to create the banner.
//
sRect.i16XMin = 0;
sRect.i16YMin= 0;
sRect.i16XMax = GrContextDpyWidthGet(&sContext) – 1;
sRect.i16YMax = 23;
clearRect.i16XMax = GrContextDpyWidthGet(&sContext) – 1;
clearRect.i16XMin = 0;
clearRect.i16YMin = 24;
clearRect.i16YMax = GrContextDpyHeightGet(&sContext) – 1;
DrawBanner(sContext, sRect);
GrContextForegroundSet(&sContext, ClrWhite);
GrContextFontSet(&sContext, g_psFontCm12);
GrStringDrawCentered(&sContext, "Temp Logger", -1,
GrContextDpyWidthGet(&sContext) / 2, 10, 0);
AcquireStart();
while(1)
{
//Get the Data From ADC Sequence
AcquireRun();
(省略数据显示部分)
}
}
xyz549040622:
读取MPU9150的数据的时候发现只能读取一次,之后就不再触发GPIOB的中断,根据你的说明MPU9150的操作是没有问题的,至于中断的触发,你的设想是什么呢,一点注释和描述都没有,看着有点费劲的。