Esempio n. 1
0
void imu_impl_init(void)
{
  /////////////////////////////////////////////////////////////////////
  // ITG3200
  itg3200_init();

  /////////////////////////////////////////////////////////////////////
  // ADXL345
  adxl345_init();

}
Esempio n. 2
0
void imu_impl_init(void)
{
  /////////////////////////////////////////////////////////////////////
  // ITG3200
  itg3200_init();

  /////////////////////////////////////////////////////////////////////
  // ADXL345
  adxl345_init();

  /////////////////////////////////////////////////////////////////////
  // HMC58XX
  hmc58xx_init();
}
Esempio n. 3
0
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
#if (ARCH == ARCH_AVR8)
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);
#elif (ARCH == ARCH_XMEGA)
	/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
	XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
	XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);

	/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
	XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
	XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);

	PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif

	/* Hardware Initialization */
	//i2c
	TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 400000));

	//button ports init
	buttons_init();

	//timer init
	TCCR1B |=(1<<CS10)|(1<<CS12);//prescaler 1024
	TCNT1 = 0;//init counter

	//screen setup - software spi, sh1106 driver (sh1306 analog)
	/* Atmega32U4 mapping:
	    SCK (D0) - PORTB, PIN1 == PN(1, 1)
	    MOSI (D1) - PORTB, PIN2
	    RES	(RST) - PORTB, PIN0
	    A0 (DC) - PORTB, PIN5 (OC1A/#A9)
	 */
	display_init();
	display_draw_logo();

	//sensors initialization
	adxl345_init(MEASURE_ON, RANGE_2G, ODR_800);
	l3g4200d_init(FIFO_HI_LO_PASS, NORM_ODR_800);
	hmc5883l_init(MODE_CONT, GAIN_4_7, NORM_75HZ_8AV);

	USB_Init();
}
Esempio n. 4
0
//init and start adxl345
void ADXL345_Init_Start(int i2c_bus_handle, unsigned char sensor_addr, unsigned char *statusPeripheralOutput)
{
if(i2c_bus_handle>=0)
{
	//init adxl
	if(!adxl345_init(i2c_bus_handle, sensor_addr))
	{
		printf("init adxl fail\n");
		//return errno;
		*statusPeripheralOutput &= ~(1<<BIT_ADXL345_READY);
	}
	else
	{
		*statusPeripheralOutput |= (1<<BIT_ADXL345_READY);
	}
#if VERBOSE==1
	printf("adxl345 init success\r\n");
#endif	
	
	//start adxl
	if(!adxl345_start(i2c_bus_handle, sensor_addr))
	{
		printf("cannot start adxl\n");
		//return errno;
		*statusPeripheralOutput &= ~(1<<BIT_ADXL345_READY);
	}
	else
	{
		*statusPeripheralOutput |= (1<<BIT_ADXL345_READY);
	}
#if VERBOSE==1
	printf("adxl345 started\r\n");
#endif	
}
else
{
#if VERBOSE==1
	printf("i2c bus not ready\r\n");
#endif	
}
}
Esempio n. 5
0
int main (int argc, char **argv) {
    int16_t *raw;
    float *acc;

    // Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
    adxl345_init();

    while(1) {
        adxl345_update(); // Update the data
        //raw = adxl345_getrawvalues(); // Read raw sensor data
        acc = adxl345_getacceleration(); // Read acceleration (g)
        // +-1%
        fprintf(stdout, "Current scale: 0x%2xg\n", adxl345_getscale());
        //fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
        fprintf(stdout, "AccX: %5.2f g\n", acc[0]); 
        fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
        fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
//        sleep(1);
    }
    return 0;
}
Esempio n. 6
0
int main(void){

int fd;
	struct acc_dat acc_xyz;
	fd = wiringPiI2CSetup(DevAddr);

	if(-1 == fd){
		perror("I2C device setup error"); 
	}
	adxl345_init(fd);
	printf("-----> ACCELEROMETER INITIALIZED\n");
	
	while (1) { 

        acc_xyz = adxl345_read_xyz(fd);
	printf("x: %05d, y: %05d, z: %05d\n", acc_xyz.x, acc_xyz.y, acc_xyz.z);	
	
delay(500);
}

return 0;
} 
Esempio n. 7
0
/*#####################################################*/
bool board_init()
{
	core_init();
	timer_init();
	RtcInit();
/*-----------------------------------------------------*/
/* Set up the Uart 0 like debug interface with RxBuff = 256, TxBuff = 256, 115200b/s*/
	Uart[0] = new_(new_uart);
	Uart[0]->TxPin = Uart0_Tx_PinMux_E16;
	Uart[0]->RxPin = Uart0_Rx_PinMux_E15;
	Uart[0]->BaudRate = 115200;
	Uart[0]->RxBuffSize = 256;
	Uart[0]->TxBuffSize = 256;
	Uart[0]->rxFifoTrigLevel = 1;
	Uart[0]->txFifoTrigLevel = 1;
	Uart[0]->UartNr = 0;
	uart_open(Uart[0]);
	DebugCom = Uart[0];
/*-----------------------------------------------------*/
	LED[0] = gpio_assign(1, 21, GPIO_DIR_OUTPUT, false);
	LED[1] = gpio_assign(1, 22, GPIO_DIR_OUTPUT, false);
	LED[2] = gpio_assign(1, 23, GPIO_DIR_OUTPUT, false);
	LED[3] = gpio_assign(1, 24, GPIO_DIR_OUTPUT, false);
/*-----------------------------------------------------*/
	/* Display board message*/
#if defined(BOARD_MESSAGE)
	UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE);
