This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI master doesn't call spi_event_handler when transferred.

Hi!

I made same code for SDK15 and it works. Now I want to rebuild project on the new SDK17.0.2 and same part of code doesn't work with SPI master.

For notice- doesn't work native example 

...examples\peripheral\spi\

And I made on the my project all settings like it was on SDK15 and can't call interrupt spi_event_handler.

my settings:

#define SPI_INSTANCE  0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
static volatile bool spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */

void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    spi_xfer_done = true;
//    NRF_LOG_INFO("Transfer completed.");
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(" Received:");
//        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}

static __INLINE uint8_t lis3dh_spi_read_write(const uint8_t reg, const uint8_t data)
{
//	uint8_t rx_buffer[2], tx_buffer[] = { reg, data };
    m_tx_buf [0] = reg;
    m_tx_buf [1] = data;
    
    spi_xfer_done = false;
    
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, m_length, m_rx_buf, m_length));
    
    while (!spi_xfer_done)
    {
        __WFE();
    }
	return m_rx_buf[1];
}

uint8_t lis3dh_read(const uint8_t reg) 
{		
	return lis3dh_spi_read_write(reg | LIS3DH_READ_MSK, 0xAA);	
}

void lis3dh_write(const uint8_t reg, const uint8_t data) 
{
	lis3dh_spi_read_write(reg | LIS3DH_WRITE_MSK, data);	
}
    
void lis3dh_init(void)
{
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = 7;
    spi_config.miso_pin = 8;
    spi_config.mosi_pin = 9;
    spi_config.sck_pin  = 10;

    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

	lis3dh_write(CTRL_REG1, 0x2F); 		
}

What I make wrong?

Parents
  • Hi,

    So the examples\peripheral\spi sample does not work?
    Have you made any changes to it?
    Do you get any warnings when you build?
    Have you tried deleting the build folder/ cleaning the solution in SES?

  • Hi,

    yes, this example doesn't work. Also doesn't work on 17.1.0 SDK

    I have modified only pins numbers. But same example with same pins but SDK15.0.2 work properly.

    I have no any errors and warning when compiled.

    I rebuild a new example \peripheral\spi with new debug code. And work with Keil.

    Check it pls. I think, you have error in the SDK 17

  • What do you mean when you say it "doesn't work"? Does the spi_event_handler not get called?
    I am getting "Transfer Completed" when I run the SPI example, so the spi_event_handler is getting called here.
    Or are you seeing a different issue now?

  • yes, the spi_event_handler not called.

    I just changed pins to

        spi_config.ss_pin   = 7;
        spi_config.miso_pin = 8;
        spi_config.mosi_pin = 9;
        spi_config.sck_pin  = 10;

    But. I want to repeat, same config in SDK15.0.2 works properly

Reply Children
No Data
Related