mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Reading gyro registers directly working.
This commit is contained in:
parent
e7990f5d43
commit
13e5f4123a
@ -481,19 +481,24 @@ int main()
|
||||
//if(PIOS_BMA180_Test() != 0)
|
||||
// panic(2);
|
||||
|
||||
if(PIOS_HMC5883_Test() != 0)
|
||||
panic(3);
|
||||
//if(PIOS_HMC5883_Test() != 0)
|
||||
// panic(3);
|
||||
|
||||
if(PIOS_BMP085_Test() != 0)
|
||||
panic(4);
|
||||
//if(PIOS_BMP085_Test() != 0)
|
||||
// panic(4);
|
||||
|
||||
while(1) {
|
||||
gyro_error = PIOS_IMU3000_ReadFifo((uint8_t *) gyro, sizeof(gyro));
|
||||
if(PIOS_HMC5883_NewDataAvailable())
|
||||
PIOS_HMC5883_ReadMag(mag);
|
||||
pressure = PIOS_BMP085_GetPressure();
|
||||
PIOS_DELAY_WaitmS(5);
|
||||
uint32_t count = 500;
|
||||
while(count--) {
|
||||
gyro_error = PIOS_IMU3000_ReadGyros(gyro);
|
||||
// if(PIOS_HMC5883_NewDataAvailable())
|
||||
// PIOS_HMC5883_ReadMag(mag);
|
||||
// pressure = PIOS_BMP085_GetPressure();
|
||||
PIOS_DELAY_WaitmS(50);
|
||||
}
|
||||
|
||||
if(PIOS_IMU3000_Test() != 0)
|
||||
panic(1);
|
||||
|
||||
pressure++;
|
||||
gyro[0]++;
|
||||
mag[0]++;
|
||||
|
@ -742,11 +742,11 @@ void PIOS_Board_Init(void) {
|
||||
if (PIOS_SPI_Init(&pios_spi_accel_id, &pios_spi_accel_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
PIOS_BMA180_Attach(pios_spi_accel_id);
|
||||
PIOS_BMA180_Init(&pios_bma180_cfg);
|
||||
/*PIOS_BMA180_Attach(pios_spi_accel_id);
|
||||
PIOS_BMA180_Init(&pios_bma180_cfg);*/
|
||||
PIOS_IMU3000_Init(&pios_imu3000_cfg);
|
||||
PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);
|
||||
/*PIOS_HMC5883_Init(&pios_hmc5883_cfg);
|
||||
PIOS_BMP085_Init(&pios_bmp085_cfg);*/
|
||||
|
||||
|
||||
/* Set up the SPI interface to the OP board */
|
||||
|
@ -148,60 +148,30 @@ int32_t PIOS_IMU3000_ReadID()
|
||||
* \return number of bytes transferred if operation was successful
|
||||
* \return -1 if error during I2C transfer
|
||||
*/
|
||||
uint32_t imu_read = 0;
|
||||
|
||||
int32_t PIOS_IMU3000_ReadFifo(uint8_t * buffer, uint16_t len)
|
||||
{
|
||||
uint16_t fifo_level;
|
||||
|
||||
uint8_t addr_buffer[] = {
|
||||
0x3A,
|
||||
};
|
||||
|
||||
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = PIOS_IMU3000_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = sizeof(addr_buffer),
|
||||
.buf = addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = PIOS_IMU3000_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_READ,
|
||||
.len = 2,
|
||||
.buf = (uint8_t *) &fifo_level,
|
||||
}
|
||||
};
|
||||
|
||||
// Get the number of bytes in the fifo
|
||||
PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list, NELEMENTS(txn_list));
|
||||
addr_buffer[0] = 0x3C;
|
||||
|
||||
uint16_t fifo_level;
|
||||
int8_t retval1, retval2;
|
||||
|
||||
// Get the number of bytes in the fifo
|
||||
retval1 = PIOS_IMU3000_Read(PIOS_IMU3000_FIFO_CNT_MSB, (uint8_t *) &fifo_level, sizeof(fifo_level));
|
||||
if(retval1 != 0)
|
||||
return -1;
|
||||
|
||||
if(len > fifo_level)
|
||||
len = fifo_level;
|
||||
len &= 0x01f8; // only read chunks of 8 bytes (includes footer)
|
||||
len -= (len % 10); // only read chunks of 10 bytes (includes footer and temperature measurement)
|
||||
|
||||
// No bytes available to transfer
|
||||
if(len == 0)
|
||||
return 0;
|
||||
|
||||
imu_read += len;
|
||||
|
||||
const struct pios_i2c_txn txn_list2[] = {
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = PIOS_IMU3000_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_WRITE,
|
||||
.len = sizeof(addr_buffer),
|
||||
.buf = addr_buffer,
|
||||
}
|
||||
,
|
||||
{
|
||||
.info = __func__,
|
||||
.addr = PIOS_IMU3000_I2C_ADDR,
|
||||
.rw = PIOS_I2C_TXN_READ,
|
||||
.len = len,
|
||||
.buf = buffer,
|
||||
}
|
||||
};
|
||||
return PIOS_I2C_Transfer(PIOS_I2C_GYRO_ADAPTER, txn_list2, NELEMENTS(txn_list)) ? len : -1;
|
||||
retval2 = PIOS_IMU3000_Read(PIOS_IMU3000_FIFO_REG, (uint8_t *) &buffer, len);
|
||||
return (retval2 < 0) ? -1 : len;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,8 +260,10 @@ uint8_t PIOS_IMU3000_Test(void)
|
||||
/**
|
||||
* @brief IRQ Handler
|
||||
*/
|
||||
uint32_t imu3000_irq = 0;
|
||||
void PIOS_IMU3000_IRQHandler(void)
|
||||
{
|
||||
imu3000_irq++;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user