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

spi fails after removing print statements

So i am utilizing SPI and i got it to work, however for some absurd reason after removing the segger_print statement below from before the while loop the spi would stop functioning. otherwise it works perfectly fine. Any idea why a print statement would cause this? do i need to add a delay? Although i would expect the while loop to handle any delay necessary.

uint32_t LCD_SPI_Write_Command (uint8_t command)
{
	spi_lcd_xfer_done = false;
	LCD_CSX_LOW(); //	set CSX to low to activate LCD listening
	LCD_DCX_LOW(); // indicate command
	uint32_t err_code = nrf_drv_spi_transfer(&m_spi_LCD, &command, 1, NULL, 0);
	if (err_code != NRF_SUCCESS) {
		SEGGER_RTT_printf(0, "[ERROR] on command transfer :%d \n", err_code);
	}
		SEGGER_RTT_printf(0,"Im writing a command! \n");

	while (!spi_lcd_xfer_done)
	  {
	  }
	return err_code;
}
Parents
  • thanks kl-cruz it actually worked. i still dont fully understand why the elimination of a comment would prevent it from working and simply adding the keyword volatile would permit it to work again.

    as for your other recommendation, i didnt fully understand it. I dont have a thread or OS. simply one main method. but i guess what you are recommending is to do something similar to this right?

    if (spi_lcd_xfer_done ==true) {
          nrf_drv_spi_transfer();
    }
    

    so it wont send data unless transfer is done and that way it wont wait at while loop right?

  • Yes, You can do something like this like You describe. It is better to do things asynchronously than synchronously. Of course if You want to save some energy. You can also try to fill buffers in main function, start first transmission, then fill next buffers and then only update pointer in irq handler/callback to next buffers and start next transmission (in irq context). You can do two things in one time (load new data to buffers and send another data). Just doublebuffered!

Reply
  • Yes, You can do something like this like You describe. It is better to do things asynchronously than synchronously. Of course if You want to save some energy. You can also try to fill buffers in main function, start first transmission, then fill next buffers and then only update pointer in irq handler/callback to next buffers and start next transmission (in irq context). You can do two things in one time (load new data to buffers and send another data). Just doublebuffered!

Children
No Data
Related