#endif
/*-----------------------------------------------------*/
/* Set up the Twi 0 to communicate with PMIC and the Onboard serial EEprom memory */
	UARTPuts(DebugCom, "Setup TWI 0 with RxBuff = 258, TxBuff = 258....." , -1);
	TWI[0] = new_(new_twi);
	TWI[0]->SdaPin = Twi0_Sda_PinMux_C17;
	TWI[0]->SclPin = Twi0_Scl_PinMux_C16;
	TWI[0]->BaudRate = 100000;
	TWI[0]->TwiNr = 0;
	TWI[0]->Priority = 0;
	TWI[0]->UseInterrupt = TRUE;
	TWI[0]->RxBuffSize = 258;
	TWI[0]->TxBuffSize = 258;
	twi_open(TWI[0]);
	UARTPuts(DebugCom, "OK.\n\r" , -1);
/*-----------------------------------------------------*/
	if(!is_beaglebone()) return false;
/*-----------------------------------------------------*/
/* Set up the Twi 1 to communicate with PMIC and the Onboard serial EEprom memory */
	UARTPuts(DebugCom, "Setup TWI 1 with RxBuff = 258, TxBuff = 258....." , -1);
	TWI[1] = new_(new_twi);
	TWI[1]->SdaPin = Twi1_Sda_PinMux_B16;
	TWI[1]->SclPin = Twi1_Scl_PinMux_A16;
	TWI[1]->BaudRate = 100000;
	TWI[1]->TwiNr = 1;
	TWI[1]->Priority = 0;
	TWI[1]->UseInterrupt = TRUE;
	TWI[1]->RxBuffSize = 258;
	TWI[1]->TxBuffSize = 258;
	twi_open(TWI[1]);
	UARTPuts(DebugCom, "OK.\n\r" , -1);
/*-----------------------------------------------------*/
/* Set up the Twi 2 to communicate with PMIC and the Onboard serial EEprom memory */
	UARTPuts(DebugCom, "Setup TWI 2 with RxBuff = 258, TxBuff = 258....." , -1);
	TWI[2] = new_(new_twi);
	TWI[2]->SdaPin = Twi2_Sda_PinMux_D18;
	TWI[2]->SclPin = Twi2_Scl_PinMux_D17;
	TWI[2]->BaudRate = 100000;
	TWI[2]->TwiNr = 2;
	TWI[2]->Priority = 0;
	TWI[2]->UseInterrupt = TRUE;
	TWI[2]->RxBuffSize = 258;
	TWI[2]->TxBuffSize = 258;
	twi_open(TWI[2]);
	UARTPuts(DebugCom, "OK.\n\r" , -1);
