示例#1
0
static int aConfigure(int aFile)
{
    CHECK(ADXL345_Init(aFile, ADXL345_ID, true));

    struct ADXL345_DataFormat confDataFormat = {
        .range = ADXL345_RANGE_2G,
    };
    CHECK(ADXL345_ConfigureDataFormat(aFile, &confDataFormat));

    struct ADXL345_Power confPowerControl = {
        .measurement = true,
    };
    CHECK(ADXL345_ConfigurePower(aFile, &confPowerControl));

    return 0;
}

static int cConfigure(int cFile)
{
    CHECK(HMC5883L_Init(cFile, HMC5883L_ID, true));

    struct HMC5883L conf = {
        .gain = HMC5883L_GAIN_1090,
        .measurementMode = HMC5883L_MEASUREMENTMODE_NORMAL,
        .outputRate = HMC5883L_OUTPUTRATE_30,
        .samples = HMC5883L_SAMPLES_2,
    };
    CHECK(HMC5883L_Configure(cFile, &conf));

    CHECK(HMC5883L_SetContinuousMeasurement(cFile));

    return 0;
}
/**************************************************************************************************
* Function ACCEL_Start()
* -------------------------------------------------------------------------------------------------
* Overview: Function Initialize I2C bus and accel module
* Input: Nothing
* Output: test status: 0 - skiped; 1 - pass; 2 - fail
**************************************************************************************************/
void ACCEL_Start(char *test)
{
  // Reset error flag
  *test = 0;
  
  // Initialize I2C communication
  I2C2_Init(250000);

  TFT_Set_Font(TFT_defaultFont, CL_WHITE, FO_HORIZONTAL);
  TFT_Set_Pen(bg_color, 1);
  TFT_Set_Brush(1, bg_color, 0, 0, 0, 0);

  TFT_Write_Text("Starting Accel test...", 90, 100);
  Delay_ms(2000);
  TFT_Rectangle(70, 70, 250, 130);
  
  // Initialize ADXL345 accelerometer
  if (ADXL345_Init() == 0)
  {
    TFT_Write_Text("Accel module initialized.", 90, 100);
    *test = 1;
    Delay_ms(2000);
  }
  else
  {
    TFT_Write_Text("Error during Accel module initialization.", 90, 100);
    *test = 2;
  }
    
  TFT_Rectangle(70, 70, 250, 130);
}
示例#3
0
uint8_t init_speedy(void){

	uint8_t data = 0x00;

	//Init I2C 1
	if(init_i2c(I2C_1) != 0)
		return 1;

	//Pyro Sensor
	if(write_i2c(I2C_1, ADDR_TPA81, &data, 1) != 1)
		return 11;

	//SRF08 hinten links
	if(write_i2c(I2C_1, SRF_HL, &data, 1) != 1)
		return 12;

	//SRF08 vorne
	if(write_i2c(I2C_1, SRF_V, &data, 1) != 1)
		return 13;

	//SRF08 hinten rechts
	if(write_i2c(I2C_1, SRF_HR, &data, 1) != 1)
		return 14;

	//Init I2C 2
	if(init_i2c(I2C_2) != 0)
		return 2;

	//HMC6343
	if(write_i2c(I2C_2, ADDR_HMC, &data, 1) != 1)
		return 21;

	//MAX11613
	if(write_i2c(I2C_2, ADDR_MAX11613, &data, 1) != 1)
		return 22;

	//LCD
	if(write_i2c(I2C_2, LCD03_ADRESS, &data, 1) != 1)
		return 23;

	//ITG3200
	if(write_i2c(I2C_2, ADDR_ITG, &data, 1) != 1)
		return 24;

	//Init Motor Modul
	if(init_itg() != 0)
		return 3;

	//Init G Sensor ADXL345 on DE0 Nano SoC
	if(!ADXL345_Init())
		return 4;

	return 0;
}
示例#4
0
文件: main.c 项目: 363546178/no-OS
int main(void)
{
    // Configure system
	SystemConfiguration();

    // Configure SPI
	SPI_Init(SPI_BASEADDR, 0, 1, 1);

    // Initialize ADXL345 specific settings
	ADXL345_Init();

    // Initialize Interrupts
	InterruptsInit();

    // Run demo program
	DemoProgram();

	return(0);
}
示例#5
0
文件: main.c 项目: rmnsfx/DVA141
int main (void)
{
	volatile char temp = 1;
	volatile uint16_t temp1 = 1;
	volatile uint16_t temp2 = 1;
	volatile bool state = false;
	
	system_init();
	
	init_gpio();

	clock_output();
	
	delay_init();	
		
	configure_spi_master_AD5421();
	configure_spi_master_ADXL();
	
	AD5421_Init();	
	ADXL345_Init();
	
	//configure_extint_channel();		
	//configure_extint_callbacks();	
	//system_interrupt_enable_global();
	

	
	xTaskCreate(Testtask, "Testtask", configMINIMAL_STACK_SIZE, (void *)100, mainQUEUE_SEND_TASK_PRIORITY, NULL);
	vTaskStartScheduler();
	

	
	
	//X = ADXL345_GetX();
 	//Y = ADXL345_GetY();
 	//Z = ADXL345_GetZ();
	
}
示例#6
0



