void delay(uint32_t nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); // Make sure the timer finished, go back to sleep if it didn't // (Another interrupt may have woken up the system) while (ROM_TimerValueGet(WTIMER5_BASE, TIMER_A) != nTime * 10) ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_BASE, TIMER_A); }
//***************************************************************************** // // Function to wait for the SHT21 transactions to complete. // //***************************************************************************** void SHT21AppI2CWait(char *pcFilename, uint_fast32_t ui32Line) { // // 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) { SHT21AppErrorHandler(pcFilename, ui32Line); } // // clear the data flag for next use. // g_vui8DataFlag = 0; }
//***************************************************************************** // // TMP006 Application error handler. // //***************************************************************************** void TMP006AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line) { // // 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"); // // Go to sleep wait for interventions. A more robust application could // attempt corrective actions here. // while(1) { ROM_SysCtlSleep(); } }
void delay(unsigned long nTime) { ROM_TimerLoadSet(WTIMER5_BASE, TIMER_A, nTime * 10); ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(WTIMER5_BASE, TIMER_A); ROM_SysCtlSleep(); ROM_TimerIntDisable(WTIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerDisable(WTIMER5_BASE, TIMER_A); }
//***************************************************************************** int main(void) { // Set system clock to 50 MHz ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable the GPIO port F // Configure PF1 (Red LED), PF2 (Blue LED) and PF3 (Green LED) as outputs ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); /* // This code uses TivaWare to set up 1 kHz interrupts using system clock // Comment out when using register-direct code to configure SysTick ROM_SysTickPeriodSet (SysCtlClockGet()/1000); ROM_SysTickIntEnable(); ROM_SysTickEnable(); */ // This code uses PIOSC/4 as the clock source and generates 1 kHz interrupts // Comment out when using TivaWare functions to configure SysTick NVIC_ST_CTRL_R = 0x00; // clear CLK_SRC bit so PIOSC/4 is SysTick's clock source NVIC_ST_RELOAD_R = 4000; // (16MHz/4) / 1000 = 4000 NVIC_ST_CTRL_R = 0x03; // enable interrupts and enable timer NVIC_ST_CURRENT_R = 0x00; // clear SysTick counter (not necessary - just as example) // Turn on Green LED only ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, GPIO_PIN_3); while(1) { // Low power sleep mode while waiting for interrupt ROM_SysCtlSleep(); } }
//***************************************************************************** // // TMP006 Application error handler. // //***************************************************************************** void TMP006AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line) { // // 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"); // // Set RGB Color to RED // g_pui32Colors[0] = 0xFFFF; g_pui32Colors[1] = 0; g_pui32Colors[2] = 0; RGBColorSet(g_pui32Colors); // // Increase blink rate to get attention // RGBBlinkRateSet(10.0f); // // Go to sleep wait for interventions. A more robust application could // attempt corrective actions here. // while(1) { ROM_SysCtlSleep(); } }
int sensor(void) { ui32CompDCMStarted = 0; // 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]); // currentSpeed=i32IPart[9]; how to get velocity from speed } return pitch= i32IPart[9]; }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static uint32_t ui32PrevSeconds; static uint32_t ui32PrevXferCount; static uint32_t ui32PrevUARTCount = 0; uint32_t ui32XfersCompleted; uint32_t ui32BytesTransferred; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Enable the GPIO port that is used for the on-board LED. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // // Initialize the UART. // ConfigureUART(); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency on the display. // UARTprintf("Tiva C Series @ %u MHz\n\n", ROM_SysCtlClockGet() / 1000000); // // Show statistics headings. // UARTprintf("CPU Memory UART Remaining\n"); UARTprintf("Usage Transfers Transfers Time\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ui8ControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Remember the current count of memory buffer transfers. // ui32PrevXferCount = g_ui32MemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. // while(1) { // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ui32Seconds != ui32PrevSeconds) { // // Turn on the LED as a heartbeat // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ui32CPUUsage >> 16); // // Remember the new seconds count. // ui32PrevSeconds = g_ui32Seconds; // // Calculate how many memory transfers have occurred since the last // second. // ui32XfersCompleted = g_ui32MemXferCount - ui32PrevXferCount; // // Remember the new transfer count. // ui32PrevXferCount = g_ui32MemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ui32BytesTransferred = ui32XfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ui32BytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ui32BytesTransferred / 1000000); } else if(ui32BytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 100000); } else if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ui32XfersCompleted = (g_ui32RxBufACount + g_ui32RxBufBCount - ui32PrevUARTCount); // // Remember the new UART transfer count. // ui32PrevUARTCount = g_ui32RxBufACount + g_ui32RxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ui32BytesTransferred = ui32XfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ui32BytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ui32BytesTransferred / 1000000, (ui32BytesTransferred % 1000000) / 10000); } else if(ui32BytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ui32BytesTransferred / 1000); } else if(ui32BytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 100); } else if(ui32BytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ui32BytesTransferred / 1000, (ui32BytesTransferred % 1000) / 10); } else if(ui32BytesTransferred >= 100) { UARTprintf("%3d B/s ", ui32BytesTransferred); } else if(ui32BytesTransferred >= 10) { UARTprintf("%2d B/s ", ui32BytesTransferred); } else { UARTprintf("%1d B/s ", ui32BytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%2ds", 10 - ui32PrevSeconds); // // Turn off the LED. // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); // // See if we have run int32_t enough and exit the loop if so. // if(g_ui32Seconds >= 10) { break; } }
//***************************************************************************** // // 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; // // 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 port B used for motion interrupt. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Initialize the UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JMPU9150 Raw Example\n"); // // Set the color to a purple approximation. // g_pui32Colors[RED] = 0x8000; g_pui32Colors[BLUE] = 0x8000; g_pui32Colors[GREEN] = 0x0000; // // Initialize RGB driver. // 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. // 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 INT signal from the // MPU9150 // ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2); ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOB); // // Keep only some parts of the systems running while in sleep mode. // GPIOB is for the MPU9150 interrupt pin. // UART0 is the virtual serial port // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver // I2C3 is the I2C interface to the ISL29023 // ROM_SysCtlPeripheralClockGating(true); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB); 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, ROM_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); 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"); // // Enable blinking indicates config finished successfully // RGBBlinkRateSet(1.0f); 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]); } } }
//Write the phrases to the LCD void write_phrases() { while(1){ //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, pin_data); if(flag_check == 1){ if(UP_FLAG) { UP_FLAG = 0; current_list_position += 1; } if(DOWN_FLAG) { DOWN_FLAG = 0; current_list_position -= 1; } flag_check = 0; clear_screen(); //Modulo for circular list, used to print the phrases in a circular fashion current_list_position += SIZE; current_list_position %= SIZE; int i, j, index; for(i = current_list_position; i < current_list_position + 2 ; i ++) { GPIOPinWrite(port_C, GPIO_PIN_5, pin_5); index = i % SIZE; for(j = 0; j < strlen(phrases[index]); j++) { write_char_to_pins(phrases[index][j]); } //RS Low GPIOPinWrite(port_C, GPIO_PIN_5, 0x0); //Next Display Line writeDataPins(1,1,0,0,0,0,0,0); } } ROM_SysCtlSleep(); } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static unsigned long ulPrevSeconds; static unsigned long ulPrevXferCount; static unsigned long ulPrevUARTCount = 0; unsigned long ulXfersCompleted; unsigned long ulBytesTransferred; unsigned long ulButton; // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Set the push button as an input with a pull-up. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency and exit instructions. // UARTprintf("Stellaris @ %u MHz\n", ROM_SysCtlClockGet() / 1000000); UARTprintf("Press button to use debugger.\n\n"); // // Show statistics headings. // UARTprintf("CPU Memory UART\n"); UARTprintf("Usage Transfers Transfers\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; // // Remember the current count of memory buffer transfers. // ulPrevXferCount = g_ulMemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. When the // processor is sleeping a lot, it can be hard to connect to the target // with the debugger. Pressing the button will cause this loop to exit // and the processor will no longer sleep. // while(1) { // // Check for the select button press. If the button is pressed, // then exit this loop. // ulButton = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4); if(!ulButton) { break; } // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ulCPUUsage >> 16); // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // Calculate how many memory transfers have occurred since the last // second. // ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount; // // Remember the new transfer count. // ulPrevXferCount = g_ulMemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ulBytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ulBytesTransferred / 1000000); } else if(ulBytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 100000); } else if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount - ulPrevUARTCount); // // Remember the new UART transfer count. // ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%c", g_pcTwirl[ulPrevSeconds % 4]); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); }
//***************************************************************************** // // Main 'C' Language entry point. // //***************************************************************************** int main(void) { float fAmbient; int32_t i32IntegerPart, i32FractionPart; uint8_t ui8Mask; // // 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 and its pins. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JISL29023 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); // // Configure and Enable the GPIO interrupt. Used for INT signal from the // ISL29023 // ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5); GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_5); ROM_GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_FALLING_EDGE); ROM_IntEnable(INT_GPIOE); // // 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 // TIMER0, TIMER1 and WTIMER5 are used by the RGB driver // I2C3 is the I2C interface to the ISL29023 // 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); // // Configure desired interrupt priorities. Setting the I2C interrupt to be // of more priority than SysTick and the GPIO interrupt means those // interrupt routines can use the I2CM_DRV Application context does not use // I2CM_DRV API and GPIO and SysTick are at the same priority level. This // prevents re-entrancy problems with I2CM_DRV but keeps the MCU in sleep // state as much as possible. UART is at least priority so it can operate // in the background. // ROM_IntPrioritySet(INT_I2C3, 0x00); ROM_IntPrioritySet(FAULT_SYSTICK, 0x40); ROM_IntPrioritySet(INT_GPIOE, 0x80); ROM_IntPrioritySet(INT_UART0, 0x80); // // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Initialize I2C3 peripheral. // I2CMInit(&g_sI2CInst, I2C3_BASE, INT_I2C3, 0xff, 0xff, ROM_SysCtlClockGet()); // // Initialize the ISL29023 Driver. // ISL29023Init(&g_sISL29023Inst, &g_sI2CInst, ISL29023_I2C_ADDRESS, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the ISL29023 to measure ambient light continuously. Set a 8 // sample persistence before the INT pin is asserted. Clears the INT flag. // Persistence setting of 8 is sufficient to ignore camera flashes. // ui8Mask = (ISL29023_CMD_I_OP_MODE_M | ISL29023_CMD_I_INT_PERSIST_M | ISL29023_CMD_I_INT_FLAG_M); ISL29023ReadModifyWrite(&g_sISL29023Inst, ISL29023_O_CMD_I, ~ui8Mask, (ISL29023_CMD_I_OP_MODE_ALS_CONT | ISL29023_CMD_I_INT_PERSIST_8), ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the upper threshold to 80% of maximum value // g_sISL29023Inst.pui8Data[1] = 0xCC; g_sISL29023Inst.pui8Data[2] = 0xCC; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_HT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Configure the lower threshold to 20% of maximum value // g_sISL29023Inst.pui8Data[1] = 0x33; g_sISL29023Inst.pui8Data[2] = 0x33; ISL29023Write(&g_sISL29023Inst, ISL29023_O_INT_LT_LSB, g_sISL29023Inst.pui8Data, 2, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // //Configure and enable SysTick Timer // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // After all the init and config we start blink the LED // RGBBlinkRateSet(1.0f); // // Loop Forever // while(1) { ROM_SysCtlSleep(); if(g_vui8DataFlag) { g_vui8DataFlag = 0; // // Get a local floating point copy of the latest light data // ISL29023DataLightVisibleGetFloat(&g_sISL29023Inst, &fAmbient); // // Perform the conversion from float to a printable set of integers // i32IntegerPart = (int32_t)fAmbient; i32FractionPart = (int32_t)(fAmbient * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the temperature as integer and fraction parts. // UARTprintf("Visible Lux: %3d.%03d\n", i32IntegerPart, i32FractionPart); // // Check if the intensity of light has crossed a threshold. If so // then adjust range of sensor readings to track intensity. // if(g_vui8IntensityFlag) { // // Disable the low priority interrupts leaving only the I2C // interrupt enabled. // ROM_IntPriorityMaskSet(0x40); // // Reset the intensity trigger flag. // g_vui8IntensityFlag = 0; // // Adjust the lux range. // ISL29023AppAdjustRange(&g_sISL29023Inst); // // Now we must manually clear the flag in the ISL29023 // register. // ISL29023Read(&g_sISL29023Inst, ISL29023_O_CMD_I, g_sISL29023Inst.pui8Data, 1, ISL29023AppCallback, &g_sISL29023Inst); // // Wait for transaction to complete // ISL29023AppI2CWait(__FILE__, __LINE__); // // Disable priority masking so all interrupts are enabled. // ROM_IntPriorityMaskSet(0); } } } }
//***************************************************************************** // // 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); } }
//***************************************************************************** // // This example application demonstrates the use of the different sleep modes // and different power configuration options. // //***************************************************************************** int main(void) { // // Set the clocking to run from the MOSC with the PLL at 16MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 16000000); // // Set the clocking for Deep-Sleep. // Power down the PIOSC & MOSC to save power and run from the // internal 30kHz osc. // ROM_SysCtlDeepSleepClockConfigSet(1, (SYSCTL_DSLP_OSC_INT30 | SYSCTL_DSLP_PIOSC_PD | SYSCTL_DSLP_MOSC_PD)); // // Initialize the UART and write the banner. // Indicate we are currently in Run Mode. // ConfigureUART(); UARTprintf("\033[2J\033[H"); UARTprintf("Sleep Modes example\n\n"); UARTprintf("Mode:\t\tClock Source:\tLED Toggle Source:"); UARTprintf("\nRun\t\tMOSC with PLL\tTimer"); // // Initialize the buttons driver. // ButtonsInit(); // // Enable the interrupt for the button. // ROM_GPIOIntEnable(GPIO_PORTJ_AHB_BASE, GPIO_INT_PIN_0); // // Enable the GPIO ports that are used for the on-board LEDs. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Set pad config. // MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Set direction. // ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN); // // Enable the interrupt for the button. // ROM_GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0); // // Enable interrupt to NVIC. // ROM_IntEnable(INT_GPIOJ); // // Enable the GPIO ports that are used for the on-board LEDs. // ROM_SysCtlPeripheralEnable(RUN_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(SLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(DSLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(TOGGLE_GPIO_SYSCTL); // // Enable the GPIO pins for the LED. // ROM_GPIOPinTypeGPIOOutput(RUN_GPIO_BASE, RUN_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(SLEEP_GPIO_BASE, SLEEP_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(DSLEEP_GPIO_BASE, DSLEEP_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(TOGGLE_GPIO_BASE, TOGGLE_GPIO_PIN); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the 32-bit periodic timer. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock); // // Setup the interrupts for the timer timeout. // ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Configure the PWM0 to count down without synchronization. // This will be used in Deep-Sleep. // ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // // Enable the PWM0 output signal. // ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true); // // Set up the period to match the timer. // ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 65000); // // Configure the PWM for a 50% duty cycle. // ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 65000 >> 1); // // Enable the timer. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Enable the Timer in Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); // // Enable the PWM in Deep-Sleep Mode. // ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_PWM0); // // Enable the Button Port in Sleep & Deep-Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_GPIOJ); // // Enable the LED Ports in Sleep & Deep-Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralDeepSleepEnable(DSLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralSleepEnable(TOGGLE_GPIO_SYSCTL); ROM_SysCtlPeripheralDeepSleepEnable(TOGGLE_GPIO_SYSCTL); // // Enable Auto Clock Gating Control. // ROM_SysCtlPeripheralClockGating(true); // // Set LDO to 1.15V in Sleep. // Set LDO to 1.10V in Deep-Sleep. // SysCtlLDOSleepSet(SYSCTL_LDO_1_15V); SysCtlLDODeepSleepSet(SYSCTL_LDO_1_10V); // // Set SRAM to Standby when in Sleep Mode. // Set Flash & SRAM to Low Power in Deep-Sleep Mode. // SysCtlSleepPowerSet(SYSCTL_SRAM_STANDBY); SysCtlDeepSleepPowerSet(SYSCTL_FLASH_LOW_POWER | SYSCTL_SRAM_LOW_POWER); // // Call to set initial LED power state. // PowerLEDsSet(); // // Loop forever. // while(1) { // // Handle going into the different sleep modes outside of // interrupt context. // if (g_ui32SleepMode == 1) { // // Go into Sleep Mode. // ROM_SysCtlSleep(); } else if (g_ui32SleepMode == 2) { // // Go into Deep-Sleep Mode. // ROM_SysCtlDeepSleep(); } } }
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); }
//***************************************************************************** // // Takes in data array [16], compute dcm data and update the array // // Created by Bill Yiqiu Wang on 26July15 // //***************************************************************************** void CompDCM(float data[]) { 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 = data; pfGyro = data + 3; pfMag = data + 6; pfEulers = data + 9; pfQuaternion = data + 12; // // 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); // // 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); // // 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; } }