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
  • Hi,

    Are you able to use debug in SES to found out where it hangs?

    We do have some examples with SPI that you cant test out with SPI, SPI Master Example, nrfx SPI Master Example, SPI Slave Example and SPI Transaction Manager Example

    Side note: You can upload code snippets here by using the  insert > code function, like this:

    Here is some code


    Regards,
    Jonathan

  • 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);

  • 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]);

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

Children
Related