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

After addition SPI to softdevice, some unknown error happened. Even the circulation in main function didn't work?

Hi,

I just want to add SPI to my BLE project to read some data from my gyro, but after spi's addition, the code doesn't work normally anymore. I print a log in the cycle of main function, after add spi, the circulation in main function just cycle limited times.

Before adding spi, i've defined a timer and timerout handler existed, but after spi's addition, the code can't enter the " timerout_handler" function, because i found some logs i've defined in " timerout_handler"  didn't print and display.

main function:

timer_handler:

Settings related to spi:

the LOG sequence: it stop print when "i" in increase to 35

If anyone have some opinions ?

best regards,

jerry

Parents Reply
  • This is a bug:

      uint8_t* icm_x_acc;	
    
      icm_x_acc[0]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_H);//0x43
      icm_x_acc[1]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_L);

    The pointer is uninitialised, so a memory corruption is inevitable. Try this:

    static uint8_t SomeBuffer[2];
    
      uint8_t* icm_x_acc = SomeBuffer;	
    
      icm_x_acc[0]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_H);//0x43
      icm_x_acc[1]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_L);
    
    or
    
      uint8_t icm_x_acc[2];	
    
      icm_x_acc[0]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_H);//0x43
      icm_x_acc[1]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_L);

Children
  • Hi,

    yes, it is a bug. But after i fixed it, the code still went wrong.

    I found once i add the code below to "timeout_handler" , it went wrong. 

    icm_x_acc[0]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_H);//0x43
    	icm_x_acc[1]=ICM_Get_Accelerometer(ICM20602_ACCEL_XOUT_L);
    	NRF_LOG_INFO("ACCEL_XOUT_H is£º%x\n",icm_x_acc[0]);
      NRF_LOG_INFO("ACCEL_XOUT_L is£º%x\n",icm_x_acc[1]);

    However, if i annotate these, everything work well. I guess  it didn't get the acceleration??so the code hangs?

  • First try moving that code to the main() loop and just set a flag in the timeout handler; when the flag is set execute those lines and clear the flag ready for the next set. That avoids all the myriad interrupt level issues, and also improves the handler efficiency.

    As an aside, "ACCEL_XOUT_L is£º%x\n" is suspicious; isn't "ACCEL_XOUT_L is %x\n" what you intended? Note that %x expects a 16-bit value, so even better typecast the values to 16-bit (that latter is probably not an issue, but worth correcting).

      NRF_LOG_INFO("ACCEL_XOUT_H is %x\n",(uint16_t)icm_x_acc[0]);
      NRF_LOG_INFO("ACCEL_XOUT_L is %x\n",(uint16_t)icm_x_acc[1]);

  • Hi, 

    yeah, i've tried the way you said, but it was so strange, the code seemed that it didn't go to timeout_handler and even there were no logs printed out , just like the code was a mess. 

    So i annotated the  "application_timers_start();", just moving the  acceleration_read code to main() loop,

    this time, there were logs printed, but the logs was also a mess. Details were here.

    If you have any suggestions, it would be ok .thanks.

    Jerry

  • I don't use NRF Log much, but try adding this line after the two log lines to ensure the logs are pushed out quickly:

       NRF_LOG_FLUSH();

    Otherwise you need a Nordic insight

  • Hi, hmolesworth

    I've solved the logs' problem. But it seemed that i've deviated from the point. My purpose was put the acceleration_read function and its logs in the timeout handler, in terms of my function , putting the code in main() loop was inappropriate. 

    Now, problem still exists if i move the code to timeout_handler(). I'm looking for answer to fix it.

    But thanks your answers sincerely.

    Jerry

Related