# HG changeset patch # User ideenmodellierer # Date 1552510165 -3600 # Node ID 9ecc2e60418df7ecf04c0de4d650939fbee49718 # Parent a492a7a457b7201bc4473d61907dde96822e052f Removed not used compass code Code was prepared for usage of LSM303DLHCTR but at the end the OSTC4 was never equipped with this chip diff -r a492a7a457b7 -r 9ecc2e60418d Small_CPU/Inc/i2c.h --- a/Small_CPU/Inc/i2c.h Wed Mar 13 20:53:05 2019 +0100 +++ b/Small_CPU/Inc/i2c.h Wed Mar 13 21:49:25 2019 +0100 @@ -10,7 +10,6 @@ #define DEVICE_COMPASS_HMC5883L 0x3C // Hardware gen 1 #define DEVICE_COMPASS_303D 0x3C // Hardware gen 2 (Single chip solution LSM303D) -#define DEVICE_ACCELARATOR_303DLHC 0x32 // Hardware gen 2 (Single chip solution LSM303DLHC) #define DEVICE_COMPASS_303AGR 0x3C // Hardware gen 3 (Single chip solution LSM303AGR) /* Battery Gas Gauge */ diff -r a492a7a457b7 -r 9ecc2e60418d Small_CPU/Src/compass.c --- a/Small_CPU/Src/compass.c Wed Mar 13 20:53:05 2019 +0100 +++ b/Small_CPU/Src/compass.c Wed Mar 13 21:49:25 2019 +0100 @@ -39,7 +39,6 @@ #include "stm32f4xx_hal.h" -#define MODE_LSM303DLHC #define TEST_IF_HMC5883L //#define COMPASS_DEACTIVATE @@ -112,7 +111,6 @@ #define HMC5883L (1) ///< id used with hardwareCompass #define LSM303D (2) ///< id used with hardwareCompass -#define LSM303DLHC (3) ///< id used with hardwareCompass #define COMPASS_NOT_RECOGNIZED (4) ///< id used with hardwareCompass @@ -279,34 +277,7 @@ hardwareCompass = HMC5883L; } - -// k�nnte Probleme mit altem Chip machen -// beim 303D f�hrt dieser Code dazu, dass WHOIAM_VALUE nicht geschickt wird!!! - -#ifdef MODE_LSM303DLHC - HAL_StatusTypeDef resultOfOperation = HAL_TIMEOUT; - - if(hardwareCompass == 0) - { - uint8_t data = DLHC_CTRL_REG1_A; - resultOfOperation = I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &data, 1); - if(resultOfOperation == HAL_OK) - { - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &data, 1); - testCompassTypeDebug = data; - if((data & 0x0f) == 0x07) - { - hardwareCompass = LSM303DLHC; - } - } - else - { - testCompassTypeDebug = 0xEE; - } - } - -#endif - +/* No compass identified => Retry */ if(hardwareCompass == 0) { uint8_t data = WHO_AM_I; @@ -318,7 +289,7 @@ hardwareCompass = HMC5883L; } -// was in else before ! +/* Assume that a HMC5883L is equipped by default if detection still failed */ if(hardwareCompass == 0) hardwareCompass = HMC5883L; @@ -341,12 +312,6 @@ } #endif - - if(hardwareCompass == LSM303DLHC) - { - compass_init_LSM303DLHC(fast, gain); - } - else if(hardwareCompass == LSM303D) { compass_init_LSM303D(fast, gain); @@ -374,11 +339,6 @@ // =============================================================================== int compass_calib(void) { - if(hardwareCompass == LSM303DLHC) - { - return compass_calib_common(); // 170821 zur Zeit kein lowpass filtering gefunden, nur high pass auf dem Register ohne Erkl�rung - } - else if(hardwareCompass == LSM303D) { LSM303D_accel_set_onchip_lowpass_filter_bandwidth(773); @@ -406,11 +366,6 @@ // =============================================================================== void compass_sleep(void) { - if(hardwareCompass == LSM303DLHC) - { - compass_sleep_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { compass_sleep_LSM303D(); @@ -430,11 +385,6 @@ // =============================================================================== void compass_read(void) { - if(hardwareCompass == LSM303DLHC) - { - compass_read_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { compass_read_LSM303D(); @@ -453,7 +403,6 @@ // =============================================================================== void accelerator_init(void) { -// if((hardwareCompass != LSM303D) && (hardwareCompass != LSM303DLHC)) if(hardwareCompass == HMC5883L) accelerator_init_MMA8452Q(); } @@ -465,7 +414,6 @@ // =============================================================================== void accelerator_sleep(void) { -// if((hardwareCompass != LSM303D) && (hardwareCompass != LSM303DLHC)) if(hardwareCompass == HMC5883L) accelerator_sleep_MMA8452Q(); } @@ -477,11 +425,6 @@ // =============================================================================== void acceleration_read(void) { - if(hardwareCompass == LSM303DLHC) - { - acceleration_read_LSM303DLHC(); - } - else if(hardwareCompass == LSM303D) { acceleration_read_LSM303D(); @@ -549,36 +492,6 @@ LSM303D_write_checked_reg(reg, val); } - - -// =============================================================================== -// LSM303DLHC_accelerator_read_req -/// @brief -// =============================================================================== -uint8_t LSM303DLHC_accelerator_read_req(uint8_t addr) -{ - uint8_t data; - - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &addr, 1); - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &data, 1); - return data; -} - - -// =============================================================================== -// LSM303DLHC_accelerator_write_req -/// @brief -// =============================================================================== -void LSM303DLHC_accelerator_write_req(uint8_t addr, uint8_t value) -{ - uint8_t data[2]; - - /* enable accel*/ - data[0] = addr; - data[1] = value; - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, data, 2); -} - /* // =============================================================================== // LSM303D_accel_set_range @@ -1131,204 +1044,6 @@ } -// =============================================================================== -// compass_init_LSM303DLHC -/// @brief The new ST 303DLHC 2017/2018 -/// This might be called several times with different gain values during calibration -/// but gain change is not supported at the moment. -/// parts from KOMPASS LSM303DLH-compass-app-note.pdf -/// -/// @param gain: -/// @param fast: -// =============================================================================== - - - -void compass_init_LSM303DLHC(uint8_t fast, uint8_t gain) -{ -// acceleration - // todo : BDU an (wie 303D) und high res, beides in REG4 - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - - if(fast == 0) - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x27); // 10 hz - } - else - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x57); // 100 hz - } -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x88); // 0x88: BDU + HighRes, BDU ist doof! - LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x00); // 0x00 little-endian, ist's immer -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x08); // 0x08: HighRes - //LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x80); // - - -// compass - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - - if(fast == 0) - { - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - } - else - { - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x18); // 75 Hz - } - LSM303D_write_checked_reg(DLHC_CRB_REG_M,0x20); // 0x60: 2.5 Gauss ,0x40: +/-1.9 Gauss,0x20: +/-1.3 Gauss - LSM303D_write_checked_reg(DLHC_MR_REG_M,0x00); //continuous conversation - - - - return; - - -// LSM303D_write_checked_reg(,); -// LSM303D_write_checked_reg(DLHC_CTRL_REG1_A, 0x27); // 0x27 = acc. normal mode with ODR 50Hz - passt nicht mit datenblatt!! -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x40 = full scale range �2 gauss in continuous data update mode and change the little-endian to a big-endian structure. - - if(fast == 0) - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x27); // 0x27 = acc. normal mode, all axes, with ODR 10HZ laut LSM303DLHC, page 25/42 - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - //LSM303D_write_checked_reg(DLHC_CTRL_REG3_A,0x00); // 0x00 default - // - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG4_A, 0x00); // 0x00 = ich glaube little-endian ist gut -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x00 = ich glaube little-endian ist gut - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG5_A,0x00); // 0x00 default - //LSM303D_write_checked_reg(DLHC_CTRL_REG6_A,0x00); // 0x00 default - // magnetic sensor - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x10); // 15 Hz - } - else - { - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x57); // 0x57 = acc. normal mode, all axes, with ODR 100HZ, LSM303DLHC, page 25/42 - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG2_A,0x00); // 0x00 default, hier k�nnte filter sein 0x8?80, cutoff freq. not beschrieben - //LSM303D_write_checked_reg(DLHC_CTRL_REG3_A,0x00); // 0x00 default - // - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG4_A, 0x00); // 0x00 = ich glaube little-endian ist gut -// LSM303D_write_checked_reg(DLHC_CTRL_REG4_A, 0x40); // 0x00 = ich glaube little-endian ist gut - // - //LSM303D_write_checked_reg(DLHC_CTRL_REG5_A,0x00); // 0x00 default - //LSM303D_write_checked_reg(DLHC_CTRL_REG6_A,0x00); // 0x00 default - // magnetic sensor - LSM303D_write_checked_reg(DLHC_CRA_REG_M,0x18); // 75 Hz - } - LSM303D_write_checked_reg(DLHC_CRB_REG_M,0x02); // +/-1.9 Gauss - LSM303D_write_checked_reg(DLHC_MR_REG_M,0x00); //continuous conversation - - -/* -// matthias version 160620 - if(fast == 0) - { - LSM303D_write_checked_reg(ADDR_CTRL_REG0, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG1, 0x3F); // mod 12,5 Hz 3 instead of 6,25 Hz 2 - LSM303D_write_checked_reg(ADDR_CTRL_REG2, 0xC0); // anti alias 50 Hz (minimum) - LSM303D_write_checked_reg(ADDR_CTRL_REG3, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG4, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG5, 0x68); // mod 12,5 Hz 8 instead of 6,25 Hz 4 - } - else - { - LSM303D_write_checked_reg(ADDR_CTRL_REG0, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG1, 0x6F); // 100 Hz - LSM303D_write_checked_reg(ADDR_CTRL_REG2, 0xC0); - LSM303D_write_checked_reg(ADDR_CTRL_REG3, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG4, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG5, 0x74); // 100 Hz - } - LSM303D_write_checked_reg(ADDR_CTRL_REG6, 0x00); - LSM303D_write_checked_reg(ADDR_CTRL_REG7, 0x00); -*/ - return; -} - -// =============================================================================== -// compass_sleep_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void compass_sleep_LSM303DLHC(void) -{ - LSM303DLHC_accelerator_write_req(DLHC_CTRL_REG1_A, 0x07); // CTRL_REG1_A: linear acceleration Power-down mode - LSM303D_write_checked_reg(DLHC_MR_REG_M, 0x02); // MR_REG_M: magnetic sensor Power-down mode -} - - -// =============================================================================== -// compass_read_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void compass_read_LSM303DLHC(void) -{ - uint8_t data; - - memset(magDataBuffer,0,6); - - compass_DX_f = 0; - compass_DY_f = 0; - compass_DZ_f = 0; - - for(int i=0;i<6;i++) - { - data = DLHC_OUT_X_L_M + i; - I2C_Master_Transmit( DEVICE_COMPASS_303D, &data, 1); - I2C_Master_Receive( DEVICE_COMPASS_303D, &magDataBuffer[i], 1); - } - - // 303DLHC new order - compass_DX_f = (((int16_t)((magDataBuffer[0] << 8) | (magDataBuffer[1])))); - compass_DZ_f = (((int16_t)((magDataBuffer[2] << 8) | (magDataBuffer[3])))); - compass_DY_f = (((int16_t)((magDataBuffer[4] << 8) | (magDataBuffer[5])))); - - // no rotation, otherwise see compass_read_LSM303D() - return; -} - - -// =============================================================================== -// acceleration_read_LSM303DLHC -/// @brief The new 2017/2018 compass chip. -// =============================================================================== -void acceleration_read_LSM303DLHC(void) -{ - uint8_t data; - float xraw_f, yraw_f, zraw_f; - float accel_report_x, accel_report_y, accel_report_z; - - memset(accDataBuffer,0,6); - - accel_DX_f = 0; - accel_DY_f = 0; - accel_DZ_f = 0; - - for(int i=0;i<6;i++) - { - data = DLHC_OUT_X_L_A + i; - I2C_Master_Transmit( DEVICE_ACCELARATOR_303DLHC, &data, 1); - I2C_Master_Receive( DEVICE_ACCELARATOR_303DLHC, &accDataBuffer[i], 1); - } - - xraw_f = ((float)( (int16_t)((accDataBuffer[1] << 8) | (accDataBuffer[0])))); - yraw_f = ((float)( (int16_t)((accDataBuffer[3] << 8) | (accDataBuffer[2])))); - zraw_f = ((float)( (int16_t)((accDataBuffer[5] << 8) | (accDataBuffer[4])))); - - rotate_accel_3f(&xraw_f, &yraw_f, &zraw_f); - - // mh f�r 303D - accel_report_x = xraw_f; - accel_report_y = yraw_f; - accel_report_z = zraw_f; - - accel_DX_f = ((int16_t)(accel_report_x)); - accel_DY_f = ((int16_t)(accel_report_y)); - accel_DZ_f = ((int16_t)(accel_report_z)); -} - - // -------------------------------------------------------------------------------- // ----------EARLIER COMPONENTS --------------------------------------------------- // --------------------------------------------------------------------------------