Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: MOTORWARE, MSP430FR5994, C2000WARE
Hello,
I'm currently succesfull run Lab12b from motorware.
I'd like to add some code to read bmi160 accel + gyro and show that mesurements in console while debugging.
I add bmi160.c, bmi.h, bmi160_support.c, bmi160_support.h to project from (...)\BOOSTXL-SENSORS_SensorGUI_MSP430FR5994\src
But when i try to compile errors occur - libraries are missing:
#include "driverlib.h"
#include "i2c_driver.h"
#include "demo_sysctl.h"
There are also a few other errors...
I'm enclosing the code in which I added reading the sensor:
//this is proj_lab12b main file with some additions for bmi160 accel+gyro sensor on sensors booster pack
#include <math.h>
#include "main.h"
#include <stdio.h>
#include "bmi160_support.h"
#include "bmi160.h"
#ifdef FLASH
#pragma CODE_SECTION(mainISR,"ramfuncs");
#endif
// Include header files used in the main function
// **************************************************************************
// the defines
#define LED_BLINK_FREQ_Hz 5
// **************************************************************************
// **************************************************************************
// BMI160
BMI160_RETURN_FUNCTION_TYPE returnValue;
struct bmi160_gyro_t s_gyroXYZ;
struct bmi160_accel_t s_accelXYZ;
struct bmi160_mag_xyz_s32_t s_magcompXYZ;
//Calibration off-sets
int16_t accel_off_x;
int16_t accel_off_y;
int16_t accel_off_z;
int16_t gyro_off_x;
int16_t gyro_off_y;
uint16_t gyro_off_z;
// **************************************************************************
// the globals
uint_least16_t gCounter_updateGlobals = 0;
bool Flag_Latch_softwareUpdate = true;
CTRL_Handle ctrlHandle;
HAL_Handle halHandle;
USER_Params gUserParams;
HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
HAL_AdcData_t gAdcData;
_iq gMaxCurrentSlope = _IQ(0.0);
#ifdef FAST_ROM_V1p6
CTRL_Obj *controller_obj;
#else
CTRL_Obj ctrl; //v1p7 format
#endif
ENC_Handle encHandle;
ENC_Obj enc;
SLIP_Handle slipHandle;
SLIP_Obj slip;
ST_Obj st_obj;
ST_Handle stHandle;
uint16_t gLEDcnt = 0;
volatile MOTOR_Vars_t gMotorVars = MOTOR_Vars_INIT;
#ifdef FLASH
// Used for running BackGround in flash, and ISR in RAM
extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
#endif
#ifdef DRV8301_SPI
// Watch window interface to the 8301 SPI
DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
#endif
#ifdef DRV8305_SPI
// Watch window interface to the 8305 SPI
DRV_SPI_8305_Vars_t gDrvSpi8305Vars;
#endif
_iq gFlux_pu_to_Wb_sf;
_iq gFlux_pu_to_VpHz_sf;
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf;
_iq gTorque_Flux_Iq_pu_to_Nm_sf;
// **************************************************************************
// the functions
void main(void)
{
uint_least8_t estNumber = 0;
#ifdef FAST_ROM_V1p6
uint_least8_t ctrlNumber = 0;
#endif
// Only used if running from FLASH
// Note that the variable FLASH is defined by the project
#ifdef FLASH
// Copy time critical code and Flash setup code to RAM
// The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker. Refer to the linker files.
memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
#endif
// initialize the hardware abstraction layer
halHandle = HAL_init(&hal,sizeof(hal));
// check for errors in user parameters
USER_checkForErrors(&gUserParams);
// store user parameter error in global variable
gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
// do not allow code execution if there is a user parameter error
if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
{
for(;;)
{
gMotorVars.Flag_enableSys = false;
}
}
// initialize the user parameters
USER_setParams(&gUserParams);
// set the hardware abstraction layer parameters
HAL_setParams(halHandle,&gUserParams);
// initialize the controller
#ifdef FAST_ROM_V1p6
ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
controller_obj = (CTRL_Obj *)ctrlHandle;
#else
ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
#endif
{
CTRL_Version version;
// get the version number
CTRL_getVersion(ctrlHandle,&version);
gMotorVars.CtrlVersion = version;
}
// set the default controller parameters
CTRL_setParams(ctrlHandle,&gUserParams);
// setup faults
HAL_setupFaults(halHandle);
// initialize the interrupt vector table
HAL_initIntVectorTable(halHandle);
// enable the ADC interrupts
HAL_enableAdcInts(halHandle);
// enable global interrupts
HAL_enableGlobalInts(halHandle);
// enable debug interrupts
HAL_enableDebugInt(halHandle);
// disable the PWM
HAL_disablePwm(halHandle);
// initialize the ENC module
encHandle = ENC_init(&enc, sizeof(enc));
// setup the ENC module
ENC_setup(encHandle, 1, USER_MOTOR_NUM_POLE_PAIRS, USER_MOTOR_ENCODER_LINES, 0, USER_IQ_FULL_SCALE_FREQ_Hz, USER_ISR_FREQ_Hz, 8000.0);
// initialize the SLIP module
slipHandle = SLIP_init(&slip, sizeof(slip));
// setup the SLIP module
SLIP_setup(slipHandle, _IQ(gUserParams.ctrlPeriod_sec));
// initialize the SpinTAC Components
stHandle = ST_init(&st_obj, sizeof(st_obj));
// setup the SpinTAC Components
ST_setupVelCtl(stHandle);
ST_setupPosConv(stHandle);
#ifdef DRV8301_SPI
// turn on the DRV8301 if present
HAL_enableDrv(halHandle);
// initialize the DRV8301 interface
HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
#endif
#ifdef DRV8305_SPI
// turn on the DRV8305 if present
HAL_enableDrv(halHandle);
// initialize the DRV8305 interface
HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);
#endif
// enable DC bus compensation
CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
// compute scaling factors for flux and torque calculations
gFlux_pu_to_Wb_sf = USER_computeFlux_pu_to_Wb_sf();
gFlux_pu_to_VpHz_sf = USER_computeFlux_pu_to_VpHz_sf();
gTorque_Ls_Id_Iq_pu_to_Nm_sf = USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf();
gTorque_Flux_Iq_pu_to_Nm_sf = USER_computeTorque_Flux_Iq_pu_to_Nm_sf();
for(;;)
{
// Waiting for enable system flag to be set
while(!(gMotorVars.Flag_enableSys));
// Dis-able the Library internal PI. Iq has no reference now
CTRL_setFlag_enableSpeedCtrl(ctrlHandle, false);
//***********************************************************************************************
printf("Hello world! \n");
// Initialize bmi160 sensor
bmi160_initialize_sensor();
//returnRslt = bmi160_config_running_mode(APPLICATION_NAVIGATION);
bmi160_accel_foc_trigger_xyz(0x03, 0x03, 0x01, &accel_off_x, &accel_off_y, &accel_off_z);
bmi160_set_foc_gyro_enable(0x01, &gyro_off_x, &gyro_off_y, &gyro_off_z);
//***********************************************************************************************
// loop while the enable system flag is true
while(gMotorVars.Flag_enableSys)
{
//***********************************************************************************************
//Read Accel and Gyro values
returnValue = bmi160_read_accel_xyz(&s_accelXYZ);
returnValue = bmi160_read_gyro_xyz(&s_gyroXYZ);
printf("\"gyro\":{\"x\":%d,\"y\":%d,\"z\":%d},"
"\"accel\":{\"x\":%d,\"y\":%d,\"z\":%d}}\n",
s_gyroXYZ.x, s_gyroXYZ.y, s_gyroXYZ.z,
s_accelXYZ.x, s_accelXYZ.y, s_accelXYZ.z);
//***********************************************************************************************
//rest of proj_lab12b without changes
Are there any errors in my code? Maybe I should make changes in the bmi160 libraries?