/*! \brief Led Task to scroll led before reset */ void led_task(void) { switch (step_led_task) { case 0: gpio_clr_gpio_pin(LED1_GPIO); gpio_set_gpio_pin(LED2_GPIO); gpio_set_gpio_pin(LED3_GPIO); break; case 1: gpio_set_gpio_pin(LED1_GPIO); gpio_clr_gpio_pin(LED2_GPIO); gpio_set_gpio_pin(LED3_GPIO); break; case 2: gpio_set_gpio_pin(LED1_GPIO); gpio_set_gpio_pin(LED2_GPIO); gpio_clr_gpio_pin(LED3_GPIO); break; default: gpio_clr_gpio_pin(LED1_GPIO); gpio_set_gpio_pin(LED2_GPIO); gpio_set_gpio_pin(LED3_GPIO); break; } step_led_task++; cpu_delay_ms(300,FOSC0); }
void BlinkLEDExample() { LED_Off(LED0|LED1|LED2|LED3); while (1) { LED_Toggle(LED0|LED1|LED2|LED3); cpu_delay_ms(1000, FOSCRC); } }
void delay_ms(unsigned long delay) { #if (defined FREERTOS_USED) vTaskDelay( (portTickType)TASK_DELAY_MS(delay) ); #elif (defined NUTOS_USED) NutSleep(delay); #else cpu_delay_ms(delay, s_fcpu_hz); #endif }
/*! \brief Watchdog scheduler */ void wdt_scheduler(void) { volatile avr32_pm_t* pm = &AVR32_PM; // If Reset Cause is due to a Watchdog reset just relaunch Watchdog and turn // LED0 to 4 on to let user know that a new wdt reset has occurred. if (pm->RCAUSE.wdt) { wdt_reenable(); gpio_clr_gpio_pin(LED0_GPIO); gpio_set_gpio_pin(LED1_GPIO); gpio_set_gpio_pin(LED2_GPIO); gpio_set_gpio_pin(LED3_GPIO); cpu_delay_ms(300,FOSC0); } // If Reset Cause is due to a Power On reset, enable Watchdog with default value else if (pm->RCAUSE.por) { opt.us_timeout_period = WDT_MIN_VALUE_US ; // Save current value in GPLP register pm_write_gplp(pm, 0, opt.us_timeout_period); wdt_enable(&opt); } // If Reset Cause is due to an External reset, increment opt.us_timeout_period else if (pm->RCAUSE.ext) { // Reload current value stored in GPLP register opt.us_timeout_period = pm_read_gplp(pm, 0); opt.us_timeout_period += WDT_CTRL_STEP_US; if (opt.us_timeout_period >= WDT_MAX_VALUE_US) opt.us_timeout_period = WDT_MIN_VALUE_US; wdt_enable(&opt); // Save new value in GPLP register pm_write_gplp(pm,0,opt.us_timeout_period); } // Else relaunch Watchdog and toggle GPIO to let user know that a new reset has occurred else { opt.us_timeout_period = WDT_MIN_VALUE_US; // Save start value of watchdog in GPLP register pm_write_gplp(pm, 0, opt.us_timeout_period); wdt_enable(&opt); } }
/*! \brief Watchdog scheduler */ void wdt_scheduler(void) { // If Reset Cause is due to a Watchdog reset just relaunch Watchdog and turn // LED0 to 4 on to let user know that a new wdt reset has occurred. if(AVR32_PM.RCAUSE.wdt) { wdt_reenable(); gpio_clr_gpio_pin(LED0_GPIO); gpio_clr_gpio_pin(LED1_GPIO); gpio_clr_gpio_pin(LED2_GPIO); gpio_clr_gpio_pin(LED3_GPIO); cpu_delay_ms(300,FOSC0); // If Reset Cause is due to a Power On reset, enable Watchdog with default value }else if (AVR32_PM.RCAUSE.por) { current_wdt_value = WDT_MIN_VALUE_US ;//WDT_MIN_VALUE; // Save current value in GPLP register pcl_write_gplp(0,current_wdt_value); opt.us_timeout_period = current_wdt_value; wdt_enable(&opt); // If Reset Cause is due to an External reset, increment current_wdt_value }else if (AVR32_PM.RCAUSE.ext) { // Reload current value stored in GPLP register current_wdt_value = pcl_read_gplp(0); current_wdt_value += WDT_CTRL_STEP_US; //WDT_CTRL_STEP; if (current_wdt_value >= WDT_MAX_VALUE_US) current_wdt_value = WDT_MIN_VALUE_US; opt.us_timeout_period = current_wdt_value; wdt_enable(&opt); // Save new value in GPLP register pcl_write_gplp(0,current_wdt_value); // Else relaunch Watchdog and toggle GPIO to let user know that a new reset has occurred }else{ current_wdt_value = WDT_MIN_VALUE_US; //WDT_MIN_VALUE // Save start value of watchdog in GPLP register pcl_write_gplp(0,current_wdt_value); opt.us_timeout_period = current_wdt_value; wdt_enable(&opt); } }
void LEDSequencingExample() { LED_Init(); int counter = 0; while (1) { LED_Off(LED0|LED1|LED2|LED3); switch (counter) { case 0: LED_On(LED0); break; case 1: LED_On(LED1); break; case 2: LED_On(LED2); break; case 3: LED_On(LED3); break; case 4: LED_On(LED2); break; case 5: LED_On(LED1); break; } counter = (counter + 1) % 6; cpu_delay_ms(200, FOSCRC); } }
void FastBlink() { LED_Off(LED0|LED1|LED2|LED3); unsigned int counter = 0; while (1) { //if (counter % 1) LED_Toggle(LED0); if (counter % 2) LED_Toggle(LED1); if (counter % 4) LED_Toggle(LED2); if (counter % 8) LED_Toggle(LED3); counter++; cpu_delay_ms(2, FOSCRC); } }
void delay_ms(unsigned long delay) { cpu_delay_ms(delay, s_fcpu_hz); }
/*! \brief Sets the SDRAM Controller up, initializes the SDRAM found on the * board and tests it. */ int main(void) { unsigned long sdram_size, progress_inc, i, j, tmp, noErrors = 0; volatile unsigned long *sdram = SDRAM; // Switch to external oscillator 0. pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); // Initialize the debug USART module. init_dbg_rs232(FOSC0); // Calculate SDRAM size in words (32 bits). sdram_size = SDRAM_SIZE >> 2; print_dbg("\x0CSDRAM size: "); print_dbg_ulong(SDRAM_SIZE >> 20); print_dbg(" MB\r\n"); // Initialize the external SDRAM chip. sdramc_init(FOSC0); print_dbg("SDRAM initialized\r\n"); // Determine the increment of SDRAM word address requiring an update of the // printed progression status. progress_inc = (sdram_size + 50) / 100; // Fill the SDRAM with the test pattern. for (i = 0, j = 0; i < sdram_size; i++) { if (i == j * progress_inc) { LED_Toggle(LED_SDRAM_WRITE); print_dbg("\rFilling SDRAM with test pattern: "); print_dbg_ulong(j++); print_dbg_char('%'); } sdram[i] = i; } LED_Off(LED_SDRAM_WRITE); print_dbg("\rSDRAM filled with test pattern \r\n"); // Recover the test pattern from the SDRAM and verify it. for (i = 0, j = 0; i < sdram_size; i++) { if (i == j * progress_inc) { LED_Toggle(LED_SDRAM_READ); print_dbg("\rRecovering test pattern from SDRAM: "); print_dbg_ulong(j++); print_dbg_char('%'); } tmp = sdram[i]; if (tmp != i) { noErrors++; } } LED_Off(LED_SDRAM_READ); print_dbg("\rSDRAM tested: "); print_dbg_ulong(noErrors); print_dbg(" corrupted word(s) \r\n"); if (noErrors) { LED_Off(LED_SDRAM_ERRORS); while (1) { LED_Toggle(LED_SDRAM_ERRORS); cpu_delay_ms(200, FOSC0); // Fast blink means errors. } } else { LED_Off(LED_SDRAM_OK); while (1) { LED_Toggle(LED_SDRAM_OK); cpu_delay_ms(1000, FOSC0); // Slow blink means OK. } } }
/*! \brief Main function. Execution starts here. * * \retval 42 Fatal error. */ int main(void) { uint32_t iter=0; uint32_t cs2200_out_freq=11289600; static bool b_sweep_up=true; static uint32_t freq_step=0; // USART options. static usart_serial_options_t USART_SERIAL_OPTIONS = { .baudrate = USART_SERIAL_EXAMPLE_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT }; // Initialize the TWI using the internal RCOSC init_twi(AVR32_PM_RCOSC_FREQUENCY); // Initialize the CS2200 and produce a default frequency. cs2200_setup(11289600, FOSC0); sysclk_init(); // Initialize the board. // The board-specific conf_board.h file contains the configuration of the board // initialization. board_init(); // Initialize the TWI init_twi(sysclk_get_pba_hz()); // Initialize Serial Interface using Stdio Library stdio_serial_init(USART_SERIAL_EXAMPLE,&USART_SERIAL_OPTIONS); // Initialize the HMatrix. init_hmatrix(); print_dbg("\r\nCS2200 Example\r\n"); // Generate a 12.288 MHz frequency out of the CS2200. print_dbg("Output 12.288 MHz\r\n"); cs2200_freq_clk_out(_32_BITS_RATIO(12288000, FOSC0)); cpu_delay_ms( 10000, sysclk_get_cpu_hz()); // Generate a 11.2896 MHz frequency out of the CS2200. print_dbg("Output 11.2896 MHz\r\n"); cs2200_freq_clk_out(_32_BITS_RATIO(cs2200_out_freq, FOSC0)); cpu_delay_ms( 10000, sysclk_get_cpu_hz()); print_dbg("Sweep from 11.2896 MHz steps of 100 PPM\r\n"); freq_step = PPM(cs2200_out_freq, 100); while(1) { uint32_t ratio; if(b_sweep_up) { if( iter<=10 ) { print_dbg("Add 100 PPM\r\n"); iter++; cs2200_out_freq += freq_step; ratio = _32_BITS_RATIO(cs2200_out_freq, FOSC0); cs2200_freq_clk_adjust((uint16_t)ratio); cpu_delay_ms( 1000, sysclk_get_cpu_hz()); while( twi_is_busy() ); } else b_sweep_up=false; } if(!b_sweep_up) { if( iter>0 ) { print_dbg("Sub 100 PPM\r\n"); iter--; cs2200_out_freq -= freq_step; ratio = _32_BITS_RATIO(cs2200_out_freq, FOSC0); cs2200_freq_clk_adjust((uint16_t)ratio); cpu_delay_ms( 1000, sysclk_get_cpu_hz()); while( twi_is_busy() ); } else b_sweep_up=true; } } }
static void twi_init(U32 fpba_hz) { const gpio_map_t AT42QT1060_TWI_GPIO_MAP = { {AT42QT1060_TWI_SCL_PIN, AT42QT1060_TWI_SCL_FUNCTION}, {AT42QT1060_TWI_SDA_PIN, AT42QT1060_TWI_SDA_FUNCTION} }; const twi_options_t AT42QT1060_TWI_OPTIONS = { .pba_hz = 24000000, .speed = AT42QT1060_TWI_MASTER_SPEED, .chip = AT42QT1060_TWI_ADDRESS }; // Assign I/Os to SPI. gpio_enable_module(AT42QT1060_TWI_GPIO_MAP, sizeof(AT42QT1060_TWI_GPIO_MAP) / sizeof(AT42QT1060_TWI_GPIO_MAP[0])); // Initialize as master. twi_master_init(AT42QT1060_TWI, &AT42QT1060_TWI_OPTIONS); } /*! \brief Callback function for a detect event of the touch sensor device. */ void touch_detect_callback(void) { touch_detect = true; } struct at42qt1060_data touch_data; void controller_task(void) { // if a touch is detected we read the status if(touch_detect) { touch_data.detect_status = at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); // need to read input port status too to reset CHG line at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); touch_detect = false; } } static void controller_detect_int_handler(void) { if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN)) { gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); touch_detect_callback(); } } void controller_init(U32 fcpu_hz, U32 fhsb_hz, U32 fpbb_hz, U32 fpba_hz) { // Disable all interrupts Disable_global_interrupt(); twi_init(fpba_hz); // wait until the device settles its CHG line cpu_delay_ms(230, fcpu_hz); at42qt1060_init(fcpu_hz); BSP_INTC_IntReg(&controller_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, AVR32_INTC_INT1); // For now we only react on falling edge // Actually this is a level interrupt (low active) gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE); gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); //static_fcpu_hz = fcpu_hz; cpu_set_timeout(cpu_ms_2_cy(JOYSTICK_KEY_DEBOUNCE_MS, static_fcpu_hz), &joystick_key_sensibility_timer); // Enable global interrupts Enable_global_interrupt(); }
int main (void) { // PM and PWM stuff volatile avr32_pm_t *ourPM; ourPM = GNMS_PM; gnms_pm_init(ourPM); gnms_pwm_init(); gnms_sci_init(); gnms_button_init(); gnms_adc_init(); #if 0 volatile avr32_gpio_port_t* led0_gpio_port = &AVR32_GPIO.port[LED0_PIN/32]; led0_gpio_port->oderc = 1 << LED0_PIN; led0_gpio_port->gpers = 1 << LED0_PIN; led0_gpio_port->puerc = 1 << LED0_PIN; led0_gpio_port->ovrc = 1 << LED0_PIN; led0_gpio_port->oders = 1 << LED0_PIN; while (true) { gpio_toggle_pin(LED0_PIN); cpu_delay_ms(500, 12000000); } #endif #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_POWER_ON_STRING); #endif cpu_delay_ms(5000, CLOCK_SPEED); send_IR_Command(gnms_power_str); unsigned long curTemp = 0; //gnms_adc_get_temp(); enum gnmsFanSpeed_e fanSpeed = GNMS_FAN_SPEED_NA; unsigned long sciVar = 0; unsigned long adcVar = 500000; while (true) { // button press detection cur_proj_left = gpio_get_pin_value(PROJECTOR_LEFT); cur_proj_right = gpio_get_pin_value(PROJECTOR_RIGHT); cur_proj_up = gpio_get_pin_value(PROJECTOR_UP); cur_proj_down = gpio_get_pin_value(PROJECTOR_DOWN); cur_proj_menu = gpio_get_pin_value(PROJECTOR_MENU); cur_proj_enter = gpio_get_pin_value(PROJECTOR_ENTER); cur_proj_exit = gpio_get_pin_value(PROJECTOR_EXIT); cur_vol_up = gpio_get_pin_value(VOLUME_UP); cur_vol_dn = gpio_get_pin_value(VOLUME_DN); if (cur_proj_left != prev_proj_left) { if (cur_proj_left != 0) { send_IR_Command(gnms_left_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_LEFT); #endif } prev_proj_left = cur_proj_left; } if (cur_proj_right != prev_proj_right) { if (cur_proj_right != 0) { send_IR_Command(gnms_right_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_RIGHT); #endif } prev_proj_right = cur_proj_right; } if (cur_proj_up != prev_proj_up) { if (cur_proj_up != 0) { send_IR_Command(gnms_up_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_UP); #endif } prev_proj_up = cur_proj_up; } if (cur_proj_down != prev_proj_down) { if (cur_proj_down != 0) { send_IR_Command(gnms_down_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_DOWN); #endif } prev_proj_down = cur_proj_down; } if (cur_proj_menu != prev_proj_menu) { if (cur_proj_menu != 0) { send_IR_Command(gnms_menu_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_MENU); #endif } prev_proj_menu = cur_proj_menu; } if (cur_proj_enter != prev_proj_enter) { if (cur_proj_enter != 0) { send_IR_Command(gnms_enter_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_ENTER); #endif } prev_proj_enter = cur_proj_enter; } if (cur_proj_exit != prev_proj_exit) { if (cur_proj_exit != 0) { send_IR_Command(gnms_esc_str); #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_EXIT); #endif } prev_proj_exit = cur_proj_exit; } if (cur_vol_up != prev_vol_up) { if (cur_vol_up != 0) { gnms_sci_write_line(GNMS_VOLUME_UP_STRING); } prev_vol_up = cur_vol_up; } if (cur_vol_dn != prev_vol_dn) { if (cur_vol_dn != 0) { gnms_sci_write_line(GNMS_VOLUME_DN_STRING); } prev_vol_dn = cur_vol_dn; } if (adcVar > 500000) { adcVar = 0; // temperature check curTemp = gnms_adc_get_high(); if (curTemp >= GNMS_TEMP_HIGH) { if (fanSpeed != GNMS_FAN_SPEED_HIGH) { //run the fans on high gnms_turn_fans_on_high(); fanSpeed = GNMS_FAN_SPEED_HIGH; #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_HIGH); #endif } } else if (curTemp >= GNMS_TEMP_MED) { if (fanSpeed != GNMS_FAN_SPEED_MED) { // run the fans on med gnms_turn_fans_on_med(); fanSpeed = GNMS_FAN_SPEED_MED; #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_MED); #endif } } else if (curTemp >= GNMS_TEMP_LOW) { if (fanSpeed != GNMS_FAN_SPEED_LOW) { // turn fans low gnms_turn_fans_on_low(); fanSpeed = GNMS_FAN_SPEED_LOW; #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_LOW); #endif } } else if (curTemp < GNMS_TEMP_LOW) { if (fanSpeed != GNMS_FAN_SPEED_OFF) { gnms_turn_fans_off(); fanSpeed = GNMS_FAN_SPEED_OFF; #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_OFF); #endif } } } if (sciVar > 10000) { sciVar = 0; if (gnms_sci_check_for_input() == true) { #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_POWER_DN_STRING); #endif break; } } sciVar++; adcVar++; } // power off the projector by sending it the power signal twice #if GNMS_DEBUG == 1 gnms_sci_write_line(GNMS_DEBUG_STR_PROJ); #endif send_IR_Command(gnms_power_str); cpu_delay_ms(300, CLOCK_SPEED); send_IR_Command(gnms_power_str); adc_disable(adc,GNMS_ADC_0); adc_disable(adc,GNMS_ADC_1); while (true) { // wait for shut down to complete } }
int main(void) { enum sleepmgr_mode current_sleep_mode = SLEEPMGR_ACTIVE; uint32_t ast_counter = 0; /* * Initialize the synchronous clock system to the default configuration * set in conf_clock.h. * \note All non-essential peripheral clocks are initially disabled. */ sysclk_init(); /* * Initialize the resources used by this example to the default * configuration set in conf_board.h */ board_init(); /* * Turn the activity status LED on to inform the user that the device * is active. */ gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN); /* * Configure pin change interrupt for asynchronous wake-up (required to * wake up from the STATIC sleep mode) and enable the EIC clock. * * First, enable the clock for the EIC module. */ sysclk_enable_pba_module(SYSCLK_EIC); /* * Map the interrupt line to the GPIO pin with the right peripheral * function. */ gpio_enable_module_pin(WAKE_BUTTON_EIC_PIN, WAKE_BUTTON_EIC_FUNCTION); /* * Enable the internal pull-up resistor on that pin (because the EIC is * configured such that the interrupt will trigger on low-level, see * eic_options.eic_level). */ gpio_enable_pin_pull_up(WAKE_BUTTON_EIC_PIN); // Init the EIC controller with the options eic_init(&AVR32_EIC, &eic_options, sizeof(eic_options) / sizeof(eic_options_t)); // Enable External Interrupt Controller Line eic_enable_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE); // Enable the AST clock. sysclk_enable_pba_module(SYSCLK_AST); // Initialize the AST in Counter mode ast_init_counter(&AVR32_AST, AST_OSC_RC, AST_PSEL_RC_1_76HZ, ast_counter); /* * Configure the AST to wake up the CPU when the counter reaches the * selected alarm0 value. */ AVR32_AST.WER.alarm0 = 1; // Enable the AST ast_enable(&AVR32_AST); // Initialize the sleep manager, lock initial mode. sleepmgr_init(); sleepmgr_lock_mode(current_sleep_mode); while (1) { ast_counter = ast_get_counter_value(&AVR32_AST); // disable alarm 0 ast_disable_alarm0(&AVR32_AST); // Set Alarm to current time + (6/1.76) seconds ast_counter += 6; ast_set_alarm0_value(&AVR32_AST, ast_counter); // Enable alarm 0 ast_enable_alarm0(&AVR32_AST); /* * Turn the activity status LED off to inform the user that the * device is in a sleep mode. */ gpio_set_pin_high(LED_ACTIVITY_STATUS_PIN); /* * Go to sleep in the deepest allowed sleep mode (i.e. no * deeper than the currently locked sleep mode). */ sleepmgr_enter_sleep(); /* * Turn the activity status LED on to inform the user that the * device is active. */ gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN); // After wake up, clear the Alarm0 AVR32_AST.SCR.alarm0 = 1; // Unlock the current sleep mode. sleepmgr_unlock_mode(current_sleep_mode); // Add a 3s delay cpu_delay_ms(3000, sysclk_get_cpu_hz()); // Clear the External Interrupt Line (in case it was raised). eic_clear_interrupt_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE); // Lock the next sleep mode. ++current_sleep_mode; if ((current_sleep_mode >= SLEEPMGR_NR_OF_MODES) #if UC3L && (BOARD == UC3L_EK) /* Note concerning the SHUTDOWN sleep mode: the shutdown sleep * mode can only be used when the UC3L supply mode is the 3.3V * Supply Mode with 1.8V Regulated I/O Lines. That is not how * the UC3L is powered on the ATUC3L-EK so the SHUTDOWN mode * cannot be used on this board. Thus we skip this sleep mode * in this example for this board. */ || (current_sleep_mode == SLEEPMGR_SHUTDOWN) #endif ) { current_sleep_mode = SLEEPMGR_ACTIVE; } sleepmgr_lock_mode(current_sleep_mode); } }
int configureMPU60X0(int8_t mpuAddress, int8_t gyroFullScale, int8_t accelFullScale, int8_t DPLFConfig) { uint8_t data; // Send a device reset and tell the device to derive its clock from a PLL using the X-axis of the gyroscope as a base. data = MPU60X0_PWR_MGMT_1_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_PWR_MGMT_1, &data, 1) != 0) { return(-1); } // Delay for 100ms. cpu_delay_ms(100, sysclk_get_cpu_hz()); // Send the signal path reset byte. // Just to ensure the entire device has been reset. data = MPU60X0_SIGNAL_PATH_RESET_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_SIGNAL_PATH_RESET, &data, 1) != 0) { return(-1); } // Delay for 100ms. cpu_delay_ms(100, sysclk_get_cpu_hz()); // Send the configuration byte. // Set EXT_SYNC off and DLPF to 260Hz bandwidth or a user defined value. data = (DPLFConfig > -1) ? (((MPU60X0_CONFIG_BYTE) & 0xF8) | DPLFConfig) : MPU60X0_CONFIG_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_CONFIG, &data, 1) != 0) { return(-1); } // Configure the gyroscope. // Set the full scale range of the gyroscope to GYRO_FS_SEL (defined in header file) or a user defined value. data = (gyroFullScale > -1) ? (((MPU60X0_GYRO_CONFIG_BYTE) & 0xE3) | (gyroFullScale << 3)) : MPU60X0_GYRO_CONFIG_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_GYRO_CONFIG, &data, 1) != 0) { return(-1); } // Configure the accelerometer. // Set the full scale range of the accelerometer to ACCEL_FS_SEL (defined in header file) or a user defined value. data = (accelFullScale > -1) ? (((MPU60X0_ACCEL_CONFIG_BYTE) & 0xE3) | (accelFullScale << 3)) : MPU60X0_ACCEL_CONFIG_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_ACCEL_CONFIG, &data, 1) != 0) { return(-1); } // Configure the interrupt generation byte. // Set the MPU60X0 to only generate interrupts when a set of sensor readings are available. data = MPU60X0_INT_ENABLE_BYTE; if (sendMPUPacket(mpuAddress, MPU60X0_INT_ENABLE, &data, 1) != 0) { return(-1); } return(0); }