This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I need help with converting any example from Keil to SES

Hello,

I've been trying for days to convert any example from Keil to SES, I have road probably every question here on the dev zone but I am unable to fix this, I ever specially install windows on my mac to try if there it would work.

So, I have done everything from official nordic documents, I've been through several problems which I happily solve, but that I'm not able to.

I get those errors:


unplaced section: .log_dynamic_data_app [nrf_log_frontend.o], size=12, align=4

undefined symbol: __SRAM_segment_end__

undefined symbol: __start_log_const_data

undefined symbol: __start_log_dynamic_data

undefined symbol: __stop_log_const_data

I'm working on latest SEGGER, I have tried latest SDK, also 14.2 . The same errors. 

Thanks for reply

Parents
  • It seems like you are not using the correct startup code.  Startup code and linker scripts are different.  Startup code and linker script go in pair. You need to use the one made for SES.

  • Hey, I have followed instructions from here https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/segger-embedded-studio-a-cross-platform-ide but its a little bit outdated since now there is SES 4.50.

    Maybe there is a tutorial of how to rewrite programs from Keil to SES? Please like, I have spent so much hours for that, everyone seems get it done, and I am unable to transfer even Blinky example... 

  • As just told you.  Comment out that imu init line. you don't need it.

  • Okay I'm sorry, im just little bit tired. I actually commented  out all things that has "imu" in it, it will be okay? Because If I outcomennted only line with

    Here's the code:

    /**-------------------------------------------------------------------------
    @example	mot_sensor_demo.cpp
    
    
    @brief	Motion sensor demo
    
    	This application demo shows UART Rx/Tx over BLE custom service using EHAL library.
    
    @author	Hoang Nguyen Hoan
    @date	Dec. 21, 2018
    
    @license
    
    Copyright (c) 2018, I-SYST inc., all rights reserved
    
    Permission to use, copy, modify, and distribute this software for any purpose
    with or without fee is hereby granted, provided that the above copyright
    notice and this permission notice appear in all copies, and none of the
    names : I-SYST or its contributors may be used to endorse or
    promote products derived from this software without specific prior written
    permission.
    
    For info or contributing contact : hnhoan at i-syst dot com
    
    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    ----------------------------------------------------------------------------*/
    #include <stdio.h>
    #include <atomic>
    #include <inttypes.h>
    
    #include "nrf.h"
    #include "coredev/iopincfg.h"
    #include "coredev/i2c.h"
    #include "coredev/uart.h"
    #include "iopinctrl.h"
    #include "timer_nrf5x.h"
    #include "sensors/agm_mpu9250.h"
    #include "imu/imu_mpu9250.h"
    #include "stddev.h"
    #include "timer_nrf5x.h"
    #include "idelay.h"
    
    
    #define MPU9250
    #include "board.h"
    
    std::atomic<bool> g_bTest(false);
    
    void TimerHandler(Timer *pTimer, uint32_t Evt);
    
    const static TIMER_CFG s_TimerCfg = {
        .DevNo = 0,
    	.ClkSrc = TIMER_CLKSRC_DEFAULT,
    	.Freq = 0,			// 0 => Default highest frequency
    	.IntPrio = 1,
    	.EvtHandler = TimerHandler,
    };
    
    TimerLFnRF5x g_Timer;
    
    
    //********** I2C **********
    static const I2CCFG s_I2cCfg = {
    	0,			// I2C device number
    	{
    		{I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    		{I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    	},
    	100000,	    // Rate
    	I2CMODE_MASTER,
    	5,			// Retry
    	0,			// Number of slave addresses
    	{0,},		// Slave addresses
    	true,	    // DMA
    	false,		// Use interrupt
    	6,			// Interrupt prio
    	NULL		// Event callback
    };
    
    I2C g_I2c;
    
    DeviceIntrf *g_pIntrf = &g_I2c;
    
    
    
    
    static const ACCELSENSOR_CFG s_AccelCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 1000,
    	.Scale = 2,
    	.FltrFreq = 0,
    	.bInter = true,
    	.IntPol = DEVINTR_POL_LOW,
    };
    
    static const GYROSENSOR_CFG s_GyroCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Sensitivity = 10,
    	.FltrFreq = 200,
    };
    
    static const MAGSENSOR_CFG s_MagCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Precision = MAGSENSOR_PRECISION_HIGH,
    };
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt);
    
    static const IMU_CFG s_ImuCfg = {
    	.EvtHandler = ImuEvtHandler
    };*/
    
    
    //ImuMpu9250 g_Imu;
    AgmMpu9250 g_MotSensor;
    
    AccelSensor *g_pAccel = NULL;
    GyroSensor *g_pGyro = NULL;
    MagSensor *g_pMag = NULL;
    
    uint32_t g_DT = 0;
    static uint32_t g_TPrev = 0;
    
    void TimerHandler(Timer *pTimer, uint32_t Evt)
    {
        if (Evt & TIMER_EVT_TRIGGER(0))
        {
        }
    }
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt)
    {
    	ACCELSENSOR_DATA accdata;
    
    	switch (Evt)
    	{
    		case DEV_EVT_DATA_RDY:
    			g_MotSensor.Read(accdata);
    			g_Imu.Read(accdata);
    			printf("Accel %d: %d %d %d\r\n", accdata.Timestamp, accdata.X, accdata.Y, accdata.Z);
    			//g_Imu.Read(quat);
    			//printf("Quat %d: %d %d %d %d\r\n", quat.Timestamp, quat.Q1, quat.Q2, quat.Q2, quat.Q3);
    
    			break;
    	}
    }*/
    
    
    /*void ImuIntHandler(int IntNo)
    {
    	if (IntNo == 0)
    	{
    		uint32_t t = g_Timer.uSecond();
    		g_DT = t - g_TPrev;
    		g_TPrev = t;
    
    		g_Imu.IntHandler();
    		g_MotSensor.IntHandler();
    	}
    }*/
    
    
    bool HardwareInit()
    {
    	bool res;
    
    	g_Timer.Init(s_TimerCfg);
    
    	res = g_I2c.Init(s_I2cCfg);
    
    	if (res == true)
    	{
    		res = g_MotSensor.Init(s_AccelCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pAccel = &g_MotSensor;
    		}
    
    		//res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor);
    	}
    
    	if (res == true)
    	{
    
    		int8_t m[9] = { 1, 0, 0,
    						0, 1, 0,
    						0, 0, 1 };
    	}
    
    	return res;
    }
    
    int main()
    {
    	bool res = HardwareInit();
    
    
    	if (res == false)
    	{
    		printf("Failed initializing hardware\r\n");
    
    		return 1;
    	}
    
    	printf("MotionSensorDemo\r\n");
    
    	ACCELSENSOR_RAWDATA arawdata;
    	ACCELSENSOR_DATA accdata;
    	GYROSENSOR_RAWDATA grawdata;
    	GYROSENSOR_DATA gyrodata;
    	MAGSENSOR_RAWDATA mrawdata;
    
    	memset(&arawdata, 0, sizeof(ACCELSENSOR_RAWDATA));
    	memset(&accdata, 0, sizeof(ACCELSENSOR_DATA));
    	memset(&gyrodata, 0, sizeof(GYROSENSOR_DATA));
    
    
    	uint32_t prevt = 0;
    	int cnt = 100;
    	while (1)
    	{
    		uint32_t t = g_Timer.uSecond();
    
    
    		g_MotSensor.UpdateData();
    
    		uint32_t dt = arawdata.Timestamp - prevt;
    		prevt = arawdata.Timestamp;
    
    		g_MotSensor.Read(arawdata);
    
    		if (g_pGyro)
    		{
    			g_pGyro->Read(grawdata);
    		}
    
    		if (g_pMag)
    		{
    			g_pMag->Read(mrawdata);
    		}
    
    		//g_Imu.Read(accdata);
    
    		if (cnt-- < 0)
    		{
    			cnt = 100;
    			printf("Accel %d %d: %d %d %d\r\n", (uint32_t)g_DT, (uint32_t)dt, arawdata.X, arawdata.Y, arawdata.Z);
    			//printf("Accel %d %d: %f %f %f\r\n", (uint32_t)g_DT, (uint32_t)dt, accdata.X, accdata.Y, accdata.Z);
    		}
    	}
    }
    



    I Runed it, and I achieved getting only 0 for accel, So I debug it, and, I got zeros for acceleretomer, zeros for magnetometer and weird data for gyroscope:


    Where do I look next?

    This is what I am getting:

    Accel 0 0: 0 0 0

    So its not only the values of accel but also the timing 

    (uint32_t)g_DT, (uint32_t)dt

  • I thing I see where your problem is. If you read the datasheet, you'll see that the mag sensor is at a different i2c address.  Change the device addre in the Mag sensor config to 

    MPU9250_MAG_I2C_DEVADDR

  • Okay I see, I road the agm_mpu9250 and you're right. I changed that, but unfortunately still situation seems the same ;/

    code:

    /**-------------------------------------------------------------------------
    @example	mot_sensor_demo.cpp
    
    
    @brief	Motion sensor demo
    
    	This application demo shows UART Rx/Tx over BLE custom service using EHAL library.
    
    @author	Hoang Nguyen Hoan
    @date	Dec. 21, 2018
    
    @license
    
    Copyright (c) 2018, I-SYST inc., all rights reserved
    
    Permission to use, copy, modify, and distribute this software for any purpose
    with or without fee is hereby granted, provided that the above copyright
    notice and this permission notice appear in all copies, and none of the
    names : I-SYST or its contributors may be used to endorse or
    promote products derived from this software without specific prior written
    permission.
    
    For info or contributing contact : hnhoan at i-syst dot com
    
    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    ----------------------------------------------------------------------------*/
    #include <stdio.h>
    #include <atomic>
    #include <inttypes.h>
    
    #include "nrf.h"
    #include "coredev/iopincfg.h"
    #include "coredev/i2c.h"
    #include "coredev/uart.h"
    #include "iopinctrl.h"
    #include "timer_nrf5x.h"
    #include "sensors/agm_mpu9250.h"
    #include "imu/imu_mpu9250.h"
    #include "stddev.h"
    #include "timer_nrf5x.h"
    #include "idelay.h"
    
    
    #define MPU9250
    #include "board.h"
    
    std::atomic<bool> g_bTest(false);
    
    void TimerHandler(Timer *pTimer, uint32_t Evt);
    
    const static TIMER_CFG s_TimerCfg = {
        .DevNo = 0,
    	.ClkSrc = TIMER_CLKSRC_DEFAULT,
    	.Freq = 0,			// 0 => Default highest frequency
    	.IntPrio = 1,
    	.EvtHandler = TimerHandler,
    };
    
    TimerLFnRF5x g_Timer;
    
    
    //********** I2C **********
    static const I2CCFG s_I2cCfg = {
    	0,			// I2C device number
    	{
    		{I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    		{I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    	},
    	100000,	    // Rate
    	I2CMODE_MASTER,
    	5,			// Retry
    	0,			// Number of slave addresses
    	{0,},		// Slave addresses
    	true,	    // DMA
    	false,		// Use interrupt
    	6,			// Interrupt prio
    	NULL		// Event callback
    };
    
    I2C g_I2c;
    
    DeviceIntrf *g_pIntrf = &g_I2c;
    
    
    
    
    static const ACCELSENSOR_CFG s_AccelCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 1000,
    	.Scale = 2,
    	.FltrFreq = 0,
    	.bInter = true,
    	.IntPol = DEVINTR_POL_LOW,
    };
    
    static const GYROSENSOR_CFG s_GyroCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Sensitivity = 10,
    	.FltrFreq = 200,
    };
    
    static const MAGSENSOR_CFG s_MagCfg = {
    	.DevAddr = MPU9250_MAG_I2C_DEVADDR,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Precision = MAGSENSOR_PRECISION_HIGH,
    };
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt);
    
    static const IMU_CFG s_ImuCfg = {
    	.EvtHandler = ImuEvtHandler
    };*/
    
    
    //ImuMpu9250 g_Imu;
    AgmMpu9250 g_MotSensor;
    
    AccelSensor *g_pAccel = NULL;
    GyroSensor *g_pGyro = NULL;
    MagSensor *g_pMag = NULL;
    
    uint32_t g_DT = 0;
    static uint32_t g_TPrev = 0;
    
    void TimerHandler(Timer *pTimer, uint32_t Evt)
    {
        if (Evt & TIMER_EVT_TRIGGER(0))
        {
        }
    }
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt)
    {
    	ACCELSENSOR_DATA accdata;
    
    	switch (Evt)
    	{
    		case DEV_EVT_DATA_RDY:
    			g_MotSensor.Read(accdata);
    			//g_Imu.Read(accdata);
    			printf("Accel %d: %d %d %d\r\n", accdata.Timestamp, accdata.X, accdata.Y, accdata.Z);
    			//g_Imu.Read(quat);
    			//printf("Quat %d: %d %d %d %d\r\n", quat.Timestamp, quat.Q1, quat.Q2, quat.Q2, quat.Q3);
    
    			break;
    	}
    }*/
    
    
    /*void ImuIntHandler(int IntNo)
    {
    	if (IntNo == 0)
    	{
    		uint32_t t = g_Timer.uSecond();
    		g_DT = t - g_TPrev;
    		g_TPrev = t;
    
    		//g_Imu.IntHandler();
    		g_MotSensor.IntHandler();
    	}
    }*/
    
    
    bool HardwareInit()
    {
    	bool res;
    
    	g_Timer.Init(s_TimerCfg);
    
    	res = g_I2c.Init(s_I2cCfg);
    
    	if (res == true)
    	{
    		res = g_MotSensor.Init(s_AccelCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pAccel = &g_MotSensor;
    		}
    
    		//res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor);
    	}
    
    	if (res == true)
    	{
    
    		int8_t m[9] = { 1, 0, 0,
    						0, 1, 0,
    						0, 0, 1 };
    	}
    
    	return res;
    }
    
    int main()
    {
    	bool res = HardwareInit();
    
    
    	if (res == false)
    	{
    		printf("Failed initializing hardware\r\n");
    
    		return 1;
    	}
    
    	printf("MotionSensorDemo\r\n");
    
    	ACCELSENSOR_RAWDATA arawdata;
    	ACCELSENSOR_DATA accdata;
    	GYROSENSOR_RAWDATA grawdata;
    	GYROSENSOR_DATA gyrodata;
    	MAGSENSOR_RAWDATA mrawdata;
    
    	memset(&arawdata, 0, sizeof(ACCELSENSOR_RAWDATA));
    	memset(&accdata, 0, sizeof(ACCELSENSOR_DATA));
    	memset(&gyrodata, 0, sizeof(GYROSENSOR_DATA));
    
    
    	uint32_t prevt = 0;
    	int cnt = 100;
    	while (1)
    	{
    		uint32_t t = g_Timer.uSecond();
    
    
    		g_MotSensor.UpdateData();
    
    		uint32_t dt = arawdata.Timestamp - prevt;
    		prevt = arawdata.Timestamp;
    
    		g_MotSensor.Read(arawdata);
    
    		if (g_pGyro)
    		{
    			g_pGyro->Read(grawdata);
    		}
    
    		if (g_pMag)
    		{
    			g_pMag->Read(mrawdata);
    		}
    
    		//g_Imu.Read(accdata);
    
    		if (cnt-- < 0)
    		{
    			cnt = 100;
    			printf("Accel %d %d: %d %d %d\r\n", (uint32_t)g_DT, (uint32_t)dt, arawdata.X, arawdata.Y, arawdata.Z);
    			//printf("Accel %d %d: %f %f %f\r\n", (uint32_t)g_DT, (uint32_t)dt, accdata.X, accdata.Y, accdata.Z);
    		}
    	}
    }
    



