//***************************************************************************** // // Called by the NVIC as a SysTick interrupt, which is used to generate the // sample interval // //***************************************************************************** void SysTickIntHandler() { GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1); BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00); }
//***************************************************************************** // // Called by the NVIC as a SysTick interrupt, which is used to generate the // sample interval // //***************************************************************************** void SysTickIntHandler() { // // Blink the blue LED to indicate data read from BMP180. // MAP_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_4, ((GPIOPinRead(GPIO_PORTQ_BASE, GPIO_PIN_4)) ^ GPIO_PIN_4)); BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); }
void Timer1IntHandler(void) { TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); if(GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_0)) { GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0, PIN_LOW); } else { GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0, PIN_HIGH); } switch(sensorTurn) { case 0: { TMP006DataRead(&g_sTMP006Inst, TMP006AppCallback, &g_sTMP006Inst); TimerDisable(TIMER1_BASE, TIMER_A); break; } case 1: { BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); TimerDisable(TIMER1_BASE, TIMER_A); break; } case 2: { ISL29023DataRead(&g_sISL29023Inst, ISL29023AppCallback, &g_sISL29023Inst); TimerDisable(TIMER1_BASE, TIMER_A); break; } case 3: { SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); TimerDisable(TIMER1_BASE, TIMER_A); break; } case 4: { MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst); TimerDisable(TIMER1_BASE, TIMER_A); break; } } }
//***************************************************************************** // // Called by the NVIC as a SysTick interrupt, which is used to generate the // sample interval // //***************************************************************************** void SysTickIntHandler() { unsigned char sw_pin_status; // get pressure data BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); // SW debounce sw_pin_status = ~((unsigned char)(MAP_GPIOPinRead(SW_BASE, (SW1|SW2)))); if ( (sw_pin_status & SW1) != (sw_state & SW1) ){ sw1_debounce_count++; if (sw1_debounce_count >= SW_DEBOUNCE_CNT){ sw_state = (sw_state & ~SW1) | (sw_pin_status & SW1); sw1_debounce_count = 0; } }else{ sw1_debounce_count = 0; } if ( (sw_pin_status & SW2) != (sw_state & SW2) ){ sw2_debounce_count++; if (sw2_debounce_count >= SW_DEBOUNCE_CNT){ sw_state = (sw_state & ~SW2) | (sw_pin_status & SW2); sw2_debounce_count = 0; } }else{ sw2_debounce_count = 0; } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; // // Setup the system clock to run at 40 MHz from PLL with crystal reference // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // Set the color to a white approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x8000; // // Initialize RGB driver. Use a default intensity and blink rate. // RGBInit(0); RGBColorSet(g_pui32Colors); RGBIntensitySet(0.5f); RGBEnable(); // // The I2C3 peripheral must be enabled before use. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C3 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // ROM_GPIOPinConfigure(GPIO_PD0_I2C3SCL); ROM_GPIOPinConfigure(GPIO_PD1_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Initialize the GPIO for the LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize the I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ROM_SysCtlClockGet()); // // Initialize the BMP180. // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 Hz. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / (10 * 3)); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // After all the init and config we start blink the LED // RGBBlinkRateSet(1.0f); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision. // UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision. // UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision. // UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / (10 * 3)); }//while end }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fTemperature, fPressure, fAltitude; int32_t i32IntegerPart; int32_t i32FractionPart; tContext sContext; uint32_t ui32SysClock; char pcBuf[15]; // // Setup the system clock to run at 40 Mhz from PLL with crystal reference // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 40000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "bmp180"); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Enable UART0 // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, ui32SysClock); // // Print the welcome message to the terminal. // UARTprintf("\033[2JBMP180 Example\n"); // // The I2C3 peripheral must be enabled before use. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); // // Configure the pin muxing for I2C3 functions on port G4 and G5. // This step is not necessary if your part does not support pin muxing. // MAP_GPIOPinConfigure(GPIO_PG4_I2C3SCL); MAP_GPIOPinConfigure(GPIO_PG5_I2C3SDA); // // Select the I2C function for these pins. This function will also // configure the GPIO pins pins for I2C operation, setting them to // open-drain operation with weak pull-ups. Consult the data sheet // to see which functions are allocated per pin. // MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_5); // // Enable interrupts to the processor. // MAP_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ui32SysClock); // // Initialize the BMP180 // BMP180Init(&g_sBMP180Inst, &g_sI2CInst, BMP180_I2C_ADDRESS, BMP180AppCallback, &g_sBMP180Inst); // // Wait for initialization callback to indicate reset request is complete. // while(g_vui8DataFlag == 0) { // // Wait for I2C Transactions to complete. // } // // Reset the data ready flag // g_vui8DataFlag = 0; // // Enable the system ticks at 10 hz. // MAP_SysTickPeriodSet(ui32SysClock / (10 * 3)); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Configure PQ4 to control the blue LED. // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); // // Print temperature, pressure and altitude labels once on the LCD. // GrStringDraw(&sContext, "Temperature", 11, ((GrContextDpyWidthGet(&sContext) / 2) - 96), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); GrStringDraw(&sContext, "Pressure", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 63), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); GrStringDraw(&sContext, "Altitude", 8, ((GrContextDpyWidthGet(&sContext) / 2) - 59), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); // // Begin the data collection and printing. Loop Forever. // while(1) { // // Read the data from the BMP180 over I2C. This command starts a // temperature measurement. Then polls until temperature is ready. // Then automatically starts a pressure measurement and polls for that // to complete. When both measurement are complete and in the local // buffer then the application callback is called from the I2C // interrupt context. Polling is done on I2C interrupts allowing // processor to continue doing other tasks as needed. // BMP180DataRead(&g_sBMP180Inst, BMP180AppCallback, &g_sBMP180Inst); while(g_vui8DataFlag == 0) { // // Wait for the new data set to be available. // } // // Reset the data ready flag. // g_vui8DataFlag = 0; // // Get a local copy of the latest temperature data in float format. // BMP180DataTemperatureGetFloat(&g_sBMP180Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart =(int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print temperature with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%03d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) - 24, 1); UARTprintf("Temperature %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Get a local copy of the latest air pressure data in float format. // BMP180DataPressureGetFloat(&g_sBMP180Inst, &fPressure); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fPressure; i32FractionPart =(int32_t) (fPressure * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print Pressure with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, -1, ((GrContextDpyWidthGet(&sContext) / 2) + 16), (GrContextDpyHeightGet(&sContext) - 32) / 2, 1); UARTprintf("Pressure %3d.%03d\t\t", i32IntegerPart, i32FractionPart); // // Calculate the altitude. // fAltitude = 44330.0f * (1.0f - powf(fPressure / 101325.0f, 1.0f / 5.255f)); // // Convert the floats to an integer part and fraction part for easy // print. // i32IntegerPart = (int32_t) fAltitude; i32FractionPart =(int32_t) (fAltitude * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print altitude with three digits of decimal precision to LCD and // terminal. // usnprintf(pcBuf, sizeof(pcBuf), "%3d.%03d ", i32IntegerPart, i32FractionPart); GrStringDraw(&sContext, pcBuf, 8, ((GrContextDpyWidthGet(&sContext) / 2) + 16), ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24, 1); UARTprintf("Altitude %3d.%03d", i32IntegerPart, i32FractionPart); // // Print new line. // UARTprintf("\n"); // // Delay to keep printing speed reasonable. About 100 milliseconds. // MAP_SysCtlDelay(ui32SysClock / (10 * 3)); } }
void bmp085DataRead(int index){ BMP180DataRead(&bmpAppInstance[index], bmp085AppCallback, &bmpAppInstance[index]); while(bmp085_dataFlag == 0); bmp085_dataFlag = 0; BMP180DataTemperatureGetFloat(&bmpAppInstance[index], &bmpTemperature); BMP180DataPressureGetFloat(&bmpAppInstance[index], &bmpPressure); }