示例#1
0
void infrared_i2c_update( void ) {
#if ! (defined SITL || defined HITL)
  // IR horizontal
  if (irh_trans.status == I2CTransDone && ir_i2c_hor_status == IR_I2C_IDLE) {
    if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_hor_done) {
      irh_trans.buf[0] = ir_i2c_conf_word | IR_HOR_OC_BIT | IR_START_CONV ;
      I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1);
      ir_i2c_hor_status = IR_I2C_CONFIGURE_HOR;
    } else {
      // Read next values
      I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3);
      ir_i2c_data_hor_available = FALSE;
      ir_i2c_hor_status = IR_I2C_READ_IR1;
    }
  }
  // IR vertical
  if (irv_trans.status == I2CTransDone) {
    if (ValidConfWord(ir_i2c_conf_word) && !ir_i2c_conf_ver_done) {
      irv_trans.buf[0] = ir_i2c_conf_word | IR_VER_OC_BIT;
      I2CTransmit(i2c0, irv_trans, IR_VER_I2C_ADDR, 1);
    } else {
      // Read next values
      I2CReceive(i2c0, irv_trans, IR_VER_I2C_ADDR, 2);
      ir_i2c_data_ver_available = FALSE;
    }
  }
#endif /* SITL || HITL */
}
示例#2
0
void infrared_i2c_hor_event( void ) {
#if ! (defined SITL || defined HITL)
  irh_trans.status = I2CTransDone;
  switch (ir_i2c_hor_status) {
    case IR_I2C_IDLE :
      break;
    case IR_I2C_READ_IR1 :
      if (bit_is_set(irh_trans.buf[2],7)) {
        I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3);
        break;
      }
      // Read IR1 value
      int16_t ir1 = (irh_trans.buf[0]<<8) | irh_trans.buf[1];
      ir1 = ir1 - (IR_I2C_IR1_NEUTRAL << ir_i2c_conf_word);
      ir_i2c.ir1 = FilterIR(ir_i2c.ir1, ir1);
      // Select IR2 channel
      irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR2 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV;
      I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1);
      ir_i2c_hor_status = IR_I2C_IR2_SELECTED;
      break;
    case IR_I2C_IR2_SELECTED :
      // IR2 selected, asking for IR2 value
      I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3);
      ir_i2c_hor_status = IR_I2C_READ_IR2;
      break;
    case IR_I2C_READ_IR2 :
      // Read IR2 value
      if (bit_is_set(irh_trans.buf[2],7)) {
        I2CReceive(i2c0, irh_trans, IR_HOR_I2C_ADDR, 3);
        break;
      }
      int16_t ir2 = (irh_trans.buf[0]<<8) | irh_trans.buf[1];
      ir2 = ir2 - (IR_I2C_IR2_NEUTRAL << ir_i2c_conf_word);
      ir_i2c.ir2 = FilterIR(ir_i2c.ir2, ir2);
      // Update estimator
      ir_i2c_data_hor_available = TRUE;
#ifndef IR_I2C_READ_ONLY
      if (ir_i2c_data_ver_available) {
        ir_i2c_data_hor_available = FALSE;
        ir_i2c_data_ver_available = FALSE;
        UpdateIRValue(ir_i2c);
      }
#endif
      // Select IR1 channel
      irh_trans.buf[0] = IR_HOR_I2C_SELECT_IR1 | IR_HOR_OC_BIT | ir_i2c_conf_word | IR_START_CONV;
      I2CTransmit(i2c0, irh_trans, IR_HOR_I2C_ADDR, 1);
      ir_i2c_hor_status = IR_I2C_IR1_SELECTED;
      break;
    case IR_I2C_IR1_SELECTED :
      // End reading cycle
      ir_i2c_hor_status = IR_I2C_IDLE;
      break;
    case IR_I2C_CONFIGURE_HOR :
      // End conf cycle
      ir_i2c_conf_hor_done = TRUE;
      ir_i2c_hor_status = IR_I2C_IDLE;
      break;
  }