/*-----------------------------------------------------*/
	beaglebone_detect_extension_boards();
/*-----------------------------------------------------*/
#if USE_ADXL345
	ADXL345_1 = new_(new_adxl345);
	ADXL345_1->MasterSlaveAddr = ADXL345_SLAVE_ADDR_ALT_0;
	ADXL345_1->TwiStruct = TWI[2];
	ADXL345_1->Calibration_X = -14;
	ADXL345_1->Calibration_Y = 11;
	ADXL345_1->Calibration_Z = 24;
	ADXL345_1->FilterBuffSize = 4;
	if(adxl345_init(ADXL345_1))
	{
		UARTPuts(DebugCom, "ADXL345 detected on TWI2.\n\r" , -1);
	}
	else
	{
		if(ADXL345_1) free(ADXL345_1);
		UARTPuts(DebugCom, "ADXL345 not detected.\n\r" , -1);
	}
#endif
/*-----------------------------------------------------*/
	UARTPuts(DebugCom, "Init MMCSD0 .......", -1);
	sdCtrl[0].SdNr = 0;
	mmcsd_init(&sdCtrl[0], 0, 6, LED[0]);
	UARTPuts(DebugCom, "OK.\n\r", -1);
    mmcsd_idle(&sdCtrl[0]);
/*-----------------------------------------------------*/
	eMMC_Res = gpio_assign(1, 20, GPIO_DIR_OUTPUT, false);
	gpio_out(eMMC_Res, 0);
	Sysdelay(10);
	gpio_out(eMMC_Res, 1);
	UARTPuts(DebugCom, "Init MMCSD1 .......", -1);
	sdCtrl[1].SdNr = 1;
	mmcsd_init(&sdCtrl[1], -1, -1, LED[0]);
	UARTPuts(DebugCom, "OK.\n\r", -1);
    mmcsd_idle(&sdCtrl[1]);
/*-----------------------------------------------------*/
#ifdef usb_1_msc
	UARTPuts(DebugCom, "Init USBMSC1 Host.......", -1);
	usb_msc_host_init(1, LED[2]);
	UARTPuts(DebugCom, "OK.\n\r", -1);
    usb_msc_host_idle(1);
#elif defined( usb_1_mouse ) && !defined( touch )
/*-----------------------------------------------------*/
	UARTPuts(DebugCom, "Init USBMOUSE1 Host.......", -1);
	usb_mouse_host_init(1);
	UARTPuts(DebugCom, "OK.\n\r", -1);
#endif
/*-----------------------------------------------------*/
#if defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToMmcSd0)
	UARTPuts(DebugCom, "Bridge USBMSC0 Dev for MMCSD0 Interface.......", -1);
	drv_rw_func.DriveStruct = &sdCtrl[0];
	drv_rw_func.drv_ioctl_func = mmcsd_ioctl;
	drv_rw_func.drv_r_func = mmcsd_read;
	drv_rw_func.drv_w_func = mmcsd_write;
	usb_msc_dev_init(0);
	UARTPuts(DebugCom, "OK.\n\r", -1);
/*-----------------------------------------------------*/
#elif  defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToMmcSd1)
	UARTPuts(DebugCom, "Bridge USBMSC0 Dev for MMCSD1 Interface.......", -1);
	drv_rw_func.DriveStruct = &sdCtrl[1];
	drv_rw_func.drv_ioctl_func = mmcsd_ioctl;
	drv_rw_func.drv_r_func = mmcsd_read;
	drv_rw_func.drv_w_func = mmcsd_write;
	usb_msc_dev_init(0);
	UARTPuts(DebugCom, "OK.\n\r", -1);