int main(int argc, char *argv[]){
	
	int file;
	const char *filename = "/dev/i2c-0";
	uint8_t id;
	bool bSuccess;
	const int mg_per_digi = 4;
	uint16_t szXYZ[3];
	int cnt=0, max_cnt=0;
	
	printf("===== gsensor test =====\r\n");
	
	if (argc == 2){
		max_cnt = atoi(argv[1]);
	}
	
	// open bus
	if ((file = open(filename, O_RDWR)) < 0) {
  	  /* ERROR HANDLING: you can check errno to see what went wrong */
	    perror("Failed to open the i2c bus of gsensor");
  	  exit(1);
	}
	

	// init	 
	// gsensor i2c address: 101_0011
	int addr = 0b01010011; 
	if (ioctl(file, I2C_SLAVE, addr) < 0) {
  	  printf("Failed to acquire bus access and/or talk to slave.\n");
	    /* ERROR HANDLING; you can check errno to see what went wrong */
  	  exit(1);
	}	
	

    // configure accelerometer as +-2g and start measure
    bSuccess = ADXL345_Init(file);
    if (bSuccess){
        // dump chip id
        bSuccess = ADXL345_IdRead(file, &id);
        if (bSuccess)
            printf("id=%02Xh\r\n", id);
    }        
    
    
    while(bSuccess && (max_cnt == 0 || cnt < max_cnt)){
        if (ADXL345_IsDataReady(file)){
            bSuccess = ADXL345_XYZ_Read(file, szXYZ);
            if (bSuccess){
	              cnt++;
                printf("[%d]X=%d mg, Y=%d mg, Z=%d mg\r\n", cnt,(int16_t)szXYZ[0]*mg_per_digi, (int16_t)szXYZ[1]*mg_per_digi, (int16_t)szXYZ[2]*mg_per_digi);
                // show raw data, 
                //printf("X=%04x, Y=%04x, Z=%04x\r\n", (alt_u16)szXYZ[0], (alt_u16)szXYZ[1],(alt_u16)szXYZ[2]);
                usleep(1000*1000);
            }
        }
    }
    
    if (!bSuccess)
        printf("Failed to access accelerometer\r\n");
	
		if (file)
			close(file);
			
		printf("gsensor, bye!\r\n");			
示例#7
0
文件: main.c 项目: dazuo78/TBall
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
	float x,y,z;
    short sx,sy,sz;
    unsigned char regVal;
    unsigned char regVals[29]; //0x1D~0x39
	/* STM32F103xG HAL library initialization:
	   - Configure the Flash prefetch
	   - Systick timer is configured by default as source of time base, but user 
		 can eventually implement his proper time base source (a general purpose 
		 timer for example or other time source), keeping in mind that Time base 
		 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
		 handled in milliseconds basis.
	   - Set NVIC Group Priority to 4
	   - Low Level Initialization
	*/
	HAL_Init();

	/* Configure the system clock to 72 MHz */
	SystemClock_Config();
    
    //uart
    BSP_COM_Init(COM1, &huart);

	/* Configure LED1 and LED3 */
	BSP_LED_Init(LED1);
	BSP_LED_Init(LED3);

	/* Configure Key push-button */
	BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

	/*##-1- Configure the I2C peripheral ######################################*/
	ADXL345_Init(ADXL345_I2C_COMM);
  
   
    // full resolution
    ADXL345_SetRangeResolution(ADXL345_RANGE_PM_2G, 1); 
    
    // enter measurement mode
    ADXL345_SetPowerMode(1);
    
    // self test mode
//    regVal = ADXL345_GetRegisterValue(ADXL345_DATA_FORMAT);
//    regVal |= ADXL345_SELF_TEST;
//    ADXL345_SetRegisterValue(ADXL345_DATA_FORMAT, regVal);
    // dump ADXL345 registers
    HAL_Delay(1);
    //ADXL345_GetMultiRegisterValue(ADXL345_THRESH_TAP, sizeof(regVals), regVals);

	/* Infinite loop */  
    printf("\n\r UART Printf Example: retarget the C library printf function to the UART\n\r");
	while (1)
	{
        
        ADXL345_GetGxyz(&x, &y, &z);
        printf("\n\rx: %.1f, y: %.1f, z: %.1f\n\r", x, y, z);
       // ADXL345_GetXyz(&sx, &sy, &sz);
       // printf("\n\rx: %d, y: %d, z: %d\n\r", sx, sy, sz);
        HAL_Delay(1000);
	}
}
示例#8
0
文件: PmodACL.c 项目: 070411209/no-OS
/***************************************************************************//**
 * @brief Main function.
 *
 * @return None.
*******************************************************************************/
void main(void)
{
    /* Set pin 7 and pin 8 (J11 connector) as input, to avoid the output pins
    of the Pmod ACL to be connected to an output pin of the microcontroller. */
    PM7 |= (1 << 6);    // P76 (PMOD-IRQA)
    PM7 |= (1 << 7);    // P77 (PMOD-IRQB)
    
    /* Initialize RDKRL78G14. */
    RDKRL78G14_Init();
    
    /* Enable interrupts. */
    __enable_interrupt();
        
    /* Initialize timer. */
    TIME_Init();
    
    /* Initialize the ST7579 Display. */
    ST7579_Init();
    
    /* Initialize ADXL345. */
    if(ADXL345_Init(ADXL345_SPI_COMM) == 0)
    {
        ADI_Component("ADXL345 OK");
    }
    else
    {
        ADI_Component("ADXL345 Error");
    }
    ADXL345_SetTapDetection(ADXL345_SINGLE_TAP |
                            ADXL345_DOUBLE_TAP, // Tap type.
                            ADXL345_TAP_Z_EN,   // Axis control.
                            0x10,               // Tap duration.
                            0x10,               // Tap latency.
                            0x40,               // Tap window. 
                            0x10,               // Tap threshold.
                            0x00);              // Interrupt Pin.
    ADXL345_SetFreeFallDetection(0x01,  // Free-fall detection enabled.
                                 0x05,  // Free-fall threshold.
                                 0x14,  // Time value for free-fall detection.
                                 0x00); // Interrupt Pin.
    
    /* Set the range and the resolution. */
    ADXL345_SetRangeResolution(ADXL345_RANGE_PM_4G, ADXL345_FULL_RES);
    ADXL345_SetPowerMode(0x1);          // Measure mode.
    while(1)
    {
        /* Read and display the output data of each axis. */ 
        ADXL345_GetGxyz(&x, &y, &z);
        ST7579_String(2, 0, "X data:      [g]", 0); 
        ST7579_FloatNumber(2, 42, x, 3, 0); 
        ST7579_String(3, 0, "Y data:      [g]", 0); 
        ST7579_FloatNumber(3, 42, y, 3, 0); 
        ST7579_String(4, 0, "Z data:      [g]", 0); 
        ST7579_FloatNumber(4, 42, z, 3, 0);
        intSource = ADXL345_GetRegisterValue(ADXL345_INT_SOURCE);
        if((intSource & ADXL345_SINGLE_TAP) != 0)
        {
            ST7579_String(5, 0, "Single Tap", 0);
        }
        if((intSource & ADXL345_DOUBLE_TAP) != 0)
        {
            ST7579_String(6, 0, "Double Tap", 0);
        }
        if((intSource & ADXL345_FREE_FALL) != 0)
        {
            ST7579_String(7, 0, "Free-Fall", 0);
        }
        TIME_DelayMs(100);
    }
}