#endif /* !SITL && !HITL */
}
示例#3
0
void humid_sht_periodic( void ) {
  switch (sht_status) {

  case SHT_UNINIT:
    /* do soft reset, then wait at least 15ms */
    sht_status = SHT_RESET;
    sht_trans.buf[0] = SHT_SOFT_RESET;
    I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1);
    break;

  case SHT_SERIAL:
    /* get serial number part 1 */
    sht_status = SHT_SERIAL1;
    sht_trans.buf[0] = 0xFA;
    sht_trans.buf[1] = 0x0F;
    I2CTransceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 2, 8);
    break;

  case SHT_SERIAL1:
  case SHT_SERIAL2:
    break;

  default:
    /* trigger temp measurement, no master hold */
    sht_trans.buf[0] = SHT_TRIGGER_TEMP;
    sht_status = SHT_TRIG_TEMP;
    I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1);
    /* send serial number every 30 seconds */
    RunOnceEvery((4*30), DOWNLINK_SEND_SHT_SERIAL(DefaultChannel, &sht_serial1, &sht_serial2));
    break;
  }
}
示例#4
0
void wind_gfi_periodic( void ) {
    /* OE low, SEL high (for low data) */
    pcf_trans.buf[0] = 0xFF;
    pcf_trans.buf[1] = 0xBF;
    pcf_status = PCF_SET_OE_LSB;
    I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
}
示例#5
0
void ArduIMU_periodicGPS( void ) {

  if (ardu_gps_trans.status != I2CTransDone) { return; }

  // Test for high acceleration:
  //  - low speed
  //  - high thrust
  if (estimator_hspeed_dir < HIGH_ACCEL_LOW_SPEED && ap_state->commands[COMMAND_THROTTLE] > HIGH_ACCEL_HIGH_THRUST && !high_accel_done) {
    high_accel_flag = TRUE;
  } else {
    high_accel_flag = FALSE;
    if (estimator_hspeed_dir > HIGH_ACCEL_LOW_SPEED && !high_accel_flag) {
      high_accel_done = TRUE; // After takeoff, don't use high accel before landing (GS small, Throttle small)
    }
    if (estimator_hspeed_dir < HIGH_ACCEL_HIGH_THRUST_RESUME && ap_state->commands[COMMAND_THROTTLE] < HIGH_ACCEL_HIGH_THRUST_RESUME) {
      high_accel_done = FALSE; // Activate high accel after landing
    }
  }

  FillBufWith32bit(ardu_gps_trans.buf, 0, (int32_t)gps.speed_3d); // speed 3D
  FillBufWith32bit(ardu_gps_trans.buf, 4, (int32_t)gps.gspeed);   // ground speed
  FillBufWith32bit(ardu_gps_trans.buf, 8, (int32_t)DegOfRad(gps.course / 1e6));   // course
  ardu_gps_trans.buf[12] = gps.fix;                              // status gps fix
  ardu_gps_trans.buf[13] = gps_ubx.status_flags;                      // status flags
  ardu_gps_trans.buf[14] = (uint8_t)high_accel_flag;              // high acceleration flag (disable accelerometers in the arduimu filter)
  I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 15);

}
示例#6
0
void srf08_init(void)
{
  srf08_received = FALSE;
  srf08_got = FALSE;

  srf_trans.buf[0] = 0x00;
  srf_trans.buf[1] = 0x51;
  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);

  /** Setting the gain to the minimun value (to avoid echos ?) */
  srf_trans.buf[0] = SRF08_SET_GAIN;
  srf_trans.buf[1] = SRF08_MIN_GAIN;
  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);

  return;
}
示例#7
0
void tmp102_init(void) {
  tmp_meas_started = FALSE;
  /* configure 8Hz and enhanced mode */
  tmp_trans.buf[0] = TMP102_CONF_REG;
  tmp_trans.buf[1] = TMP102_CONF1;
  tmp_trans.buf[2] = TMP102_CONF2;
  I2CTransmit(TMP_I2C_DEV, tmp_trans, TMP102_SLAVE_ADDR, 3);
}
示例#8
0
void wind_gfi_event( void ) {
    if (pcf_trans.status == I2CTransSuccess) {

        if (pcf_status == PCF_SET_OE_LSB) {
            pcf_status = PCF_READ_LSB;
            I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
        }
        else if (pcf_status == PCF_READ_LSB) {
            /* read lower byte direction info */
            pcf_direction = pcf_trans.buf[0];

            /* OE low, SEL low (for high data) */
            pcf_trans.buf[0] = 0xFF;
            pcf_trans.buf[1] = 0x3F;
            pcf_status = PCF_SET_OE_MSB;
            I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
        }
        else if (pcf_status == PCF_SET_OE_MSB) {
            pcf_status = PCF_READ_MSB;
            I2CReceive(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);
        }
        else if (pcf_status == PCF_READ_MSB) {
            float fpcf_direction;

            /* read higher byte direction info */
            pcf_direction |= pcf_trans.buf[0] << 8;

            /* OE high, SEL high */
            pcf_trans.buf[0] = 0xFF;
            pcf_trans.buf[1] = 0xFF;
            pcf_status = PCF_IDLE;
            I2CTransmit(PCF_I2C_DEV, pcf_trans, PCF_SLAVE_ADDR, 2);

            /* 2048 digits per 360 degrees */
            fpcf_direction = fmod((pcf_direction * (360./2048.)) + ZERO_OFFSET_DEGREES, 360.);

            DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &pcf_direction, &fpcf_direction);
        }
        else if (pcf_status == PCF_IDLE) {
            pcf_trans.status = I2CTransDone;
        }
    }
}
void ArduIMU_periodicGPS( void ) {

  if (ardu_gps_trans.status != I2CTransDone) { return; }

  FillBufWith32bit(ardu_gps_trans.buf, 0, (int32_t)gps_speed_3d); // speed 3D
  FillBufWith32bit(ardu_gps_trans.buf, 4, (int32_t)gps_gspeed);   // ground speed
  FillBufWith32bit(ardu_gps_trans.buf, 8, (int32_t)gps_course);   // course
  ardu_gps_trans.buf[12] = gps_mode;                              // status gps fix
  ardu_gps_trans.buf[13] = gps_status_flags;                      // status flags
  I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 14);

}
示例#10
0
void ads1114_init( void ) {
  /* configure the ads1114_1 */
#if USE_ADS1114_1
  ads1114_1.i2c_addr = ADS1114_1_I2C_ADDR;
  ads1114_1.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
  ads1114_1.trans.buf[1] = ADS1114_1_CONFIG_MSB;
  ads1114_1.trans.buf[2] = ADS1114_1_CONFIG_LSB;
  I2CTransmit(ADS1114_I2C_DEVICE, ads1114_1.trans, ADS1114_1_I2C_ADDR, 3);
  ads1114_1.config_done = FALSE;
  ads1114_1.data_available = FALSE;
#endif

  /* configure the ads1114_2 */
#if USE_ADS1114_2
  ads1114_2.i2c_addr = ADS1114_2_I2C_ADDR;
  ads1114_2.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
  ads1114_2.trans.buf[1] = ADS1114_2_CONFIG_MSB;
  ads1114_2.trans.buf[2] = ADS1114_2_CONFIG_LSB;
  I2CTransmit(ADS1114_I2C_DEVICE, ads1114_2.trans, ADS1114_2_I2C_ADDR, 3);
  ads1114_2.config_done = FALSE;
  ads1114_2.data_available = FALSE;
#endif
}
示例#11
0
文件: MPPT.c 项目: AxSt/paparazzi
static void MPPT_ask( void ) {
  data_index++;
  if (data_index >= NB_I2C_DATA) {
    /* Setting the current value */
    fbw_current_milliamp = MPPT_data[MPPT_IBAT_INDEX];

    MPPT_data[MPPT_ITOTAL_INDEX] = MPPT_data[MPPT_IBAT_INDEX] + MPPT_data[MPPT_ICONV_INDEX];
    DOWNLINK_SEND_MPPT(DefaultChannel, DefaultDevice, NB_DATA, MPPT_data);
    data_index = 0;
  }

  mppt_trans.buf[0] = data_index;
  I2CTransmit(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 1);
  MPPT_status = MPPT_STATUS_ASKING;
}
示例#12
0
void generic_com_periodic( void ) {

    if (com_trans.status != I2CTransDone) {
        return;
    }

    com_trans.buf[0] = active_com;
    FillBufWith32bit(com_trans.buf, 1, gps.lla_pos.lat);
    FillBufWith32bit(com_trans.buf, 5, gps.lla_pos.lon);
    FillBufWith16bit(com_trans.buf, 9, (int16_t)(gps.lla_pos.alt/1000)); // altitude (meters)
    FillBufWith16bit(com_trans.buf, 11, gps.gspeed); // ground speed (cm/s)
    FillBufWith16bit(com_trans.buf, 13, (int16_t)(gps.course/1e4)); // course (1e3rad)
    FillBufWith16bit(com_trans.buf, 15, (uint16_t)(estimator_airspeed*100)); // TAS (cm/s)
    com_trans.buf[17] = electrical.vsupply; // decivolts
    com_trans.buf[18] = (uint8_t)(energy/100); // deciAh
    com_trans.buf[19] = (uint8_t)(ap_state->commands[COMMAND_THROTTLE]*100/MAX_PPRZ);
    com_trans.buf[20] = pprz_mode;
    com_trans.buf[21] = nav_block;
    FillBufWith16bit(com_trans.buf, 22, estimator_flight_time);
    I2CTransmit(GENERIC_COM_I2C_DEV, com_trans, GENERIC_COM_SLAVE_ADDR, NB_DATA);

}
示例#13
0
文件: MPPT.c 项目: AxSt/paparazzi
void MPPT_periodic( void ) {

  if (mppt_trans.status == I2CTransSuccess) {
    switch (MPPT_status) {
      case MPPT_STATUS_IDLE:
        /* If free, change mode if needed */
        if (MPPT_mode) {
          mppt_trans.buf[0] = MPPT_MODE_ADDR;
          mppt_trans.buf[1] = 0;
          mppt_trans.buf[2] = MPPT_mode;
          I2CTransmit(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 3);
          MPPT_mode = 0;
          MPPT_status = MPPT_STATUS_WRITING;
        } else {
          MPPT_ask();
        }
        break;

      case MPPT_STATUS_WRITING:
        MPPT_status = MPPT_STATUS_IDLE;
        break;

      case MPPT_STATUS_ASKING:
        /* The slave should send 2 bytes */
        I2CReceive(i2c0, mppt_trans, MPPT_SLAVE_ADDR, 2);
        MPPT_status = MPPT_STATUS_READING;
        break;

      case MPPT_STATUS_READING:
        /* We got 2 bytes */
        if (data_index < NB_I2C_DATA)
          MPPT_data[data_index] = (mppt_trans.buf[0]<<8) | mppt_trans.buf[1];
        MPPT_status = MPPT_STATUS_IDLE;
        break;
    }
  }
}
示例#14
0
void ArduIMU_periodicGPS( void ) {

    if (ardu_gps_trans.status != I2CTransDone) {
        return;
    }

    // Test for high acceleration:
    // - low speed
    // - high thrust
    if (gps_speed_3d < HIGH_ACCEL_LOW_SPEED && ap_state->commands[COMMAND_THROTTLE]) {
        high_accel_flag = TRUE;
    } else {
        high_accel_flag = FALSE;
    }

    FillBufWith32bit(ardu_gps_trans.buf, 0, (int32_t)gps_speed_3d); // speed 3D
    FillBufWith32bit(ardu_gps_trans.buf, 4, (int32_t)gps_gspeed); // ground speed
    FillBufWith32bit(ardu_gps_trans.buf, 8, (int32_t)gps_course); // course
    ardu_gps_trans.buf[12] = gps_mode; // status gps fix
    ardu_gps_trans.buf[13] = gps_status_flags; // status flags
    ardu_gps_trans.buf[14] = (uint8_t)high_accel_flag; // high acceleration flag (disable accelerometers in the arduimu filter)
    I2CTransmit(ARDUIMU_I2C_DEV, ardu_gps_trans, ArduIMU_SLAVE_ADDR, 15);

}
示例#15
0
static void baro_scp_start_high_res_measurement(void) {
  /* switch to high resolution */
  scp_trans.buf[0] = SCP1000_OPERATION;
  scp_trans.buf[1] = SCP1000_HIGH_RES;
  I2CTransmit(SCP_I2C_DEV, scp_trans, SCP1000_SLAVE_ADDR, 2);
}
示例#16
0
文件: main.c 项目: arduic/GitHub
/**********************************************************************************************
 *								Main
 *********************************************************************************************/