/*-----------------------------------------------------*/
#elif  defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToUsbHost1) && defined(usb_1_msc) && !defined(usb_1_mouse)
extern unsigned int g_ulMSCInstance0Usb1;//UsbMsc driver
	UARTPuts(DebugCom, "Bridge USBMSC0 Dev for USBMSC1Host Interface.......", -1);
	drv_rw_func.DriveStruct = (void *)g_ulMSCInstance0Usb1;
	drv_rw_func.drv_ioctl_func = usb_msc_host_ioctl;
	drv_rw_func.drv_r_func = usb_msc_host_read;
	drv_rw_func.drv_w_func = usb_msc_host_write;
	usb_msc_dev_init(0);
	UARTPuts(DebugCom, "OK.\n\r", -1);
#endif
/*-----------------------------------------------------*/
#ifdef lcd
	TouchScreen = new_(new_touchscreen);
	TouchScreen->TwiStruct = TWI[1];
#endif
	bool LCD3_Cape_Detected = false;
	if(Board1ConfigData) if(!memcmp(Board1ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true;
	if(Board2ConfigData) if(!memcmp(Board2ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true;
	if(Board3ConfigData) if(!memcmp(Board3ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true;
	if(Board4ConfigData) if(!memcmp(Board4ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true;
	if(LCD3_Cape_Detected)
	{
/*-----------------------------------------------------*/
		HARDBTN[0] = gpio_assign(1, 16, GPIO_DIR_INPUT, false);
		HARDBTN[1] = gpio_assign(1, 17, GPIO_DIR_INPUT, false);
		HARDBTN[2] = gpio_assign(3, 19, GPIO_DIR_INPUT, false);
		HARDBTN[3] = gpio_assign(1, 28, GPIO_DIR_INPUT, false);
		HARDBTN[4] = gpio_assign(0, 7, GPIO_DIR_INPUT, false);
/*-----------------------------------------------------*/
		LED[4] = gpio_assign(1, 28, GPIO_DIR_OUTPUT, false);
		LED[5] = gpio_assign(1, 18, GPIO_DIR_OUTPUT, false);
/*-----------------------------------------------------*/
#ifdef lcd
		ScreenBuff = new_(new_screen);
		ScreenBuff->raster_timings = &lcd_S035Q01_beaglebone_exp;
		ScreenBuff->BackLightLevel = 60;
		ScreenBuff->PmicTwiModuleStruct = TWI[0];
		screen_init(ScreenBuff);
		UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size);

		TouchScreen->screen_max_x = (double)ScreenBuff->raster_timings->X;
		TouchScreen->screen_max_y = (double)ScreenBuff->raster_timings->Y;
		TouchScreen->pDisplay = ScreenBuff;
		InitTouchScreen(TouchScreen);
		UARTPuts(DebugCom, "Init calibration of LCD resistive touch screen....." , -1);
		TouchCalibrate(TouchScreen, ScreenBuff);
		UARTPuts(DebugCom, "OK.\n\r" , -1);
		put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren);
		box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y);
#endif
	}
	else
	{
#ifdef lcd
		if(ft5x06_init(TouchScreen, 0, 30))
		{
			UARTPuts(DebugCom, "Capacitive touch screen detected and set up successful.\n\r" , -1);
#endif
			UARTPuts(DebugCom, "I suppose that is BeagleBone Multimedia cape from Chipsee.\n\r" , -1);
/*-----------------------------------------------------*/
			HARDBTN[0] = gpio_assign(1, 19, GPIO_DIR_INPUT, false);
			HARDBTN[1] = gpio_assign(1, 16, GPIO_DIR_INPUT, false);
			HARDBTN[2] = gpio_assign(1, 17, GPIO_DIR_INPUT, false);
			HARDBTN[3] = gpio_assign(0, 7, GPIO_DIR_INPUT, false);
			//HARDBTN[4] = gpio_assign(1, 3, GPIO_DIR_INPUT, false); If you use BBB this pin is used by the DAT3 of eMMC onboard memory(if you want to use this pin you will use the eMMC in 1 bit data bus mode).
/*-----------------------------------------------------*/
#ifdef lcd
			ScreenBuff = new_(new_screen);
			ScreenBuff->raster_timings = &lcd_AT070TN92_beaglebone_exp;
			ScreenBuff->BackLightPort = 1;
			ScreenBuff->BackLightPin = 18;
			screen_init(ScreenBuff);
			TouchScreen->screen_max_x = ScreenBuff->raster_timings->X;
			TouchScreen->screen_max_y = ScreenBuff->raster_timings->Y;
			TouchScreen->pDisplay = ScreenBuff;
			UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size);
			put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren);
			box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y);
			backlight_on(ScreenBuff);
		}
		else
		{
			//UARTPuts(DebugCom, "No display detected.\n\r" , -1);
			//free_touchscreen(TouchScreen);
			UARTPuts(DebugCom, "I suppose that is BeagleBone Multimedia cape from Chipsee.\n\r" , -1);
/*-----------------------------------------------------*/
			HARDBTN[0] = gpio_assign(1, 19, GPIO_DIR_INPUT, false);
			HARDBTN[1] = gpio_assign(1, 16, GPIO_DIR_INPUT, false);
			HARDBTN[2] = gpio_assign(1, 17, GPIO_DIR_INPUT, false);
			HARDBTN[3] = gpio_assign(0, 7, GPIO_DIR_INPUT, false);
			//HARDBTN[4] = gpio_assign(1, 3, GPIO_DIR_INPUT, false);
/*-----------------------------------------------------*/
			ScreenBuff = new_(new_screen);
			ScreenBuff->raster_timings = &HDMI_DISPLAY_MODE_STRUCT;
			ScreenBuff->BackLightPort = 1;
			ScreenBuff->BackLightPin = 18;
			screen_init(ScreenBuff);
#ifdef touch
			TouchScreen->screen_max_x = ScreenBuff->raster_timings->X;
			TouchScreen->screen_max_y = ScreenBuff->raster_timings->Y;
			TouchScreen->pDisplay = ScreenBuff;
			InitTouchScreen(TouchScreen);
			UARTPuts(DebugCom, "Init calibration of LCD resistive touch screen....." , -1);
			TouchCalibrate(TouchScreen, ScreenBuff);
			UARTPuts(DebugCom, "OK.\n\r" , -1);
#endif
			UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size);
			put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren);
			box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y);
			backlight_on(ScreenBuff);
		}
