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... 

  • Here's second, and doing small steps from now there is a lot don't know what to look for

  • well just do step over the function and if the function return false then restart to that function and step into it to find out why.  You don't have to step all the way neither.  Just set a breakpoint where you suspect a problem and run upto it

  • Okay so I found out that this function make res = false:

    res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor); change res from true to false, so I step into it:

    First:


    than I step into: bool res = vpMpu->InitDMP(DMP_START_ADDR, (uint8_t*)s_DMPImage, DMP_CODE_SIZE);





    here's the change, this function change bool res = false;  then I step into res = UploadDMPImage(pDmpImage, Len); hoping that later if(res) change res to true;
    then here is that:

    and lots of minor steps, but getting there:


    And I am not able to get out of "while" couple of times, than lots of minor steps, and then here:


    and then everything breaks and "failed initializing hardware"

    Reassuminng

    So this function results false:

    res = g_Imu.Init(s_ImuCfg, &g_MotSensor, &g_MotSensor, &g_MotSensor); -> results false,


    inside that function, this function results false:
     bool res = vpMpu->InitDMP(DMP_START_ADDR, (uint8_t*)s_DMPImage, DMP_CODE_SIZE);


    inside that function, this function makes res false and later [
    if (res)] makes it again true
    bool AgmMpu9250::InitDMP(uint32_t DmpStartAddr, uint8_t * const pDmpImage, int Len)
    {
    	bool res = false;
    	uint8_t regaddr;
    	uint8_t d[2];
    //	uint8_t intval;
    
    	if (pDmpImage == NULL || Len == 0)
    		return false;
    
    	// load external image
    	res = UploadDMPImage(pDmpImage, Len);
    
    	if (res)
    	{
    		vbDmpEnabled = true;
    
    		d[0] = DmpStartAddr >> 8;//DMP_START_ADDR >> 8;
    		d[1] = DmpStartAddr & 0xFF;//DMP_START_ADDR & 0xFF;
    
    		// Write DMP program start address
    		regaddr = MPU9250_DMP_PROG_START;
    		Write(&regaddr, 1, d, 2);
    
    		// Undocumented : Enable DMP
    		regaddr = MPU9250_AG_USER_CTRL;
    		d[0] = Read8(&regaddr, 1) | MPU9250_AG_USER_CTRL_DMP_EN;
    		Write8(&regaddr, 1, d[0]);
    
    		// DMP require fifo
    		EnableFifo();
    
    		res = true;
    	}
    
    	return res;
    }

    but we step into:
    res = UploadDMPImage(pDmpImage, Len);


    then there is a lot of steps, but basically we get into:

    while (len > 0)
    	{
    		int l = min(len, MPU9250_DMP_MEM_PAGE_SIZE);
    
    		regaddr = MPU9250_DMP_MEM_BANKSEL;
    		d[0] = memaddr >> 8;
    		d[1] = memaddr & 0xFF;
    
    		Write(&regaddr, 1, d, 2);
    
    		regaddr = MPU9250_DMP_MEM_RW;
    		Write(&regaddr, 1, p, l);
    
    		p += l;
    		memaddr += l;
    		len -= l;
    	}

    then we do step into:
    Write(&regaddr, 1, d, 2);

    and we by stepping into few times get this:

    #ifdef NRF52_SERIES
    	while (DataLen > 0)
    	{
    		int l = min(DataLen, NRF52_I2C_DMA_MAXCNT);
    
    		dev->pReg->EVENTS_ERROR = 0;
    		dev->pReg->EVENTS_STOPPED = 0;
    	    if (dev->pI2cDev->DevIntrf.bDma)
    	    {
    			dev->pDmaReg->TXD.PTR = (uint32_t)pData;
    			dev->pDmaReg->TXD.MAXCNT = l;
    			dev->pDmaReg->TXD.LIST = 0;
    	    }
    		dev->pReg->SHORTS = (TWIM_SHORTS_LASTTX_SUSPEND_Enabled << TWIM_SHORTS_LASTTX_SUSPEND_Pos);
    		dev->pReg->EVENTS_SUSPENDED = 0;
    		dev->pReg->TASKS_RESUME = 1;
    		dev->pReg->TASKS_STARTTX = 1;
    
    		if (nRF5xI2CWaitTxComplete(dev, 100000) == false)
                break;
    
    		DataLen -= l;
    		pData += l;
    		cnt += l;
    	}
    #endif

    where:
    if (nRF5xI2CWaitTxComplete(dev, 100000) == false)
                break;


    and doing step into breaks the code and "failed initializing hardware",

    But while doing "step over" we step over this:
    Write(&regaddr, 1, d, 2);

     and we can't get over this loop, I do step over step over, and nothing, to break this loop I need to do step return.
    while (len > 0)
    	{
    		int l = min(len, MPU9250_DMP_MEM_PAGE_SIZE);
    
    		regaddr = MPU9250_DMP_MEM_BANKSEL;
    		d[0] = memaddr >> 8;
    		d[1] = memaddr & 0xFF;
    
    		Write(&regaddr, 1, d, 2);
    
    		regaddr = MPU9250_DMP_MEM_RW;
    		Write(&regaddr, 1, p, l);
    
    		p += l;
    		memaddr += l;
    		len -= l;
    	}


    When I do step return I get back over here:
    bool AgmMpu9250::InitDMP(uint32_t DmpStartAddr, uint8_t * const pDmpImage, int Len)
    {
    	bool res = false;
    	uint8_t regaddr;
    	uint8_t d[2];
    //	uint8_t intval;
    
    	if (pDmpImage == NULL || Len == 0)
    		return false;
    
    	// load external image
    	res = UploadDMPImage(pDmpImage, Len);
    
    	if (res)
    	{
    		vbDmpEnabled = true;
    
    		d[0] = DmpStartAddr >> 8;//DMP_START_ADDR >> 8;
    		d[1] = DmpStartAddr & 0xFF;//DMP_START_ADDR & 0xFF;
    
    		// Write DMP program start address
    		regaddr = MPU9250_DMP_PROG_START;
    		Write(&regaddr, 1, d, 2);
    
    		// Undocumented : Enable DMP
    		regaddr = MPU9250_AG_USER_CTRL;
    		d[0] = Read8(&regaddr, 1) | MPU9250_AG_USER_CTRL_DMP_EN;
    		Write8(&regaddr, 1, d[0]);
    
    		// DMP require fifo
    		EnableFifo();
    
    		res = true;
    	}
    
    	return res;
    }

    and minor step into this:

    vbDmpEnabled = true;

    is looping again this:
    while (len > 0)
    	{
    		int l = min(len, MPU9250_DMP_MEM_PAGE_SIZE);
    
    		regaddr = MPU9250_DMP_MEM_BANKSEL;
    		d[0] = memaddr >> 8;
    		d[1] = memaddr & 0xFF;
    
    		Write(&regaddr, 1, d, 2);
    
    		regaddr = MPU9250_DMP_MEM_RW;
    		Write(&regaddr, 1, p, l);
    
    		p += l;
    		memaddr += l;
    		len -= l;
    	}





    So I assume problem is somewhere there, but I am to newbie to understand anything from this. 


     

  • It is unable to upload the DMP firmware.  That is only for special algorithm.  The actual sensor don't need. You can comment out the imu.  The sensor part should work.

Reply Children
  • 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);
    		}
    	}
    }
    



  • 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.

Related