//***************************************************************************** // // Print "Hello World!" to the UART on the Intelligent UART Module. // //***************************************************************************** int main(void) { // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Enable the GPIO pins for the LED D1 (PN1). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); // // Initialize the UART. // ConfigureUART(); // // Hello! // UARTprintf("Hello, world!\n"); // // We are finished. Hang around flashing D1. // while(1) { // // Turn on D1. // LEDWrite(CLP_D1, 1); // // Delay for a bit. // SysCtlDelay(g_ui32SysClock / 10 / 3); // // Turn off D1. // LEDWrite(CLP_D1, 0); // // Delay for a bit. // SysCtlDelay(g_ui32SysClock / 10 / 3); } }
//***************************************************************************** // // Called by the NVIC as a result of GPIO port M interrupt event. For this // application GPIO port M pin 3 is the interrupt line for the MPU9150 // // For BoosterPack 2 Interface use Port M pin 7. // //***************************************************************************** void GPIOPortMIntHandler(void) { unsigned long ulStatus; // // Get the status flags to see which pin(s) caused the interrupt. // ulStatus = GPIOIntStatus(GPIO_PORTM_BASE, true); // // Clear all the pin interrupts that are set // GPIOIntClear(GPIO_PORTM_BASE, ulStatus); // // Check if this is an interrupt on the MPU9150 interrupt line. // // For BoosterPack 2 use Pin 7 instead. // if(ulStatus & GPIO_PIN_3) { // // Turn on the LED to show that transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // MPU9150 Data is ready for retrieval and processing. // MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst); } }
//***************************************************************************** // // SHT21 Application error handler. // //***************************************************************************** void SHT21AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line) { uint32_t ui32LEDState; // // Set terminal color to red and print error status and locations. // UARTprintf("\033[31;1m"); UARTprintf("Error: %d, File: %s, Line: %d\n" "See I2C status definitions in utils\\i2cm_drv.h\n", g_vui8ErrorFlag, pcFilename, ui32Line); // // Return terminal color to normal. // UARTprintf("\033[0m"); // // Read the initial LED state and clear the CLP_D2 LED. // LEDRead(&ui32LEDState); ui32LEDState &= ~CLP_D2; // // Go to sleep wait for interventions. A more robust application could // attempt corrective actions here. // while(1) { // // Toggle LED D1 to indicate the error. // ui32LEDState ^= CLP_D1; LEDWrite(CLP_D1 | CLP_D2, ui32LEDState); // // Do Nothing. // ROM_SysCtlDelay(g_ui32SysClock / (10 * 3)); } }
//***************************************************************************** // // MPU9150 Sensor callback function. Called at the end of MPU9150 sensor // driver transactions. This is called from I2C interrupt context. Therefore, // we just set a flag and let main do the bulk of the computations and display. // //***************************************************************************** void MPU9150AppCallback(void *pvCallbackData, uint_fast8_t ui8Status) { // // Turn off the LED to show that transaction is complete. // LEDWrite(CLP_D3 | CLP_D4, 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) { g_vui8I2CDoneFlag = 1; } // // Store the most recent status in case it was an error condition // g_vui8ErrorFlag = ui8Status; }
//***************************************************************************** // // This example encrypts blocks of plaintext using TDES in CBC mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], ui32Errors, ui32Idx, ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable DES interrupts. // ROM_IntEnable(INT_DES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting TDES CBC encryption demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and DES modules. // if(!DESInit()) { UARTprintf("Initialization of the DES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // This CGI handler is called whenever the web browser requests iocontrol.cgi. // This function will set LED and PIN status // //***************************************************************************** char* hCGI_ioControl(int32_t iIndex, int32_t i32NumParams, char *pcParam[], char *pcValue[]) { int32_t i32DevId; int32_t i32Cmd; bool bParamError; int8_t i8Scope = 0x00; int8_t i8Protocol = 0x00; int8_t i8Id = 0x00; i32DevId = 0x00000000; i32Cmd = 0x00000000; bParamError = false; // Get deviceId i32DevId = GetCGIParam( "id", pcParam, pcValue, i32NumParams, &bParamError ); i32Cmd = GetCGIParam( "val", pcParam, pcValue, i32NumParams, &bParamError ); // Was there any error reported by the parameter parser? if( bParamError ) { return( PARAM_ERROR_RESPONSE ); } // Identify which device and command i32DevId = i32DevId & 0x0000FFFF; // we need only 16bits i8Scope = (i32DevId & 0x3000) >> 10; i8Protocol = ( i32DevId & 0x0300) >> 8; i8Id = ( i32DevId & 0x00FF); if( i8Scope == 0x00 ) { // internal device if( i8Protocol == 0x00 ) { // no special protocol switch( i8Id ) { case DEV_INTERNAL_LED1: UARTprintf( "Triggering LED1.\n" ); LEDWrite( CLP_D1, (i32Cmd)?CLP_D1:0 ); break; case DEV_INTERNAL_LED2: UARTprintf( "Triggering LED2.\n" ); LEDWrite( CLP_D2, (i32Cmd)?CLP_D2:0 ); break; case DEV_INTERNAL_LED3: UARTprintf( "Triggering LED3.\n" ); LEDWrite( CLP_D3, (i32Cmd)?CLP_D3:0 ); break; case DEV_INTERNAL_LED4: UARTprintf( "Triggering LED4.\n" ); LEDWrite( CLP_D4, (i32Cmd)?CLP_D4:0 ); break; default: UARTprintf( "Unkown device ID.\n"); break; } } else { UARTprintf( "Protocol not supported.\n"); } } else { UARTprintf( "Device scope not supported.\n"); } return( DEFAULT_CGI_RESPONSE ); }
//***************************************************************************** // // This example generates hashes from a random block of data and empty block. // //***************************************************************************** int main(void) { uint32_t pui32HashResult[5], ui32Errors, ui32Vector, ui32Idx, ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Initialize local variables. // ui32Errors = 0; // // Enable SHA interrupts. // ROM_IntEnable(INT_SHA0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting SHA1 hash encryption demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and SHAMD5 modules. // if(!SHAMD5Init()) { UARTprintf("Initialization of the SHA module failed.\n"); ui32Errors |= 0x00000001; } // // Run tests without uDMA. // for(ui32Vector = 0; ui32Vector < 3; ui32Vector++) { UARTprintf("Running test #%d without uDMA\n", ui32Vector); // // Generate the hash. // SHA1HashGenerate(g_pui32RandomData, g_psSHA1TestVectors[ui32Vector].ui32DataLength, pui32HashResult, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 5; ui32Idx++) { if(pui32HashResult[ui32Idx] != g_psSHA1TestVectors[ui32Vector].pui32HashResult[ui32Idx]) { UARTprintf("Hash result mismatch - Exp: 0x%x, Act: 0x%x\n", g_psSHA1TestVectors[ui32Vector]. pui32HashResult[ui32Idx], pui32HashResult[0]); ui32Errors |= ((ui32Idx << 16) | 0x2); } } } // // Run tests with uDMA. // for(ui32Vector = 0; ui32Vector < 3; ui32Vector++) { UARTprintf("Running test #%d with uDMA\n", ui32Vector); // // Generate the hash. // SHA1HashGenerate(g_pui32RandomData, g_psSHA1TestVectors[ui32Vector].ui32DataLength, pui32HashResult, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 5; ui32Idx++) { if(pui32HashResult[ui32Idx] != g_psSHA1TestVectors[ui32Vector].pui32HashResult[ui32Idx]) { UARTprintf("Hash result mismatch - Exp: 0x%x, Act: 0x%x\n", g_psSHA1TestVectors[ui32Vector]. pui32HashResult[ui32Idx], pui32HashResult[0]); ui32Errors |= ((ui32Idx << 16) | 0x3); } } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // Main application entry point. // //***************************************************************************** int main(void) { int_fast32_t i32IPart[16], i32FPart[16]; uint_fast32_t ui32Idx, ui32CompDCMStarted; float pfData[16]; float *pfAccel, *pfGyro, *pfMag, *pfEulers, *pfQuaternion; // // Initialize convenience pointers that clean up and clarify the code // meaning. We want all the data in a single contiguous array so that // we can make our pretty printing easier later. // pfAccel = pfData; pfGyro = pfData + 3; pfMag = pfData + 6; pfEulers = pfData + 9; pfQuaternion = pfData + 12; // // Configure the system frequency. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins for this board. // PinoutSet(false, false); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JMPU9150 Complimentary DCM Example\n"); // // The I2C7 peripheral must be enabled before use. // // For BoosterPack 2 interface use I2C8. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Configure the pin muxing for I2C7 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // // For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinConfigure(GPIO_PD0_I2C7SCL); ROM_GPIOPinConfigure(GPIO_PD1_I2C7SDA); // // 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. // // For BoosterPack 2 interface use PA2 and PA3. // GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); ROM_GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // MPU9150. // // For BoosterPack 2 interface change this to PM7. // ROM_GPIOPinTypeGPIOInput(GPIO_PORTM_BASE, GPIO_PIN_3); GPIOIntEnable(GPIO_PORTM_BASE, GPIO_PIN_3); ROM_GPIOIntTypeSet(GPIO_PORTM_BASE, GPIO_PIN_3, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOM); // // Keep only some parts of the systems running while in sleep mode. // GPIOM is for the MPU9150 interrupt pin. // UART0 is the virtual serial port // I2C7 is the I2C interface to the ISL29023 // // For BoosterPack 2 Interface change this to I2C8. // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C7); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C7 peripheral. // // For BoosterPack 2 use I2C8. // I2CMInit(&g_sI2CInst, I2C7_BASE, INT_I2C7, 0xff, 0xff, g_ui32SysClock); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // Initialize the MPU9150 Driver. // MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS, MPU9150AppCallback, &g_sMPU9150Inst); // // Wait for transaction to complete // MPU9150AppI2CWait(__FILE__, __LINE__); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // 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__); // // Turn on the LED to show a transaction is starting. // LEDWrite(CLP_D3 | CLP_D4, CLP_D3); // // 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); // // Print the basic outline of our data table. Done once and then kept as we // print only the data. // UARTprintf("\033[2J\033[H"); UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n"); UARTprintf("\033[20GX\033[31G|\033[43GY\033[54G|\033[66GZ\n\n"); UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Gyro\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("Mag\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[20GRoll\033[31G|\033[43GPitch\033[54G|\033[66GYaw\n\n"); UARTprintf("Eulers\033[8G|\033[31G|\033[54G|\n\n"); UARTprintf("\n\033[17GQ1\033[26G|\033[35GQ2\033[44G|\033[53GQ3\033[62G|" "\033[71GQ4\n\n"); UARTprintf("Q\033[8G|\033[26G|\033[44G|\033[62G|\n\n"); ui32CompDCMStarted = 0; while(1) { // // Go to sleep mode while waiting for data ready. // while(!g_vui8I2CDoneFlag) { ROM_SysCtlSleep(); } // // Clear the flag // g_vui8I2CDoneFlag = 0; // // Get floating point version of the Accel Data in m/s^2. // MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1, pfAccel + 2); // // Get floating point version of angular velocities in rad/sec // MPU9150DataGyroGetFloat(&g_sMPU9150Inst, pfGyro, pfGyro + 1, pfGyro + 2); // // Get floating point version of magnetic fields strength in tesla // MPU9150DataMagnetoGetFloat(&g_sMPU9150Inst, pfMag, pfMag + 1, pfMag + 2); // // Check if this is our first data ever. // if(ui32CompDCMStarted == 0) { // // Set flag indicating that DCM is started. // Perform the seeding of the DCM with the first data set. // ui32CompDCMStarted = 1; CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, pfGyro[0], pfGyro[1], pfGyro[2]); CompDCMStart(&g_sCompDCMInst); } else { // // DCM Is already started. Perform the incremental update. // CompDCMMagnetoUpdate(&g_sCompDCMInst, pfMag[0], pfMag[1], pfMag[2]); CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1], pfAccel[2]); CompDCMGyroUpdate(&g_sCompDCMInst, -pfGyro[0], -pfGyro[1], -pfGyro[2]); CompDCMUpdate(&g_sCompDCMInst); } // // Increment the skip counter. Skip counter is used so we do not // overflow the UART with data. // g_ui32PrintSkipCounter++; if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT) { // // Reset skip counter. // g_ui32PrintSkipCounter = 0; // // Get Euler data. (Roll Pitch Yaw) // CompDCMComputeEulers(&g_sCompDCMInst, pfEulers, pfEulers + 1, pfEulers + 2); // // Get Quaternions. // CompDCMComputeQuaternion(&g_sCompDCMInst, pfQuaternion); // // convert mag data to micro-tesla for better human interpretation. // pfMag[0] *= 1e6; pfMag[1] *= 1e6; pfMag[2] *= 1e6; // // Convert Eulers to degrees. 180/PI = 57.29... // Convert Yaw to 0 to 360 to approximate compass headings. // pfEulers[0] *= 57.295779513082320876798154814105f; pfEulers[1] *= 57.295779513082320876798154814105f; pfEulers[2] *= 57.295779513082320876798154814105f; if(pfEulers[2] < 0) { pfEulers[2] += 360.0f; } // // Now drop back to using the data as a single array for the // purpose of decomposing the float into a integer part and a // fraction (decimal) part. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { // // Conver float value to a integer truncating the decimal part. // i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx]; // // Multiply by 1000 to preserve first three decimal values. // Truncates at the 3rd decimal place. // i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f); // // Subtract off the integer part from this newly formed decimal // part. // i32FPart[ui32Idx] = i32FPart[ui32Idx] - (i32IPart[ui32Idx] * 1000); // // make the decimal part a positive number for display. // if(i32FPart[ui32Idx] < 0) { i32FPart[ui32Idx] *= -1; } } // // Print the acceleration numbers in the table. // UARTprintf("\033[5;17H%3d.%03d", i32IPart[0], i32FPart[0]); UARTprintf("\033[5;40H%3d.%03d", i32IPart[1], i32FPart[1]); UARTprintf("\033[5;63H%3d.%03d", i32IPart[2], i32FPart[2]); // // Print the angular velocities in the table. // UARTprintf("\033[7;17H%3d.%03d", i32IPart[3], i32FPart[3]); UARTprintf("\033[7;40H%3d.%03d", i32IPart[4], i32FPart[4]); UARTprintf("\033[7;63H%3d.%03d", i32IPart[5], i32FPart[5]); // // Print the magnetic data in the table. // UARTprintf("\033[9;17H%3d.%03d", i32IPart[6], i32FPart[6]); UARTprintf("\033[9;40H%3d.%03d", i32IPart[7], i32FPart[7]); UARTprintf("\033[9;63H%3d.%03d", i32IPart[8], i32FPart[8]); // // Print the Eulers in a table. // UARTprintf("\033[14;17H%3d.%03d", i32IPart[9], i32FPart[9]); UARTprintf("\033[14;40H%3d.%03d", i32IPart[10], i32FPart[10]); UARTprintf("\033[14;63H%3d.%03d", i32IPart[11], i32FPart[11]); // // Print the quaternions in a table format. // UARTprintf("\033[19;14H%3d.%03d", i32IPart[12], i32FPart[12]); UARTprintf("\033[19;32H%3d.%03d", i32IPart[13], i32FPart[13]); UARTprintf("\033[19;50H%3d.%03d", i32IPart[14], i32FPart[14]); UARTprintf("\033[19;68H%3d.%03d", i32IPart[15], i32FPart[15]); } } }
/* * main.c */ int main(void) { float fTemperature, fHumidity; int32_t i32IntegerPart; int32_t i32FractionPart; g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); //confiugre the GPIO pins PinoutSet(false,false); ConfigureUART(); //configure I2C pins SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); GPIOPinConfigure(GPIO_PA2_I2C8SCL); GPIOPinConfigure(GPIO_PA3_I2C8SDA); GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_2); GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_3); //enable interrupts IntMasterEnable(); //initialize I2C I2CMInit(&g_sI2CInst,I2C8_BASE,INT_I2C8,0xff,0xff,g_ui32SysClock); IntPrioritySet(INT_I2C7,0xE0); //initialize the sensors SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS, SHT21AppCallback,&g_sSHT21Inst); //delay for 20 ms SysCtlDelay(g_ui32SysClock / (50 * 3)); while(1){ // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a humidity measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_RH, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 33 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 29 milliseconds. // SysCtlDelay(g_ui32SysClock / (30 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Get the raw data from the sensor over the I2C bus. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get a copy of the most recent raw data in floating point format. // SHT21DataHumidityGetFloat(&g_sSHT21Inst, &fHumidity); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a temperature measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_T, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 100 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 85 milliseconds. // SysCtlDelay(g_ui32SysClock / (10 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Read the conversion data from the sensor over I2C. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get the most recent temperature result as a float in celcius. // SHT21DataTemperatureGetFloat(&g_sSHT21Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. Humidity is returned as 0.0 to 1.0 so multiply by 100 to get // percent humidity. // fHumidity *= 100.0f; i32IntegerPart = (int32_t) fHumidity; i32FractionPart = (int32_t) (fHumidity * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the humidity value using the integers we just created. // UARTprintf("Humidity %3d.%03d\t", i32IntegerPart, i32FractionPart); // // Perform the conversion from float to a printable set of integers. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart = (int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the temperature as integer and fraction parts. // UARTprintf("Temperature %3d.%03d\n", i32IntegerPart, i32FractionPart); // // Delay for one second. This is to keep sensor duty cycle // to about 10% as suggested in the datasheet, section 2.4. // This minimizes self heating effects and keeps reading more accurate. // SysCtlDelay(g_ui32SysClock / 3); } return 0; }
//***************************************************************************** // // This example performs a CRC-32 operation on an array of data using a // number of starting seeds. // //***************************************************************************** int main(void) { uint32_t ui32Result, ui32Errors, ui32Idx, ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, false); // // Initialize local variables. // ui32Errors = 0; // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("\033[2J\033[H"); UARTprintf("Starting CRC-32 demo.\n"); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CRC and CCM modules. // if(!CRCInit()) { UARTprintf("Initialization of the CRC module failed.\n"); ui32Errors |= 0x00000001; } // // Run through the test vectors. // for(ui32Idx = 0; ui32Idx < (sizeof(g_psCRC4C11DB7TestVectors) / sizeof(tCRCTestVector)); ui32Idx++) { UARTprintf("Starting vector #%d\n", ui32Idx); // // Generate the checksum without uDMA. // UARTprintf("Generating CRC-32 checksum without uDMA.\n"); ui32Result = CRC32DataProcess(g_pui32RandomData, (sizeof(g_pui32RandomData) / 4), g_psCRC4C11DB7TestVectors[ui32Idx].ui32Seed, false); if(ui32Result != g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result) { UARTprintf("CRC result mismatch - Exp: 0x%08x, Act: 0x%08x\n", g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result, ui32Result); } // // Generate the checksum with uDMA. // UARTprintf("Generating CRC-32 checksum with uDMA.\n"); ui32Result = CRC32DataProcess(g_pui32RandomData, (sizeof(g_pui32RandomData) / 4), g_psCRC4C11DB7TestVectors[ui32Idx].ui32Seed, true); if(ui32Result != g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result) { UARTprintf("CRC result mismatch - Exp: 0x%08x, Act: 0x%08x\n", g_psCRC4C11DB7TestVectors[ui32Idx].ui32Result, ui32Result); } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { const uint8_t bufLength=10; char inputBuf[1]; // // Configure the system frequency. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins for this board. // PinoutSet(false, false); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2J\033[H"); UARTprintf("SHT21 Example\n"); // // The I2C7 peripheral must be enabled before use. // // Note: For BoosterPack 2 interface use I2C8. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); //ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Configure the pin muxing for I2C7 functions on port D0 and D1. // This step is not necessary if your part does not support pin muxing. // // Note: For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinConfigure(GPIO_PA2_I2C8SCL); ROM_GPIOPinConfigure(GPIO_PA3_I2C8SDA); // // 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. // // Note: For BoosterPack 2 interface use PA2 and PA3. // ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_2); ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_3); // // Keep only some parts of the systems running while in sleep mode. // GPIOE is for the ISL29023 interrupt pin. // UART0 is the virtual serial port. // I2C7 is the I2C interface to the ISL29023. // // Note: For BoosterPack 2 change this to I2C8. // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C8); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C7 peripheral. // // Note: For BoosterPack 2 use I2C8. // I2CMInit(&g_sI2CInst, I2C8_BASE, INT_I2C8, 0xff, 0xff, g_ui32SysClock); // // Turn on D2 to show we are starting an I2C transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Initialize the SHT21. // SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS, SHT21AppCallback, &g_sSHT21Inst); // // Initialize the TMP006 // TMP006Init(&g_sTMP006Inst, &g_sI2CInst, TMP006_I2C_ADDRESS, TMP006AppCallback, &g_sTMP006Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Delay for 20 milliseconds for SHT21 reset to complete itself. // Datasheet says reset can take as long 15 milliseconds. // ROM_SysCtlDelay(g_ui32SysClock / (50 * 3)); UARTprintf("Menu:\n"); UARTprintf("h for Humidity \n"); UARTprintf("t for Temperature \n"); // // Loop Forever. // while(1) { if(UARTgets(inputBuf,bufLength)){ if(inputBuf[0]=='h'){ UARTprintf("Sensing Humidity Data:\n"); printHumidityData(); } else if(inputBuf[0]=='t'){ UARTprintf("Sensing Temperature Data:\n"); printTemperatureData(); } } } }
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); }
void printHumidityData(void){ float fTemperature, fHumidity; int32_t i32IntegerPart; int32_t i32FractionPart; // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a humidity measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_RH, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 33 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 29 milliseconds. // ROM_SysCtlDelay(g_ui32SysClock / (30 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Get the raw data from the sensor over the I2C bus. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get a copy of the most recent raw data in floating point format. // SHT21DataHumidityGetFloat(&g_sSHT21Inst, &fHumidity); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a temperature measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_T, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 100 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 85 milliseconds. // ROM_SysCtlDelay(g_ui32SysClock / (10 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Read the conversion data from the sensor over I2C. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get the most recent temperature result as a float in celcius. // SHT21DataTemperatureGetFloat(&g_sSHT21Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. Humidity is returned as 0.0 to 1.0 so multiply by 100 to get // percent humidity. // fHumidity *= 100.0f; i32IntegerPart = (int32_t) fHumidity; i32FractionPart = (int32_t) (fHumidity * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the humidity value using the integers we just created. // UARTprintf("Humidity %3d.%03d\t", i32IntegerPart, i32FractionPart); // // Perform the conversion from float to a printable set of integers. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart = (int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the temperature as integer and fraction parts. // UARTprintf("Temperature %3d.%03d\n", i32IntegerPart, i32FractionPart); // // Delay for one second. This is to keep sensor duty cycle // to about 10% as suggested in the datasheet, section 2.4. // This minimizes self heating effects and keeps reading more accurate. // ROM_SysCtlDelay(g_ui32SysClock / 3); }