Reply
  • Okay I see, I road the agm_mpu9250 and you're right. I changed that, but unfortunately still situation seems the same ;/

    code:

    /**-------------------------------------------------------------------------
    @example	mot_sensor_demo.cpp
    
    
    @brief	Motion sensor demo
    
    	This application demo shows UART Rx/Tx over BLE custom service using EHAL library.
    
    @author	Hoang Nguyen Hoan
    @date	Dec. 21, 2018
    
    @license
    
    Copyright (c) 2018, I-SYST inc., all rights reserved
    
    Permission to use, copy, modify, and distribute this software for any purpose
    with or without fee is hereby granted, provided that the above copyright
    notice and this permission notice appear in all copies, and none of the
    names : I-SYST or its contributors may be used to endorse or
    promote products derived from this software without specific prior written
    permission.
    
    For info or contributing contact : hnhoan at i-syst dot com
    
    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    ----------------------------------------------------------------------------*/
    #include <stdio.h>
    #include <atomic>
    #include <inttypes.h>
    
    #include "nrf.h"
    #include "coredev/iopincfg.h"
    #include "coredev/i2c.h"
    #include "coredev/uart.h"
    #include "iopinctrl.h"
    #include "timer_nrf5x.h"
    #include "sensors/agm_mpu9250.h"
    #include "imu/imu_mpu9250.h"
    #include "stddev.h"
    #include "timer_nrf5x.h"
    #include "idelay.h"
    
    
    #define MPU9250
    #include "board.h"
    
    std::atomic<bool> g_bTest(false);
    
    void TimerHandler(Timer *pTimer, uint32_t Evt);
    
    const static TIMER_CFG s_TimerCfg = {
        .DevNo = 0,
    	.ClkSrc = TIMER_CLKSRC_DEFAULT,
    	.Freq = 0,			// 0 => Default highest frequency
    	.IntPrio = 1,
    	.EvtHandler = TimerHandler,
    };
    
    TimerLFnRF5x g_Timer;
    
    
    //********** I2C **********
    static const I2CCFG s_I2cCfg = {
    	0,			// I2C device number
    	{
    		{I2C0_SDA_PORT, I2C0_SDA_PIN, I2C0_SDA_PINOP, IOPINDIR_BI, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    		{I2C0_SCL_PORT, I2C0_SCL_PIN, I2C0_SCL_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_OPENDRAIN},
    	},
    	100000,	    // Rate
    	I2CMODE_MASTER,
    	5,			// Retry
    	0,			// Number of slave addresses
    	{0,},		// Slave addresses
    	true,	    // DMA
    	false,		// Use interrupt
    	6,			// Interrupt prio
    	NULL		// Event callback
    };
    
    I2C g_I2c;
    
    DeviceIntrf *g_pIntrf = &g_I2c;
    
    
    
    
    static const ACCELSENSOR_CFG s_AccelCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 1000,
    	.Scale = 2,
    	.FltrFreq = 0,
    	.bInter = true,
    	.IntPol = DEVINTR_POL_LOW,
    };
    
    static const GYROSENSOR_CFG s_GyroCfg = {
    	.DevAddr = MPU9250_I2C_DEV_ADDR0,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Sensitivity = 10,
    	.FltrFreq = 200,
    };
    
    static const MAGSENSOR_CFG s_MagCfg = {
    	.DevAddr = MPU9250_MAG_I2C_DEVADDR,
    	.OpMode = SENSOR_OPMODE_CONTINUOUS,
    	.Freq = 50000,
    	.Precision = MAGSENSOR_PRECISION_HIGH,
    };
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt);
    
    static const IMU_CFG s_ImuCfg = {
    	.EvtHandler = ImuEvtHandler
    };*/
    
    
    //ImuMpu9250 g_Imu;
    AgmMpu9250 g_MotSensor;
    
    AccelSensor *g_pAccel = NULL;
    GyroSensor *g_pGyro = NULL;
    MagSensor *g_pMag = NULL;
    
    uint32_t g_DT = 0;
    static uint32_t g_TPrev = 0;
    
    void TimerHandler(Timer *pTimer, uint32_t Evt)
    {
        if (Evt & TIMER_EVT_TRIGGER(0))
        {
        }
    }
    
    /*void ImuEvtHandler(Device * const pDev, DEV_EVT Evt)
    {
    	ACCELSENSOR_DATA accdata;
    
    	switch (Evt)
    	{
    		case DEV_EVT_DATA_RDY:
    			g_MotSensor.Read(accdata);
    			//g_Imu.Read(accdata);
    			printf("Accel %d: %d %d %d\r\n", accdata.Timestamp, accdata.X, accdata.Y, accdata.Z);
    			//g_Imu.Read(quat);
    			//printf("Quat %d: %d %d %d %d\r\n", quat.Timestamp, quat.Q1, quat.Q2, quat.Q2, quat.Q3);
    
    			break;
    	}
    }*/
    
    
    /*void ImuIntHandler(int IntNo)
    {
    	if (IntNo == 0)
    	{
    		uint32_t t = g_Timer.uSecond();
    		g_DT = t - g_TPrev;
    		g_TPrev = t;
    
    		//g_Imu.IntHandler();
    		g_MotSensor.IntHandler();
    	}
    }*/
    
    
    bool HardwareInit()
    {
    	bool res;
    
    	g_Timer.Init(s_TimerCfg);
    
    	res = g_I2c.Init(s_I2cCfg);
    
    	if (res == true)
    	{
    		res = g_MotSensor.Init(s_AccelCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pAccel = &g_MotSensor;
    		}
    
    		//res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor);
    	}
    
    	if (res == true)
    	{
    
    		int8_t m[9] = { 1, 0, 0,
    						0, 1, 0,
    						0, 0, 1 };
    	}
    
    	return res;
    }
    
    int main()
    {
    	bool res = HardwareInit();
    
    
    	if (res == false)
    	{
    		printf("Failed initializing hardware\r\n");
    
    		return 1;
    	}
    
    	printf("MotionSensorDemo\r\n");
    
    	ACCELSENSOR_RAWDATA arawdata;
    	ACCELSENSOR_DATA accdata;
    	GYROSENSOR_RAWDATA grawdata;
    	GYROSENSOR_DATA gyrodata;
    	MAGSENSOR_RAWDATA mrawdata;
    
    	memset(&arawdata, 0, sizeof(ACCELSENSOR_RAWDATA));
    	memset(&accdata, 0, sizeof(ACCELSENSOR_DATA));
    	memset(&gyrodata, 0, sizeof(GYROSENSOR_DATA));
    
    
    	uint32_t prevt = 0;
    	int cnt = 100;
    	while (1)
    	{
    		uint32_t t = g_Timer.uSecond();
    
    
    		g_MotSensor.UpdateData();
    
    		uint32_t dt = arawdata.Timestamp - prevt;
    		prevt = arawdata.Timestamp;
    
    		g_MotSensor.Read(arawdata);
    
    		if (g_pGyro)
    		{
    			g_pGyro->Read(grawdata);
    		}
    
    		if (g_pMag)
    		{
    			g_pMag->Read(mrawdata);
    		}
    
    		//g_Imu.Read(accdata);
    
    		if (cnt-- < 0)
    		{
    			cnt = 100;
    			printf("Accel %d %d: %d %d %d\r\n", (uint32_t)g_DT, (uint32_t)dt, arawdata.X, arawdata.Y, arawdata.Z);
    			//printf("Accel %d %d: %f %f %f\r\n", (uint32_t)g_DT, (uint32_t)dt, accdata.X, accdata.Y, accdata.Z);
    		}
    	}
    }
    



