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

Cannot reveive bytes when using spi transaction manager

I'm trying sending and receiving data with spi transaction manager library (nrf_spi_mngr).

The problem is that I cannot receive bytes from SPI device as end_callback doesn't work while begin_callback works.

There is no problem using SPI driver (nrf_drv_spi_transfer() and spi_event_handler() ) directly.

Why the following code doesn't work properly ?

ret_code_t spi1_master_init(void)
{
    // SPI1 (with transaction manager) initialization.
    nrf_drv_spi_config_t const m_master1_config =
    {
		.sck_pin  = 20,
		.mosi_pin = 27,
		.miso_pin = 26,
		.ss_pin   = 18,
		.irq_priority = APP_IRQ_PRIORITY_LOW,
		.orc          = 0xCC,
		.frequency    = NRF_DRV_SPI_FREQ_8M, 
		.mode         = NRF_DRV_SPI_MODE_0,
		.bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,
    };
    return nrf_spi_mngr_init(&m_nrf_spi1_mngr, &m_master1_config);
}

static uint8_t rx_buffer[3];
    
void begin_callback(void *p_user_data){
    NRF_LOG_INFO("begin\r\n");  // appears on Log 	
}
 
void end_callback(ret_code_t result, void *p_user_data){ 
    NRF_LOG_INFO("Manufacturer ID: %d\r\n", rx_buffer[0]); // doesn't appear on Log (RTT Viewer)
    NRF_LOG_INFO("Memory type: %d\r\n", rx_buffer[1]);  // doesn't appear  	
    NRF_LOG_INFO("Capacity: %d\r\n", rx_buffer[2]);  // doesn't appear 	
 }

void flash_s25fl_read_info(){ 	 
	ret_code_t ret_val; 	 	
    static uint8_t tx_buffer[] = { 0x9F }; 	 
	static nrf_spi_mngr_transfer_t transfers_cmd = 
        NRF_SPI_MNGR_TRANSFER(tx_buffer, 1, rx_buffer, 3);

    static nrf_spi_mngr_transaction_t transaction_cmd =
    {   
            .begin_callback      = begin_callback,
            .end_callback        = end_callback,
            .p_user_data         = NULL, //(void *)0,
            .p_transfers         = &transfers_cmd,  
            .number_of_transfers = 1,
            .p_required_spi_cfg  = NULL
        
    };	     	

    ret_val = nrf_spi_mngr_schedule(&m_nrf_spi1_mngr, &transaction_cmd); 	
    //ret_val =  nrf_spi_mngr_perform(&m_nrf_spi1_mngr, &transfers_cmd, 1, NULL);  // app freeze 	
    APP_ERROR_CHECK(ret_val);

	
    /* The following doesn't work too. All %d is 0 
    nrf_delay_ms(100);
    NRF_LOG_INFO("Manufacturer ID: %d\r\n", rx_buffer[0]);  	
    NRF_LOG_INFO("Memory type: %d\r\n", rx_buffer[1]); 
   	NRF_LOG_INFO("Capacity: %d\r\n", rx_buffer[2]); 
    */

}

// in main function
int main(void)
{
   APP_ERROR_CHECK(spi1_master_init());
   flash_s25fl_read_info();
}
Related