bool ms5611Detect(baro_t *baro) { GPIO_InitTypeDef GPIO_InitStructure; bool ack = false; uint8_t sig,i; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // PC13 (BMP085's XCLR reset input, which we use to disable it) GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); BMP085_OFF; delay(50); // Crashpilot 100ms No idea how long the chip takes to power-up, but let's make it 10ms // BMP085 is disabled. If we have a MS5611, it will reply. if no reply, means either we have BMP085 or no baro at all. ack = i2cRead(MS5611_ADDR, CMD_PROM_RD, 1, &sig); if (!ack) return false; delay(50); for (i = 0; i < 5; i++) ms5611_reset(); // Reset the damn thing a few times for (i = 0; i < PROM_NB; i++) ms5611_c[i] = ms5611_prom(i); // read all coefficients // read 8 words word:0 = ID; word:1-6 = C1-C6; word:7 = ChkSum if (ms5611_crc(ms5611_c) != 0) return false; // check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line! // baro->ut_delay = 10000; // baro->up_delay = 10000; // baro->repeat_delay = 4000; baro->ut_delay = 9500; baro->up_delay = 9500; baro->repeat_delay = 1; baro->start_ut = ms5611_start_ut; baro->get_ut = ms5611_get_ut; baro->start_up = ms5611_start_up; baro->get_up = ms5611_get_up; baro->calculate = ms5611_calculate; delay(50); for (i = 0; i < 10; i++) ms5611_reset(); // Reset the damn thing a few times delay(50); return true; }
bool ms5611Detect(baro_t *baro) { bool ack = false; uint8_t sig; int i; delay(10); // No idea how long the chip takes to power-up, but let's make it 10ms ack = i2cRead(BARO_I2C_INSTANCE, MS5611_ADDR, CMD_PROM_RD, 1, &sig); if (!ack) return false; ms5611_reset(); // read all coefficients for (i = 0; i < PROM_NB; i++) ms5611_c[i] = ms5611_prom(i); // check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line! if (ms5611_crc(ms5611_c) != 0) return false; // TODO prom + CRC baro->ut_delay = 10000; baro->up_delay = 10000; baro->start_ut = ms5611_start_ut; baro->get_ut = ms5611_get_ut; baro->start_up = ms5611_start_up; baro->get_up = ms5611_get_up; baro->calculate = ms5611_calculate; return true; }
bool ms5611Init() { bool ack = false; uint8_t sig; int i; ack = i2cRead(MS5611_ADDR, CMD_PROM_RD, 1, &sig); if (!ack) return false; ms5611_reset(); // read all coefficients for (i = 0; i < PROM_NB; i++) ms5611_c[i] = ms5611_prom(i); // check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line! if (ms5611_crc(ms5611_c) != 0) return false; // TODO prom + CRC baro.ut_delay = 10000; baro.up_delay = 10000; //us baro.start_ut = ms5611_start_ut; baro.get_ut = ms5611_get_ut; baro.start_up = ms5611_start_up; baro.get_up = ms5611_get_up; baro.calculate = ms5611_calculate; return true; }
bool ms5611Detect(baro_t *baro) { GPIO_InitTypeDef GPIO_InitStructure; bool ack = false; uint8_t sig; int i; // PC13 (BMP085's XCLR reset input, which we use to disable it) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); BMP085_OFF; delay(10); // No idea how long the chip takes to power-up, but let's make it 10ms // BMP085 is disabled. If we have a MS5611, it will reply. if no reply, means either // we have BMP085 or no baro at all. ack = i2cRead(MS5611_ADDR, CMD_PROM_RD, 1, &sig); if (!ack) return false; ms5611_reset(); // read all coefficients for (i = 0; i < PROM_NB; i++) ms5611_c[i] = ms5611_prom(i); // check crc, bail out if wrong - we are probably talking to BMP085 w/o XCLR line! if (ms5611_crc(ms5611_c) != 0) return false; // TODO prom + CRC baro->ut_delay = 10000; baro->up_delay = 10000; baro->repeat_delay = 4000; baro->start_ut = ms5611_start_ut; baro->get_ut = ms5611_get_ut; baro->start_up = ms5611_start_up; baro->get_up = ms5611_get_up; baro->calculate = ms5611_calculate; return true; }
THD_FUNCTION(scMS5611Thread, arg) { systime_t sleep_until; systime_t interval_st = MS2ST(ms5611_interval_ms); (void)arg; chRegSetThreadName(__func__); SC_LOG_PRINTF("d: ms5611 init\r\n"); // We need to give a bit of time to the chip until we can ask it to shut down // i2c not ready initially? (This is inherited from the LSM9DS0 driver) chThdSleepMilliseconds(20); ms5611_reset(); chThdSleepMilliseconds(100); ms5611_reset(); chThdSleepMilliseconds(100); ms5611_reset(); chThdSleepMilliseconds(100); ms5611_read_prom(); uint8_t ref_crc = ms5611_prom[MS5611_PROM_SIZE - 1] & 0x0F; uint8_t calc_crc = ms5611_calc_crc(); if (ref_crc != calc_crc) { SC_LOG_PRINTF("e: ms5611 crc failure: 0x%x vs 0x%x\r\n", ref_crc, calc_crc); } sleep_until = chVTGetSystemTime() + interval_st; // Loop initiating measurements and waiting for results while (!chThdShouldTerminateX()) { systime_t now = chVTGetSystemTime(); systime_t wait_time = sleep_until - now; uint32_t temp; uint32_t pres; msg_t msg; // Using a semaphore allows to cancel the sleep outside the thread if (chBSemWaitTimeout(&ms5611_wait_sem, wait_time) != MSG_TIMEOUT) { continue; } sleep_until += interval_st; now = chVTGetSystemTime(); temp = ms5611_read(true); if (chThdShouldTerminateX()) { break; } pres = ms5611_read(false); chMtxLock(&data_mtx); ms5611_temp = temp; ms5611_pres = pres; ms5611_time_st = now; chMtxUnlock(&data_mtx); // Notify main app about new measurements being available msg = sc_event_msg_create_type(SC_EVENT_TYPE_MS5611_AVAILABLE); sc_event_msg_post(msg, SC_EVENT_MSG_POST_FROM_NORMAL); } }
/* * Initialise the MS5611. * (Public) * * Sends a RESET and then reads in the calibration data. * * Call this once system startup, before attempting ms5611_read. * * cal_data should be a pointer to some memory to store the calibration in. */ void ms5611_init(MS5611CalData* cal_data) { ms5611_reset(); ms5611_read_cal(cal_data); }