Children
  • Unfortunately, I don't have that sensor in I2C mode.  I can't test to find the issue.  The data is updated every time you call the UpdateData() function.  Perhaps, you can breakpoint in that function to see why it didn't see the data.  You passed the init which means it is working. As to why you don't get the data, I don't know. Try configure the accel freq to 50Hz (50000).  You're config is currently set to 1 Hz.  Also let it runs bit before pausing it to look at the data.

  • because you program the mag registers into the accel with the wrong address which mess up thing.  Try power off to clear everything.

  • I tried clearing and changing accel freq but nothing change. I will try to debug that process and find what's could be wrong

  • Okay, the whole function 

    bool AgmMpu9250::UpdateData() 

    is nearly working.



    because "val" is equal to zero, I don't understand this function, but I assume it should update data, and it do not update it because, all of the "if's" are not working because of theirs condition?

    And val is equal zero because of that: (which is earlier in the code from screen)

    if (vbSensorEnabled[MPU9250_ACCEL_IDX] == true)
    		val += 8;
    	if (vbSensorEnabled[MPU9250_GYRO_IDX] == true)
    		val += 6;
    	//if (vbSensorEnabled[MPU9250_MAG_IDX] == true)
    	//	val += 8;

    So: vbSensorEnabled[MPU9250_ACCEL_IDX] is not true and also vbSensorEnabled[MPU_GYRO_IDX] is not true.

    Should I delete out commented bSensorEnabled[MPU9250_ACCEL_IDX] ?

    What else would you recommend to change?

    Second case is:
    also when I added here function to read magnetometer values:

    bool HardwareInit()
    {
    	bool res;
    
    	g_Timer.Init(s_TimerCfg);
    
    	res = g_I2c.Init(s_I2cCfg);
    
    	if (res == true)
    	{
    		res = g_MotSensor.Init(s_AccelCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pAccel = &g_MotSensor;
    		}
    
    		res = g_MotSensor.Init(s_GyroCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pGyro = &g_MotSensor;
    		}
    		res = g_MotSensor.Init(s_MagCfg, &g_I2c, &g_Timer);
    		if (res == true)
    		{
    			g_pMag = &g_MotSensor;
    		}
    
    		//res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor);
    	}
    
    	if (res == true)
    	{
    
    		int8_t m[9] = { 1, 0, 0,
    						0, 1, 0,
    						0, 0, 1 };
    	}
    
    	return res;
    }


    this function returns false to the bool res, and while I try to debug it, I come to that:


    what ever I do, the timeout is reduced by 1 and I can't get over this loop. 

Related