void TMP006AppCallback(void *pvCallbackData, uint_fast8_t ui8Status) { float fAmbient, fObject; unsigned char tempString[20]={0}; // // If the transaction succeeded set the data flag to indicate to // application that this transaction is complete and data may be ready. // if(ui8Status == I2CM_STATUS_SUCCESS&&sensorTurn==0) { // // Get a local copy of the latest data in float format. // TMP006DataTemperatureGetFloat(&g_sTMP006Inst, &fAmbient, &fObject); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // TMP006_i32IntegerPart1 = (int32_t)fAmbient; TMP006_i32FractionPart1 = (int32_t)(fAmbient * 1000.0f); TMP006_i32FractionPart1 = TMP006_i32FractionPart1 - (TMP006_i32IntegerPart1 * 1000); if(TMP006_i32FractionPart1 < 0) { TMP006_i32FractionPart1 *= -1; } //sprintf(tempString,"Ambient %3d.%03d\t", TMP006_i32IntegerPart1, TMP006_i32FractionPart1); //CLI_Write(tempString); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // TMP006_i32IntegerPart2 = (int32_t)fObject; TMP006_i32FractionPart2 = (int32_t)(fObject * 1000.0f); TMP006_i32FractionPart2= TMP006_i32FractionPart2 - (TMP006_i32IntegerPart2 * 1000); if(TMP006_i32FractionPart2 < 0) { TMP006_i32FractionPart2 *= -1; } //sprintf(tempString,"Object %3d.%03d\n\r", TMP006_i32IntegerPart2, TMP006_i32FractionPart2); //CLI_Write(tempString); sensorTurn=(sensorTurn+1)%NumberOfSensor; //sensorTurn=4; TimerEnable(TIMER1_BASE, TIMER_A); } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fAmbient, fObject; int_fast32_t i32IntegerPart; int_fast32_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); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2J\033[1;1HTMP006 Example\n"); // // Setup the color of the RGB LED. // g_pui32Colors[RED] = 0; g_pui32Colors[BLUE] = 0xFFFF; g_pui32Colors[GREEN] = 0; // // Initialize the RGB Driver and start RGB blink operation. // 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); // // Configure and Enable the GPIO interrupt. Used for DRDY from the TMP006 // ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0); GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0); ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOE); // // Keep only some parts of the systems running while in sleep mode. // GPIOE is for the TMP006 data ready interrupt. // UART0 is the virtual serial port // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver // I2C3 is the I2C interface to the TMP006 // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C3); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, SysCtlClockGet()); // // Initialize the TMP006 // TMP006Init(&g_sTMP006Inst, &g_sI2CInst, TMP006_I2C_ADDRESS, TMP006AppCallback, &g_sTMP006Inst); // // Put the processor to sleep while we wait for the I2C driver to // indicate that the transaction is complete. // while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0)) { ROM_SysCtlSleep(); } // // If an error occurred call the error handler immediately. // if(g_vui8ErrorFlag) { TMP006AppErrorHandler(__FILE__, __LINE__); } // // clear the data flag for next use. // g_vui8DataFlag = 0; // // Delay for 10 milliseconds for TMP006 reset to complete. // Not explicitly required. Datasheet does not say how long a reset takes. // ROM_SysCtlDelay(ROM_SysCtlClockGet() / (100 * 3)); // // Enable the DRDY pin indication that a conversion is in progress. // TMP006ReadModifyWrite(&g_sTMP006Inst, TMP006_O_CONFIG, ~TMP006_CONFIG_EN_DRDY_PIN_M, TMP006_CONFIG_EN_DRDY_PIN, TMP006AppCallback, &g_sTMP006Inst); // // Wait for the DRDY enable I2C transaction to complete. // while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0)) { ROM_SysCtlSleep(); } // // If an error occurred call the error handler immediately. // if(g_vui8ErrorFlag) { TMP006AppErrorHandler(__FILE__, __LINE__); } // // clear the data flag for next use. // g_vui8DataFlag = 0; // // Last thing before the loop start blinking to show we got this far and // the tmp006 is setup and ready for auto measure // RGBBlinkRateSet(1.0f); // // Loop Forever // while(1) { // // Put the processor to sleep while we wait for the TMP006 to // signal that data is ready. Also continue to sleep while I2C // transactions get the raw data from the TMP006 // while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0)) { ROM_SysCtlSleep(); } // // If an error occurred call the error handler immediately. // if(g_vui8ErrorFlag) { TMP006AppErrorHandler(__FILE__, __LINE__); } // // Reset the flag // g_vui8DataFlag = 0; // // Get a local copy of the latest data in float format. // TMP006DataTemperatureGetFloat(&g_sTMP006Inst, &fAmbient, &fObject); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // i32IntegerPart = (int32_t)fAmbient; i32FractionPart = (int32_t)(fAmbient * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } UARTprintf("Ambient %3d.%03d\t", i32IntegerPart, i32FractionPart); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // i32IntegerPart = (int32_t)fObject; i32FractionPart = (int32_t)(fObject * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } UARTprintf("Object %3d.%03d\n", i32IntegerPart, i32FractionPart); } }
void printTemperatureData(void){ float fAmbient, fObject; int_fast32_t i32IntegerPart; int_fast32_t i32FractionPart; uint32_t ui32LEDState; // Toggle LED 3 on each time through the loop. // //LEDRead(&ui32LEDState); LEDWrite(CLP_D3, (ui32LEDState ^ CLP_D3)); // // Put the processor to sleep while we wait for the TMP006 to // signal that data is ready. Also continue to sleep while I2C // transactions get the raw data from the TMP006 // while((g_vui8DataFlag == 0) && (g_vui8ErrorFlag == 0)) { ROM_SysCtlSleep(); } // // If an error occurred call the error handler immediately. // if(g_vui8ErrorFlag) { TMP006AppErrorHandler(__FILE__, __LINE__); } // // Reset the flag // g_vui8DataFlag = 0; // // Get a local copy of the latest data in float format. // TMP006DataTemperatureGetFloat(&g_sTMP006Inst, &fAmbient, &fObject); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // i32IntegerPart = (int32_t)fAmbient; i32FractionPart = (int32_t)(fAmbient * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } UARTprintf("Ambient %3d.%03d\t", i32IntegerPart, i32FractionPart); // // Convert the floating point ambient temperature to an integer part // and fraction part for easy printing. // i32IntegerPart = (int32_t)fObject; i32FractionPart = (int32_t)(fObject * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } UARTprintf("Object %3d.%03d\n", i32IntegerPart, i32FractionPart); }