int main(void) { // Setup any needed hardware SetupUART(8); SetupTimer(); SetupAccelerometer(TWOG, EIGHTBITS); InitADC(); // Enable global interrupts sei(); PORTB &= ~(_BV(PORTB5)); // Clear PB5, so it drives low by default (need to do this before switching it to an output) DDRB |= _BV(PORTB5); // Set PB5 as an output // Test data struct SensorData data; while(1) { if(ready_to_send) { SetupPulseSensor(); while(ADCSRA & _BV(ADSC)); //wait for conversion to finish DISCARD RESULT ADCSRA |= _BV(ADSC); //Start real conversion while(ADCSRA & _BV(ADSC)); //wait for conversion to finish USE RESULT data.pulse_val = ADCH; //save result of pulse sensor _delay_us(9); SetupGSR(); while(ADCSRA & _BV(ADSC)); //wait for conversion to finish DISCARD RESULT ADCSRA |= _BV(ADSC); //Start real conversion while(ADCSRA & _BV(ADSC)); //wait for conversion to finish USE RESULT data.gsr_val = ADCH; //save result of GSR sensor _delay_us(9); // Grab the accelerometer data AccelGetData(&data); // Send some bytes so RealTerm can sync to it UARTTransmit(0xAA); UARTTransmit(24); // Send the data UARTTransmit(data.pulse_val); UARTTransmit(data.gsr_val + 15); UARTTransmit(data.accel_x + 128); UARTTransmit(data.accel_y + 128); UARTTransmit(data.accel_z + 128); UARTTransmit(0); UARTTransmit(0); //to fill the UART receive fifo buffer in the tiva board for interrupt ready_to_send = false; } } }
//-------------------------------------------------------------------------------- // // Main program loop. // void main() { __disable_interrupt(); _pulseDataAddress = (char *) EEPROM_PULSE_DATA; _numberOfPulses = *_pulseDataAddress++; SetupPorts(); SetupUART(); SetupTimer2(); SetupTimer1(); __enable_interrupt(); while (1) { __wait_for_interrupt(); } }
int main(void) { // // 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(); // // Setup the system clock to run at 50 Mhz from PLL with crystal reference // SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); // SetupUART(); SetupI2C(); // UARTprintf("Starting....\n"); if(!L3G4200D_CheckDevice()) { UARTprintf("L3G4200D not detected\n"); while(1); } SetupL3G4200D(); while(1) { short x,y,z; char buff[20]; L3G4200D_ReadRaw(&x,&y,&z); ftoa(x,buff); UARTprintf("X: %s,",buff); ftoa(y,buff); UARTprintf("Y: %s,",buff); ftoa(z,buff); UARTprintf("Z: %s\n",buff); DELAY_MS(20); } }