#endif
	}
	return true;
}
Esempio n. 8
0
int main() {

	usartInit(57600);
	usartEnableReceiver();
	usartEnableTransmitter();
	usartStdio();

	setBit(DDRB, M1_DIR);
	setBit(DDRD, M1_PWM);
	setBit(DDRD, M2_DIR);
	setBit(DDRD, M2_PWM);

	clrBit(PORTB, M1_DIR);
	clrBit(PORTD, M1_PWM);
	clrBit(PORTD, M2_PWM);
	clrBit(PORTD, M2_DIR);

	timer0FastPWMMaxMode();
	timer0ClockPrescaller64();
	timer0OC0ANonInvertedMode();
	timer0OC0BNonInvertedMode();
	timer0SetCompareAValue(0);
	timer0SetCompareBValue(0);
	timer0DeactivateCompareAInterrupt();
	timer0DeactivateCompareBInterrupt();

	timer2ClockPrescaller256();
	timer2NormalMode();
	timer2OC2AOff();
	timer2OC2BOff();
	timer2ActivateOverflowInterrupt();


	i2c_init();

	adxl345_init();

	l3g4200d_init();
	l3g4200d_setoffset(0.11, -1.71, -0.46);
	//l3g4200d_settemperatureref();

	PID_init(&PID, 15,0.2,1, 0);
	PID_SetMode(&PID, 1);
	PID_SetOutputLimits(&PID, -255, 255);

	PID.mySetpoint = 0;

	motor1(0);
	motor2(0);


//	printf("\e[1;1H\e[2J");
//	printf("STARTED!\r\n");
//	_delay_ms(200);

//	motor1(120);
//	printf("Motor1 = 120\r\n");
//	_delay_ms(500);
//	motor1(-120);
//	printf("Motor1 = -120\r\n");
//	_delay_ms(500);
//	motor1(120);
//	printf("Motor1 = 120\r\n");
//	_delay_ms(500);
//	motor1(0);
//	printf("Motor1 = 0\r\n");

	sei();

	while(1);

	return 0;
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
  uint8_t value;
  switch (type) {

    case SENSORS_HW_INIT:
      if (adxl345_available()) {
        ready = 1;
      } else {
        ready = 0;
      }
      break;

    case SENSORS_ACTIVE:
      if (c) {
        return acc_active = (adxl345_init() == 0) ? 1 : 0;
      } else {
        adxl345_deinit();
        return 1;
      }
      break;

    case ACC_CONF_SENSITIVITY:
      // map to register settings
      switch (c) {
        case ACC_2G:
          value = ADXL345_MODE_2G;
          break;
        case ACC_4G:
          value = ADXL345_MODE_4G;
          break;
        case ACC_8G:
          value = ADXL345_MODE_8G;
          break;
        case ACC_16G:
          value = ADXL345_MODE_16G;
          break;
        default:
          return 0;
          break;
      }
      adxl345_set_g_range(value);
      return TRUE;
      break;

    case ACC_CONF_FIFOMODE:
      // map to register settings
      switch (c) {
        case ACC_MODE_BYPASS:
          value = ADXL345_MODE_BYPASS;
          break;
        case ACC_MODE_FIFO:
          value = ADXL345_MODE_FIFO;
          break;
        case ACC_MODE_STREAM:
          value = ADXL345_MODE_STREAM;
          break;
        default:
          return 0;
          break;
      }
      adxl345_set_fifomode(value);
      return TRUE;
      break;

    case ACC_CONF_POWERMODE:
      // TODO: implementation needed
      return 0;
      break;

    case ACC_CONF_DATA_RATE:
      if (c <= ACC_0HZ10) {
        value = ADXL345_ODR_0HZ10;
      } else if (c <= ACC_0HZ20) {
        value = ADXL345_ODR_0HZ20;
      } else if (c <= ACC_0HZ39) {
        value = ADXL345_ODR_0HZ39;
      } else if (c <= ACC_0HZ78) {
        value = ADXL345_ODR_0HZ78;
      } else if (c <= ACC_1HZ56) {
        value = ADXL345_ODR_1HZ56;
      } else if (c <= ACC_3HZ13) {
        value = ADXL345_ODR_3HZ13;
      } else if (c <= ACC_6HZ25) {
        value = ADXL345_ODR_6HZ25;
      } else if (c <= ACC_12HZ5) {
        value = ADXL345_ODR_12HZ5;
      } else if (c <= ACC_25HZ) {
        value = ADXL345_ODR_25HZ;
      } else if (c <= ACC_50HZ) {
        value = ADXL345_ODR_50HZ;
      } else if (c <= ACC_100HZ) {
        value = ADXL345_ODR_100HZ;
      } else if (c <= ACC_200HZ) {
        value = ADXL345_ODR_200HZ;
      } else if (c <= ACC_400HZ) {
        value = ADXL345_ODR_400HZ;
      } else if (c <= ACC_800HZ) {
        value = ADXL345_ODR_800HZ;
      } else if (c <= ACC_1600HZ) {
        value = ADXL345_ODR_1600HZ;
      } else if (c <= ACC_3200HZ) {
        value = ADXL345_ODR_3200HZ;
      } else {
        return 0;
      }
      adxl345_set_data_rate(value);
      return 1;
      break;

  }
  return 0;
}
Esempio n. 10
0
PROCESS_THREAD(default_app_process, ev, data)
{
  PROCESS_BEGIN();
  printf("Hello, world\n");

  _delay_ms(100);

#if DEBUG
  printf("Begin initialization:\n");

  if (microSD_init() == 0) {
    printf(":microSD   OK\n");
    microSD_switchoff();
  } else {
    printf(":microSD   FAILURE\n");
  }
  if (adxl345_init() == 0) {
    printf(":ADXL345   OK\n");
  } else {
    printf(":ADXL345   FAILURE\n");
  }
  if (at45db_init() == 0) {
    printf(":AT45DBxx  OK\n");
  } else {
    printf(":AT45DBxx  FAILURE\n");
  }
//  if (bmp085_init() == 0) {
//    printf(":BMP085    OK\n");
//  } else {
//    printf(":BMP085    FAILURE\n");
//  }
//  if (l3g4200d_init() == 0) {
//    printf(":L3G4200D  OK\n");
//  } else {
//    printf(":L3G4200D  FAILURE\n");
//  }
#else
  adxl345_init();
  microSD_switchoff();
  at45db_init();
  microSD_init();
  bmp085_init();
  l3g4200d_init();
#endif

  adc_init(ADC_SINGLE_CONVERSION, ADC_REF_2560MV_INT);
  etimer_set(&timer, CLOCK_SECOND * 0.05);

  while (1) {

    PROCESS_YIELD();
    etimer_set(&timer, CLOCK_SECOND);
    int16_t tmp;
    /*############################################################*/
    //ADXL345 serial Test
    printf("X:%+6d | Y:%+6d | Z:%+6d\n",
            adxl345_get_x_acceleration(),
            adxl345_get_y_acceleration(),
            adxl345_get_z_acceleration());

    /*############################################################*/
    //L3G4200d serial Test
    printf("X:%+6d | Y:%+6d | Z:%+6d\n",
            l3g4200d_get_x_angle(),
            l3g4200d_get_y_angle(),
            l3g4200d_get_z_angle());
    printf("T1:%+3d\n", l3g4200d_get_temp());

    /*############################################################*/
    //BMP085 serial Test
    printf("P:%+6ld\n", (uint32_t) bmp085_read_pressure(BMP085_HIGH_RESOLUTION));
    printf("T2:%+3d\n", bmp085_read_temperature());

    /*############################################################*/
    //Power Monitoring
    printf("V:%d\n", adc_get_value_from(PWR_MONITOR_ICC_ADC));
    //              tmp = adc_get_value_from(PWR_MONITOR_ICC_ADC);
    //             
    //              tmp = adc_get_value_from(PWR_MONITOR_VCC_ADC);
    //             
    /*############################################################*/
    //microSD Test
    //              uint8_t buffer[512];
    //              uint16_t j;
    //              microSD_init();
    //              for (j = 0; j < 512; j++) {
    //                      buffer[j] = 'u';
    //                      buffer[j + 1] = 'e';
    //                      buffer[j + 2] = 'r';
    //                      buffer[j + 3] = '\n';
    //
    //                      j = j + 3;
    //              }
    //
    //              microSD_write_block(2, buffer);
    //
    //              microSD_read_block(2, buffer);
    //
    //              for (j = 0; j < 512; j++) {
    //                      printf(buffer[j]);
    //              }
    //              microSD_deinit();
    //
    /*############################################################*/
    //Flash Test
    //    uint8_t buffer[512];
    //    uint16_t j, i;
    //
    //    for (i = 0; i < 10; i++) {
    //      //at45db_erase_page(i);
    //      for (j = 0; j < 512; j++) {
    //        buffer[j] = i;
    //      }
    //      at45db_write_buffer(0, buffer, 512);
    //
    //      at45db_buffer_to_page(i);
    //
    //      at45db_read_page_bypassed(i, 0, buffer, 512);
    //
    //      for (j = 0; j < 512; j++) {
    //        printf("%02x", buffer[j]);
    //        if (((j + 1) % 2) == 0)
    //          printf(" ");
    //        if (((j + 1) % 32) == 0)
    //          printf("\n");
    //      }
    //    }

  }


  PROCESS_END();
}