21static void enableISPU();
28static UNS8 modeIMU = IMU_ACC_ENABLED;
29static UNS8 configureISPU = 1;
35void putAccelRegSingle(
UNS8 regNo,
UNS8 data){
36 HAL_I2C_Mem_Write(&hi2c2, ACC_ADDR, regNo, 1, &data, 1, 25);
42 HAL_I2C_Mem_Read(&hi2c2, ACC_ADDR, regNo, 1, &data, 1, 25);
47 HAL_I2C_Mem_Write(&hi2c2, ACC_ADDR, regNo, 1, &data, length, 25);
51 HAL_I2C_Mem_Read(&hi2c2, ACC_ADDR, regNo, 1, data, length, 25);
61 putAccelRegSingle(CTRL1_XL, 0x00);
62 putAccelRegSingle(CTRL2_G, 0x00);
63 putAccelRegSingle(CTRL9_C, 0);
72 if(mode & IMU_ISPU_ENABLED)
74 if(mode & IMU_RELOAD_ISPU)
78 else if(mode & IMU_RELOAD_ISPU_DATA)
82 else if(mode & IMU_ISPU_RST)
90 putAccelRegSingle( FUNC_CFG_ACCESS, 0x00 );
92 putAccelRegSingle( CTRL9_C, 0 );
93 putAccelRegSingle( CTRL6_C, 0x10 );
94 putAccelRegSingle( CTRL7_G, 0x80 );
95 if(mode & IMU_ACC_ENABLED)
97 putAccelRegSingle( CTRL1_XL, 0x20);
101 putAccelRegSingle( CTRL1_XL, 0x00);
103 if(mode & IMU_GYRO_ENABLED)
105 putAccelRegSingle( CTRL2_G, 0x20);
109 putAccelRegSingle( CTRL2_G, 0x00);
133 static UNS8 taskDelayMSecs = 50;
134 static UNS32 tDelayRef = 0;
136 if( !
isTimedOut( &tDelayRef, TIMEOUT_ms( taskDelayMSecs ) ) )
151 static INTEGER8 xBuf[ACCEL_BUFFER_LENGTH];
152 static INTEGER8 yBuf[ACCEL_BUFFER_LENGTH];
153 static INTEGER8 zBuf[ACCEL_BUFFER_LENGTH];
156 UNS8 depth = AccelerometerSettings & ACCEL_AVERAGE_DEPTH_BITS;
158 if ((modeIMU & IMU_ISPU_ENABLED) && ((modeIMU & IMU_ACC_ENABLED) || (modeIMU & IMU_GYRO_ENABLED) || (modeIMU & IMU_TEMP_ENABLED)))
161 putAccelRegSingle( FUNC_CFG_ACCESS, 0x00 );
163 if (modeIMU & IMU_ACC_ENABLED)
166 getAccelReg( OUTX_L_A, accelData, 6 );
168 if (modeIMU & IMU_GYRO_ENABLED)
171 getAccelReg( OUTX_L_G, gyroData, 6 );
173 if (modeIMU & IMU_TEMP_ENABLED)
176 getAccelReg( OUT_TEMP_L, tempData, 2 );
179 if ((modeIMU & IMU_ISPU_ENABLED) && ((modeIMU & IMU_ACC_ENABLED) || (modeIMU & IMU_GYRO_ENABLED) || (modeIMU & IMU_TEMP_ENABLED)))
182 putAccelRegSingle( FUNC_CFG_ACCESS, 0x80 );
184 if (modeIMU & IMU_ISPU_ENABLED)
187 getAccelReg( ISPU_DOUT_00_L, ispuData, 16 );
191 if (modeIMU & IMU_ACC_ENABLED)
193 Accelerometers[0] = accelData[1] * (modeIMU & IMU_ISPU_ENABLED ? 4 : 1) + 128;
194 Accelerometers[1] = accelData[3] * (modeIMU & IMU_ISPU_ENABLED ? 4 : 1) + 128;
195 Accelerometers[2] = accelData[5] * (modeIMU & IMU_ISPU_ENABLED ? 4 : 1) + 128;
198 if (modeIMU & IMU_GYRO_ENABLED)
200 memcpy(&Gyroscopes, gyroData,
sizeof(gyroData));
202 if (modeIMU & IMU_TEMP_ENABLED)
204 memcpy(&TemperatureIMU, tempData,
sizeof(tempData));
206 if (modeIMU & IMU_ISPU_ENABLED)
208 memcpy(&Quaternion, ispuData,
sizeof(ispuData));
217 if(depth > ACCEL_BUFFER_LENGTH)
218 depth = ACCEL_BUFFER_LENGTH;
222 memmove( &xBuf[1], &xBuf[0], depth-1);
223 memmove( &yBuf[1], &yBuf[0], depth-1);
224 memmove( &zBuf[1], &zBuf[0], depth-1);
229 xBuf[0]=(
INTEGER8)(Accelerometers[0]>>2) - 32;
230 yBuf[0]=(
INTEGER8)(Accelerometers[1]>>2) - 32;
231 zBuf[0]=(
INTEGER8)(Accelerometers[2]>>2) - 32;
239 for(i=0; i<depth; i++)
250 AccelerometersFiltered[0] = (
UNS8)(x + 128);
251 AccelerometersFiltered[1] = (
UNS8)(y + 128);
252 AccelerometersFiltered[2] = (
UNS8)(z + 128);
253 AccelerometersFiltered[3] = Accelerometers[3];
257 if(AccelerometerSettings & ACCEL_CALC_TILT_BIT)
272 AccelerometersTilt[0] = -90;
274 AccelerometersTilt[0] = - (
INTEGER8) atanT( ((
UNS16)(-x)<<8) / intsqrt(yyzz));
279 AccelerometersTilt[0] = 90;
281 AccelerometersTilt[0] = (
INTEGER8) atanT( ((
UNS16)( x)<<8) / intsqrt(yyzz));
286 AccelerometersTilt[1] = -90;
288 AccelerometersTilt[1] = - (
INTEGER8) atanT( ((
UNS16)(-y)<<8) / intsqrt(xxzz));
293 AccelerometersTilt[1] = 90;
295 AccelerometersTilt[1] = (
INTEGER8) atanT( ((
UNS16)( y)<<8) / intsqrt(xxzz));
298 AccelerometersTilt[2] = 90;
300 AccelerometersTilt[2] = - (
INTEGER8) atanT( ((
UNS16)intsqrt(xxyy)<<8) / (
UNS8)(-z) );
302 AccelerometersTilt[2] = (
INTEGER8) atanT( ((
UNS16)intsqrt(xxyy)<<8) / (
UNS8)( z) );
304 AccelerometersTilt[3] = Accelerometers[3];
311 putAccelRegSingle( ISPU_MEM_SEL, memsel );
312 putAccelRegSingle( ISPU_MEM_ADDR1, (
UNS8) (addr >> 8));
313 putAccelRegSingle( ISPU_MEM_ADDR0, (
UNS8) (addr & 0xFF) );
315 HAL_I2C_Mem_Write(&hi2c2, ACC_ADDR, ISPU_MEM_DATA, 1, data, len, 100);
324 putAccelRegSingle( ISPU_MEM_SEL, 0x40+memsel );
325 putAccelRegSingle( ISPU_MEM_ADDR1, (
UNS8) (addr >> 8));
326 putAccelRegSingle( ISPU_MEM_ADDR0, (
UNS8) (addr & 0xFF) );
330 d = getAccelRegSingle( ISPU_MEM_DATA);
337 if(configureISPU == 1)
339 if(getAccelRegSingle( WHO_AM_I) == 0x22)
341 putAccelRegSingle( CTRL3_C, 0x04 );
342 putAccelRegSingle( CTRL3_C, 0x44 );
343 getAccelRegSingle( CTRL3_C);
346 putAccelRegSingle( CTRL6_C, 0 );
347 putAccelRegSingle( CTRL1_XL, 0);
348 putAccelRegSingle( CTRL2_G, 0);
349 putAccelRegSingle( CTRL7_G, 0);
350 putAccelRegSingle( INT1_CTRL, 0 );
352 putAccelRegSingle( CTRL2_G, 0x48);
353 putAccelRegSingle( CTRL1_XL, 0x4C );
355 getAccelRegSingle( CTRL1_XL );
356 getAccelRegSingle( CTRL6_C );
357 getAccelRegSingle( CTRL2_G );
358 getAccelRegSingle( CTRL7_G);
365 if(configureISPU == 1 || configureISPU == 2 || configureISPU == 3)
368 putAccelRegSingle( FUNC_CFG_ACCESS, 2 );
370 if(configureISPU == 1 || configureISPU == 2)
372 putAccelRegSingle( FUNC_CFG_ACCESS, 0 );
373 putAccelRegSingle( FUNC_CFG_ACCESS, 0x80 );
374 configISPU(0, 0x0000, ispu_data,
sizeof(ispu_data));
376 if(configureISPU == 1)
378 configISPU(1, 0x0000, ispu_bank1,
sizeof(ispu_bank1));
379 configISPU(1, 0x2000, ispu_bank2,
sizeof(ispu_bank2));
380 configISPU(1, 0x4000, ispu_bank3,
sizeof(ispu_bank3));
383 confirmISPU(0, 0x0000, ispu_data,
sizeof(ispu_data));
384 confirmISPU(1, 0x0000, ispu_bank1,
sizeof(ispu_bank1));
385 confirmISPU(1, 0x2000, ispu_bank2,
sizeof(ispu_bank2));
386 confirmISPU(1, 0x4000, ispu_bank3,
sizeof(ispu_bank3));
391 putAccelRegSingle( FUNC_CFG_ACCESS, 0);
392 putAccelRegSingle( CTRL9_C, 0 );
393 putAccelRegSingle( CTRL10_C, 0 );
394 putAccelRegSingle( CTRL1_XL, 0x10 );
396 putAccelRegSingle( FUNC_CFG_ACCESS, 0x80 );
397 putAccelRegSingle( ISPU_CONFIG, 0x01 );
399 putAccelRegSingle( FUNC_CFG_ACCESS, 0 );
403 putAccelRegSingle( CTRL1_XL, 0 );
405 putAccelRegSingle( INT2_CTRL, 0x00);
406 putAccelRegSingle( CTRL6_C, 0 );
407 putAccelRegSingle( CTRL7_G, 0 );
408 putAccelRegSingle( CTRL9_C, 0x40);
409 putAccelRegSingle( MD1_CFG, 0x02);
411 putAccelRegSingle( FUNC_CFG_ACCESS, 0x80);
412 putAccelRegSingle( ISPU_CONFIG, 0x01);
414 putAccelRegSingle( ISPU_INT1_CTRL0, 0x00);
415 putAccelRegSingle( ISPU_INT2_CTRL0, 0x00);
416 putAccelRegSingle( ISPU_ALGO0, 0x01);
418 putAccelRegSingle( FUNC_CFG_ACCESS, 0 );
419 putAccelRegSingle( CTRL1_XL, 0x4C);
420 putAccelRegSingle( CTRL2_G, 0x4C);
422 putAccelRegSingle( FUNC_CFG_ACCESS, 0x80);
433 HAL_I2C_Mem_Write(&hi2c2, TEMP_ADDR, T_CONF_REG, 1, &sendData, 1, 50);
452 static UNS8 taskDelaySecs = 1;
453 static UNS32 tDelayRef = 0;
457 if( !
isTimedOut( &tDelayRef, TIMEOUT_sec( taskDelaySecs ) ) )
467 if(HAL_I2C_Mem_Read(&hi2c2, TEMP_ADDR, T_TEMP_REG, 1, tempData, 2, 25) != HAL_OK)
478 degrC = ( ( (
INTEGER32)( ((
UNS16)tempData[0] << 4) + ((
UNS16)tempData[1] >> 4 ) ) )* 160 ) >> 8 ;
480 if( degrC > MAX_TEMPR )
484 else if( degrC < MIN_TEMPR )
489 Temperature = (
UNS16)degrC;
492void initDiagnostics(
void){
503 static UNS8 taskDelayMSecs = 100;
504 static UNS32 tDelayRef = 0;
507 if(DiagnosticsEnabled)
509 if( !
isTimedOut( &tDelayRef, TIMEOUT_ms( taskDelayMSecs ) ) )
517 HAL_ADC_Start_DMA(&hadc1, &ADCres, 4);
518 HAL_ADC_PollForConversion(&hadc1, 1);
520 Diagnostic_VOS = ADCres[0];
521 Diagnostic_VIN = ADCres[1];
522 Diagnostic_VIC = ADCres[2];
523 Diagnostic_VDD = ADCres[3];
556 UNS8 mulMask = 0x0040;
561 while (mulMask != 0) {
563 if ((retVal * retVal) > val) {
This file is generated by the NNP Tool – Object Dictionary Editor, as originally developed by CAN Fes...
void updateDiagnostics(void)
If disgnostics is enabled, update their entries in the OD.
void sleepTemperature(void)
puts thermometer to sleep
void initAccelerometer(void)
Initializes Accelerometer.
void updateAccelerometer(void)
update Accelerometer
void changeModeIMU(UNS8 mode)
Changes functional mode of ISM330IS accelerometer.
void sleepAccelerometer(void)
puts Accelerometer to sleep
void updateTemperature(void)
Gets temperature reading via I2C.
void initTemperature(void)
initializes thermometer to default configuration
#define UNS8
Unsigned int8 representation in CANFest.
#define UNS16
Unsigned int16 representation in CANFest.
#define INTEGER8
Signed int8 representation in CANFest.
#define UNS32
Unsigned int32 representation in CANFest.
#define INTEGER32
Signed int32 representation in CANFest.
#define INTEGER16
Signed int16 representation in CANFest.
: Header for main.c file. This file contains the common defines of the application.
UNS8 isTimedOut(UNS32 *tRef, UNS32 tAlarm)
Checks if a timer has timed out.
void resetTimeOut(UNS32 *tRef)
Resets a timed out timer.