void main(void) {

	//After tomorrow's test flight. FOR THE LOVE OF GOD MOVE THESE INITALIZATIONS TO FUNCTIONS
	/**********************************************************************************************
	 *								Local Variables
	 *********************************************************************************************/

	unsigned long ultrasonic = 0;

	// 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.
	FPULazyStackingEnable();

	//Set the clock speed to 80MHz aka max speed
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	/*unsigned long test[2];
	test[0] = 180;
	test[1] = 10;
	short bob[1];
	bob[0] = ((char)test[0]<<8)|(char)test[1];
	float jimmy = (short)(((char)test[0]<<8)|(char)test[1]);
	jimmy /= 26;*/

	/**********************************************************************************************
	 *								Peripheral Initialization Awake
	 *********************************************************************************************/
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);	//Turn on GPIO communication on F pins for switches
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);	//Turn on GPIO for ADC
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);	//Turn on GPIO for the PWM comms
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);	//Turn on GPIO for LED test
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);   	//Turn on GPIO for UART
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3);	//Turn on Timer for PWM
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);		//Turn on I2C communication I2C slot 0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);	//Turn on the UART com
	SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG);		//Turn on the watchdog timer. This is a risky idea but I think it's for the best.


	/**********************************************************************************************
	 *								Peripheral Initialization Sleep
	 *********************************************************************************************/
	/*SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOF);	//This sets what peripherals are still enabled in sleep mode while UART would be nice, it would require the clock operate at full speed which is :P
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOB);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_GPIOA);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER0);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER1);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER2);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_TIMER3);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_SSI0);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_I2C1);
	SysCtlPeripheralSleepDisable(SYSCTL_PERIPH_ADC);
	SysCtlPeripheralClockGating(true); 		//I'm not sure about this one maybe remove it
	 */

	/**********************************************************************************************
	 *										PWM Initialization
	 *********************************************************************************************/
	SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100);		//This shouldn't be needed will test to remove
	//PWM pin Setup
	//PWM 0 on GPIO PB6, PWM 1 on pin 4... etc
	GPIOPinConfigure(GPIO_PB6_T0CCP0);	//Pitch -		yaw +
	GPIOPinConfigure(GPIO_PB4_T1CCP0);	//Pitch +		yaw +
	GPIOPinConfigure(GPIO_PB0_T2CCP0);	//Roll -		yaw -
	GPIOPinConfigure(GPIO_PB2_T3CCP0);	//Roll +		yaw -
	GPIOPinTypeTimer(GPIO_PORTB_BASE, (GPIO_PIN_6|GPIO_PIN_4|GPIO_PIN_0|GPIO_PIN_2));

	//Prescale the timers so they are slow enough to work with the ESC
	TimerPrescaleSet(TIMER0_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER1_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER2_BASE,TIMER_A,2);
	TimerPrescaleSet(TIMER3_BASE,TIMER_A,2);

	//Basic LED Out Test	Not sure why this is here look into			This just turns on an LED that I don't have plugged in. should remove later
	GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);
	GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xFF);

	//GPIOPinTypeGPIOOutputOD(GPIO_PORTB_BASE,GPIO_PIN_0);


	//Timers Setup for PWM and the load for the countdown
	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
	TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER1_BASE, TIMER_A, ulPeriod -1);
	TimerConfigure(TIMER2_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER2_BASE, TIMER_A, (ulPeriod -1));
	TimerConfigure(TIMER3_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER3_BASE, TIMER_A, ulPeriod -1);

	//TimerPrescaleSet(TIMER2_BASE, TIMER_A, extender1);
	//TimerLoadSet(TIMER2_BASE, TIMER_A, period1);
	//Set the match which is when the thing will pull high
	TimerMatchSet(TIMER0_BASE, TIMER_A, 254);  //Duty cycle = (1-%desired)*1000 note this means this number is percent low not percent high
	TimerMatchSet(TIMER1_BASE, TIMER_A, 254);
	TimerMatchSet(TIMER2_BASE, TIMER_A, 254);
	TimerMatchSet(TIMER3_BASE, TIMER_A, 254);

	//TimerPrescaleMatchSet(TIMER2_BASE, TIMER_A, extender2);
	//TimerMatchSet(TIMER2_BASE, TIMER_A, period2);

	//Enable the timers
	TimerEnable(TIMER0_BASE, TIMER_A);
	TimerEnable(TIMER1_BASE, TIMER_A);
	TimerEnable(TIMER2_BASE, TIMER_A);
	TimerEnable(TIMER3_BASE, TIMER_A);


	/**********************************************************************************************
	 *									onboard	Chip interrupt Initialization
	 *********************************************************************************************/
	//These two buttons are used to reset the bluetooth module in case of disconnection
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);	//RGB LED's
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x00);
	HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;				//Sw1 (PF4) is unaviable unless you make it only a GPIOF input via these commands
	HWREG(GPIO_PORTF_BASE + GPIO_O_CR) = 0x1;
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);	//Onboard buttons (PF0=Sw2,PF4=Sw1
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);		//This will make the buttons falling edge (a press pulls them low)
	//void (*functionPtr)(void) = &onBoardInteruptHandle;
	GPIOPortIntRegister(GPIO_PORTF_BASE, onBoardInteruptHandle);	//set function to handle interupt
	GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4,GPIO_FALLING_EDGE);		//Set the interrupt as falling edge
	GPIOPinIntEnable(GPIO_PORTF_BASE,GPIO_PIN_0|GPIO_PIN_4);	//Enable the interrupt
	//IntMasterEnable();
	IntEnable(INT_GPIOF);

	/**********************************************************************************************
	 *								UART Initialization
	 *********************************************************************************************/
	//Unlock PD7
	HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
	HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x80;

	GPIOPinConfigure(GPIO_PD7_U2TX);			//Set PD7 as TX
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_7);

	GPIOPinConfigure(GPIO_PD6_U2RX);			//Set PD6 as RX
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6);

	UARTConfigSetExpClk(UART2_BASE,SysCtlClockGet(),115200,UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE);  //I believe the Xbee defaults to no parity I do know it's 9600 baud though, changed to 115200 for bluetooth reasons

	UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);	//Set's how big the fifo needs to be in order to call the interrupt handler, 2byte
	UARTIntRegister(UART2_BASE,Uart2IntHandler);	//Regiester the interrupt handler
	UARTIntClear(UART2_BASE, UART_INT_TX | UART_INT_RX);	//Clear the interrupt
	UARTIntEnable(UART2_BASE, UART_INT_TX | UART_INT_RX);	//Enable the interrupt to trigger on both TX and RX event's. Could possibly remove TX

	UARTEnable(UART2_BASE);	//Enable UART
	IntEnable(INT_UART2);	//Second way to enable handler not sure if needed using anyway

	/**********************************************************************************************
	 *								I2C Initialization
	 *********************************************************************************************/
	//Serious credit to the man who made the Arduino version of this. he gave me addresses and equations. Sadly Arduino obfuscates what really is happening
	//Link posted on blog page
	//gyro address = 0x68 not 0x69
	GPIOPinConfigure(GPIO_PA7_I2C1SDA);
	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);	//Set GPA7 as SDA

	GPIOPinConfigure(GPIO_PA6_I2C1SCL);
	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);	//Set GPA6 as SCL

	I2CMasterInitExpClk(I2C1_MASTER_BASE,SysCtlClockGet(),false);	//I think it operates at 100kbps
	I2CMasterEnable(I2C1_MASTER_BASE);
	//Initalize the accelerometer			Address = 0x53
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02);
	UARTSend(0xAB);
	I2CTransmit(0x53,0x2D,0x00);
	I2CTransmit(0x53,0x2D,0x10);
	I2CTransmit(0x53,0x2D,0x08);

	//Initalize the gyroscope				Address = 0x68
	I2CTransmit(0x68,0x3E,0x00);
	I2CTransmit(0x68,0x15,0x07);
	I2CTransmit(0x68,0x16,0x1E);
	I2CTransmit(0x68,0x17,0x00);
	UARTSend(0xAC);

	/**********************************************************************************************
	 *								SysTick Initialization
	 *********************************************************************************************/
	SysTickIntRegister(SysTickIntHandler);
	SysTickIntEnable();

	SysTickPeriodSet((SysCtlClockGet() / (1000 * 3))*timeBetweenCalculations);	//This sets the period for the delay. the last num is the num of milliseconds
	SysTickEnable();

	/**********************************************************************************************
	 *								Watchdog Initialization
	 *********************************************************************************************/
	WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF);	//Set the timer for a reset
	WatchdogIntRegister(WATCHDOG_BASE,WatchdogIntHandler);			//Enable interrupt
	WatchdogIntClear(WATCHDOG_BASE);
	WatchdogIntEnable(WATCHDOG_BASE);
	WatchdogEnable(WATCHDOG_BASE);	//Enable the actual timer
	IntEnable(INT_WATCHDOG);

	/**********************************************************************************************
	 *								Preflight motor inialization maybe not necessary not going to test
	 *********************************************************************************************/

	PWMSet(TIMER0_BASE,998);
	PWMSet(TIMER1_BASE,998);
	PWMSet(TIMER2_BASE,998);
	PWMSet(TIMER3_BASE,998);
	recievedCommands[0]=253;
	SysCtlDelay((SysCtlClockGet() / (1000 * 3))*100);	//Very important to ensure motor see's a start high (998 makes 0 sense but it works so shhhh don't tell anyone)
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);

	while(1){
		WatchdogReloadSet(WATCHDOG_BASE, 0xFEEFEEFF);	//Feed the dog a new time

		//UARTSend(recievedCommands[0]);
		//SysCtlDelay(50000);
		//Set 4 PWM Outputs

		//Get Acc data
		I2CRead(0x53,0x32,6,quadAcc);			//Address blah blah 2 for each axis
		rawAccToG(quadAcc,RwAcc);
		/*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x04);		//Blue

		//Get Gyro data
		/**************************************
		  Gyro ITG-3200 I2C
		  registers:
		  temp MSB = 1B, temp LSB = 1C
		  x axis MSB = 1D, x axis LSB = 1E
		  y axis MSB = 1F, y axis LSB = 20
		  z axis MSB = 21, z axis LSB = 22
		 *************************************/
		I2CRead(0x68,0x1B,8,quadGyro);			//Address blah blah 2 for each axis + 2 for temperature. why. because why not
		rawGyroToDegsec(quadGyro,Gyro_ds);
		//GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x02);		//Red

		//Get the actual angles in XYZ. Store them in RwEst
		//getInclination(RwAcc, RwEst, RwGyro, Gyro_ds, Awz);
		//After this function is called RwEst will hold the roll pitch and yaw
		//RwEst will be returned in PITCH, ROLL, YAW 0, 1, 2 remember this order very important. Little obvious but yaw is worthless

		/*if(RwEst[1]>0.5){
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);		//Red Blue, Correct data read in
		}else{
			GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x0A);		//Red Green, The correct data is not there
		}*/
		/*GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,0x06);		//Red Blue, Correct data read in
		float test=RwAcc[0]*100;		//These two commands work
		char temp = (char)test;
		//UARTSend((char)(RwAcc[0])*100);	//This one does not
		UARTSend(temp);
		//UARTSend((char)(RwAcc[1])*100);

		UARTSend(0xAA);
		SysCtlDelay((SysCtlClockGet() / (1000 * 3))*1);
		 */
	}

}
示例#17
0
/** Ask the value to the device */
void srf08_receive(void) {
LED_OFF(2);
  srf_trans.buf[0] = SRF08_ECHO_1;
  srf08_received = TRUE;
  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 1);
}
示例#18
0
void humid_sht_event( void ) {
  if (sht_trans.status == I2CTransSuccess) {
    switch (sht_status) {

    case SHT_TRIG_TEMP:
      sht_status = SHT_GET_TEMP;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_READ_TEMP:
      /* read temperature */
      tempsht = (sht_trans.buf[0] << 8) | sht_trans.buf[1];
      tempsht &= 0xFFFC;
      if (humid_sht_crc(sht_trans.buf) == 0) {
        /* trigger humid measurement, no master hold */
        sht_trans.buf[0] = SHT_TRIGGER_HUMID;
        sht_status = SHT_TRIG_HUMID;
        I2CTransmit(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 1);
      }
      else {
        /* checksum error, restart */
        sht_status = SHT_IDLE;
        sht_trans.status == I2CTransDone;
      }
      break;

    case SHT_TRIG_HUMID:
      sht_status = SHT_GET_HUMID;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_READ_HUMID:
      /* read humidity */
      humidsht = (sht_trans.buf[0] << 8) | sht_trans.buf[1];
      humidsht &= 0xFFFC;
      fhumidsht = -6. + 125. / 65536. * humidsht;
      ftempsht = -46.85 + 175.72 / 65536. * tempsht;

      sht_status = SHT_IDLE;
      sht_trans.status = I2CTransDone;

      if (humid_sht_crc(sht_trans.buf) == 0) {
        DOWNLINK_SEND_SHT_STATUS(DefaultChannel, &humidsht, &tempsht, &fhumidsht, &ftempsht);
      }
      break;

    case SHT_RESET:
      sht_status = SHT_SERIAL;
      sht_trans.status = I2CTransDone;
      break;

    case SHT_SERIAL1:
      /* read serial number part 1 */
      sht_serial[5] = sht_trans.buf[0];
      sht_serial[4] = sht_trans.buf[2];
      sht_serial[3] = sht_trans.buf[4];
      sht_serial[2] = sht_trans.buf[6];
      /* get serial number part 2 */
      sht_status = SHT_SERIAL2;
      sht_trans.buf[0] = 0xFC;
      sht_trans.buf[1] = 0xC9;
      I2CTransceive(SHT_I2C_DEV, sht_trans, SHT_SLAVE_ADDR, 2, 6);
      break;

    case SHT_SERIAL2:
      /* read serial number part 2 */
      sht_serial[1] = sht_trans.buf[0];
      sht_serial[0] = sht_trans.buf[1];
      sht_serial[7] = sht_trans.buf[3];
      sht_serial[6] = sht_trans.buf[4];
      sht_serial1=sht_serial[7]<<24|sht_serial[6]<<16|sht_serial[5]<<8|sht_serial[4];
      sht_serial2=sht_serial[3]<<24|sht_serial[2]<<16|sht_serial[1]<<8|sht_serial[0];
      DOWNLINK_SEND_SHT_SERIAL(DefaultChannel, &sht_serial1, &sht_serial2);
      sht_status = SHT_IDLE;
      sht_trans.status = I2CTransDone;
      break;

    default:
      sht_trans.status = I2CTransDone;
      break;
    }
  }
}
示例#19
0
void srf08_initiate_ranging(void) {
LED_ON(2);
  srf_trans.buf[0] = SRF08_COMMAND;
  srf_trans.buf[1] = SRF08_CENTIMETERS;
  I2CTransmit(SRF08_I2C_DEV, srf_trans, SRF08_UNIT_0, 2);
}
示例#20
0
void stop_com( void ) {
    active_com = FALSE;
    com_trans.buf[0] = active_com;
    I2CTransmit(GENERIC_COM_I2C_DEV, com_trans, GENERIC_COM_SLAVE_ADDR, 1);
}