mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Reading and writing to BMP085 sensor now working.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@249 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
7dd7c0201c
commit
7de6be3f59
@ -88,7 +88,7 @@ void PIOS_BMP085_Init(void)
|
||||
//NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Read all 22 bytes of calibration data in one transfer, this is a very optimised way of doing things */
|
||||
uint8_t Data[22];
|
||||
uint8_t Data[BMP085_CALIB_LEN];
|
||||
PIOS_BMP085_Read(BMP085_CALIB_ADDR, Data, BMP085_CALIB_LEN);
|
||||
|
||||
/* Parameters AC1-AC6 */
|
||||
@ -107,6 +107,20 @@ void PIOS_BMP085_Init(void)
|
||||
CalibData.MB = (Data[16] << 8) | Data[17];
|
||||
CalibData.MC = (Data[18] << 8) | Data[19];
|
||||
CalibData.MD = (Data[20] << 8) | Data[21];
|
||||
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC1 = %d\r", CalibData.AC1);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC2 = %d\r", CalibData.AC2);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC3 = %d\r", CalibData.AC3);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC4 = %d\r", CalibData.AC4);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC5 = %d\r", CalibData.AC5);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "AC6 = %d\r", CalibData.AC6);
|
||||
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "B1 = %d\r", CalibData.B1);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "B2 = %d\r", CalibData.B2);
|
||||
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "MB = %d\r", CalibData.MB);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "MC = %d\r", CalibData.MC);
|
||||
PIOS_COM_SendFormattedString(COM_DEBUG_USART, "MD = %d\r", CalibData.MD);
|
||||
}
|
||||
|
||||
|
||||
@ -119,9 +133,9 @@ void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type)
|
||||
{
|
||||
/* Start the conversion */
|
||||
if(Type == Temperature) {
|
||||
PIOS_BMP085_Write(BMP085_CTRL_ADDR, (uint8_t *)BMP085_TEMP_ADDR, 1);
|
||||
PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_TEMP_ADDR);
|
||||
} else if(Type == Pressure) {
|
||||
PIOS_BMP085_Write(BMP085_CTRL_ADDR, (uint8_t *)BMP085_PRES_ADDR, 1);
|
||||
PIOS_BMP085_Write(BMP085_CTRL_ADDR, BMP085_PRES_ADDR);
|
||||
}
|
||||
|
||||
CurrentRead = Type;
|
||||
@ -194,13 +208,13 @@ void PIOS_BMP085_GetValues(uint16_t *Pressure, uint16_t *Altitude, uint16_t *Tem
|
||||
* Reads one or more bytes into a buffer
|
||||
* \param[in] address BMP085 register address (depends on size)
|
||||
* \param[out] buffer destination buffer
|
||||
* \param[in] len number of bytes which should be read (1..64)
|
||||
* \param[in] len number of bytes which should be read
|
||||
* \return 0 if operation was successful
|
||||
* \return -1 if error during I2C transfer
|
||||
* \return -2 if BMP085 blocked by another task (retry it!)
|
||||
* \return -4 if invalid length
|
||||
*/
|
||||
int32_t PIOS_BMP085_Read(uint16_t address, uint8_t *buffer, uint8_t len)
|
||||
int32_t PIOS_BMP085_Read(uint8_t address, uint8_t *buffer, uint8_t len)
|
||||
{
|
||||
/* Try to get the I2C peripheral */
|
||||
if(PIOS_I2C_LockDevice(I2C_Non_Blocking) < 0) {
|
||||
@ -209,16 +223,16 @@ int32_t PIOS_BMP085_Read(uint16_t address, uint8_t *buffer, uint8_t len)
|
||||
}
|
||||
|
||||
/* Send I2C address and EEPROM address */
|
||||
/* To avoid issues with litte/big endian: copy address into temporary buffer */
|
||||
uint8_t addr_buffer[2] = {(uint8_t)(address >> 8), (uint8_t)address};
|
||||
int32_t error = PIOS_I2C_Transfer(I2C_Write_WithoutStop, BMP085_I2C_ADDR, addr_buffer, 2);
|
||||
/* To avoid issues copy address into temporary buffer */
|
||||
uint8_t addr_buffer[1] = {(uint8_t)address};
|
||||
int32_t error = PIOS_I2C_Transfer(I2C_Write_WithoutStop, BMP085_I2C_ADDR, addr_buffer, 1);
|
||||
if(!error) {
|
||||
error = PIOS_I2C_TransferWait();
|
||||
}
|
||||
|
||||
/* Now receive byte(s) */
|
||||
if(!error) {
|
||||
error = PIOS_I2C_Transfer(I2C_Read, (BMP085_I2C_ADDR + 1), buffer, len);
|
||||
error = PIOS_I2C_Transfer(I2C_Read, BMP085_I2C_ADDR, buffer, len);
|
||||
}
|
||||
if(!error) {
|
||||
error = PIOS_I2C_TransferWait();
|
||||
@ -234,16 +248,13 @@ int32_t PIOS_BMP085_Read(uint16_t address, uint8_t *buffer, uint8_t len)
|
||||
|
||||
/**
|
||||
* Writes one or more bytes to the BMP085
|
||||
* \param[in] address BankStick address (depends on size)
|
||||
* \param[in] address Register address
|
||||
* \param[in] buffer source buffer
|
||||
* \param[in] len number of bytes which should be written (1..64)
|
||||
* \return 0 if operation was successful
|
||||
* \return -1 if error during IIC transfer
|
||||
* \return -2 if BankStick blocked by another task (retry it!)
|
||||
* \note Use \ref PIOS_I2C_BS_CheckWriteFinished to check when the write operation
|
||||
* has been finished - this can take up to 5 mS!
|
||||
* \return -1 if error during I2C transfer
|
||||
* \return -2 if BMP085 blocked by another task (retry it!)
|
||||
*/
|
||||
int32_t PIOS_BMP085_Write(uint16_t address, uint8_t *buffer, uint8_t len)
|
||||
int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer)
|
||||
{
|
||||
/* Try to get the IIC peripheral */
|
||||
if(PIOS_I2C_LockDevice(I2C_Non_Blocking) < 0) {
|
||||
@ -252,16 +263,11 @@ int32_t PIOS_BMP085_Write(uint16_t address, uint8_t *buffer, uint8_t len)
|
||||
}
|
||||
|
||||
/* Send I2C address and data */
|
||||
uint8_t WriteBuffer[64+2];
|
||||
WriteBuffer[0] = (uint8_t) (address >> 8);
|
||||
WriteBuffer[1] = (uint8_t) address;
|
||||
|
||||
uint8_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
WriteBuffer[i+2] = buffer[i];
|
||||
}
|
||||
uint8_t WriteBuffer[2];
|
||||
WriteBuffer[0] = address;
|
||||
WriteBuffer[1] = buffer;
|
||||
|
||||
int32_t error = PIOS_I2C_Transfer(I2C_Write, BMP085_I2C_ADDR, WriteBuffer, len + 2);
|
||||
int32_t error = PIOS_I2C_Transfer(I2C_Write, BMP085_I2C_ADDR, WriteBuffer, 2);
|
||||
|
||||
if(!error) {
|
||||
error = PIOS_I2C_TransferWait();
|
||||
|
@ -40,17 +40,17 @@
|
||||
|
||||
/* Local Types */
|
||||
typedef struct {
|
||||
uint16_t AC1;
|
||||
uint16_t AC2;
|
||||
uint16_t AC3;
|
||||
int16_t AC1;
|
||||
int16_t AC2;
|
||||
int16_t AC3;
|
||||
uint16_t AC4;
|
||||
uint16_t AC5;
|
||||
uint16_t AC6;
|
||||
uint16_t B1;
|
||||
uint16_t B2;
|
||||
uint16_t MB;
|
||||
uint16_t MC;
|
||||
uint16_t MD;
|
||||
int16_t B1;
|
||||
int16_t B2;
|
||||
int16_t MB;
|
||||
int16_t MC;
|
||||
int16_t MD;
|
||||
} BMP085CalibDataTypeDef;
|
||||
|
||||
typedef enum {
|
||||
@ -63,7 +63,7 @@ void PIOS_BMP085_Init(void);
|
||||
void PIOS_BMP085_StartADC(ConversionTypeTypeDef Type);
|
||||
void PIOS_BMP085_ReadADC(void);
|
||||
void PIOS_BMP085_GetValues(uint16_t *Pressure, uint16_t *Altitude, uint16_t *Temperature);
|
||||
int32_t PIOS_BMP085_Read(uint16_t address, uint8_t *buffer, uint8_t len);
|
||||
int32_t PIOS_BMP085_Write(uint16_t address, uint8_t *buffer, uint8_t len);
|
||||
int32_t PIOS_BMP085_Read(uint8_t address, uint8_t *buffer, uint8_t len);
|
||||
int32_t PIOS_BMP085_Write(uint8_t address, uint8_t buffer);
|
||||
|
||||
#endif /* PIOS_BMP085_H */
|
||||
|
Loading…
Reference in New Issue
Block a user