Ejemplo n.º 1
0
TM_BMP180_Result_t Measure_BMP180(TM_BMP180_t* BMP180_Data, TM_BMP180_Oversampling_t Oversampling)
{
	TM_BMP180_Result_t Result;
		/* Start temperature conversion */
        TM_BMP180_StartTemperature(BMP180_Data);
        
        /* Wait delay in microseconds */
        /* You can do other things here instead of delay */
        osDelay(5);
        
        /* Read temperature first */
        TM_BMP180_ReadTemperature(BMP180_Data);
		    
        /* Start pressure conversion at ultra high resolution */
        TM_BMP180_StartPressure(BMP180_Data, Oversampling);
        
        /* Wait delay in microseconds */
        /* You can do other things here instead of delay */
        if (Oversampling == TM_BMP180_Oversampling_UltraLowPower)
					osDelay(5);
				else if (Oversampling == TM_BMP180_Oversampling_Standard)
					osDelay(8);
				else if (Oversampling == TM_BMP180_Oversampling_HighResolution)
					osDelay(14);
				else	osDelay(26);
        
        /* Read pressure value */
        Result = TM_BMP180_ReadPressure(BMP180_Data);
        
				return Result;
}
Ejemplo n.º 2
0
int main(void) {
	char buffer[50];
	
	/* Working structure */
	TM_BMP180_t BMP180_Data;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USART1, 11500baud, TX: PB6 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize BMP180 pressure sensor */
	if (TM_BMP180_Init(&BMP180_Data) == TM_BMP180_Result_Ok) {
		/* Init OK */
		TM_USART_Puts(USART1, "BMP180 configured and ready to use\n\n");
	} else {
		/* Device error */
		TM_USART_Puts(USART1, "BMP180 error\n\n");
		while (1);
	}
	
	/* Imagine, we are at 1000 meters above the sea */
	/* And we read pressure of 95000 pascals */
	/* Pressure right on the sea is */
	sprintf(buffer, "Pressure right above the sea: %d pascals\n", TM_BMP180_GetPressureAtSeaLevel(95000, 1000));
	TM_USART_Puts(USART1, buffer);
	sprintf(buffer, "Data were calculated from pressure %d pascals at know altitude %d meters\n\n\n", 95000, 1000);
	TM_USART_Puts(USART1, buffer);

	while (1) {
		/* Start temperature conversion */
		TM_BMP180_StartTemperature(&BMP180_Data);
		
		/* Wait delay in microseconds */
		/* You can do other things here instead of delay */
		Delay(BMP180_Data.Delay);
		
		/* Read temperature first */
		TM_BMP180_ReadTemperature(&BMP180_Data);
		
		/* Start pressure conversion at ultra high resolution */
		TM_BMP180_StartPressure(&BMP180_Data, TM_BMP180_Oversampling_UltraHighResolution);
		
		/* Wait delay in microseconds */
		/* You can do other things here instead of delay */
		Delay(BMP180_Data.Delay);
		
		/* Read pressure value */
		TM_BMP180_ReadPressure(&BMP180_Data);
		
		/* Format data and print to USART */
		sprintf(buffer, "Temp: %2.3f degrees\nPressure: %6d Pascals\nAltitude at current pressure: %3.2f meters\n\n",
			BMP180_Data.Temperature,
			BMP180_Data.Pressure,
			BMP180_Data.Altitude
		);
		/* Send to USART */
		TM_USART_Puts(USART1, buffer);
		
		/* Some delay */
		Delayms(1000);
	}
}