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

BLE plus SPI Slave functionalities don't work at the same time?

Hi 

I am using an Analog Devices chip as a SPI master and BMD350 (based on nRF52832 chip) as a SPI slave. I want my phone app to send command to the BMD 350 (SPI Slave via Bluetooth) upon a request from the SPI Master and then the SPI Slave should respond with data/command it received from the phone via the MISO line while also receiving the data from the Master on the MOSI line and send it out to the phone app.

How I am trying to make this work: I have integrated the ble_app_uart example with the spis example from SDK 16.0.0 by creating a function called spi_init() and placing it in the main() of ble_app_uart and defining it similar to the spis example in the SDK. 

The issue I have is when I comment this part of the code, the BLE radio displays the device name for me to connect using my phone app but when I uncomment it, the BLE radio doesn't show the device name. It looks like only the SPI functionality or the Bluetooth functionality work at a time but not both together. I would appreciate if someone can help me understand how the ble and spi slave functionality can work together in the ble_app_uart example.

What is the function of this part of the code?

// while (1)
// {
// memset(m_rx_buf, 0, m_length);
// spis_xfer_done = false;
//
// APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
//
// while (!spis_xfer_done)
// {
// __WFE();
// }
//
// NRF_LOG_FLUSH();
// NRF_LOG_INFO((char *)m_tx_buf);
//
// bsp_board_led_invert(BSP_BOARD_LED_0);
// }

Kind regards,
Tejas

Parents
  • static void spi_init(void)
    {
      //   Enable the constant latency sub power mode to minimize the time it takes
      //     for the SPIS peripheral to become active after the CSN line is asserted
      //     (when the CPU is in sleep mode).
      NRF_POWER->TASKS_CONSTLAT = 1;
      bsp_board_init(BSP_INIT_LEDS);
      
      APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
      NRF_LOG_DEFAULT_BACKENDS_INIT();
      
      printf("SPIS example");
      NRF_LOG_INFO("SPIS example");
      
      nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
      spis_config.csn_pin               = APP_SPIS_CS_PIN;    
      spis_config.miso_pin              = APP_SPIS_MISO_PIN;  
      spis_config.mosi_pin              = APP_SPIS_MOSI_PIN;  
      spis_config.sck_pin               = APP_SPIS_SCK_PIN;   
      
      APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));  
     // APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
     /*add this */
    //  while (1)
    //    {
    //      memset(m_rx_buf, 0, m_length);
    //      spis_xfer_done = false;
    //      
    //      APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
    //                               
    //      while (!spis_xfer_done)
    //      {
    //        __WFE();
    //      }
    //      
    //      NRF_LOG_FLUSH();
    //      NRF_LOG_INFO((char *)m_tx_buf);    
    //      
    //      bsp_board_led_invert(BSP_BOARD_LED_0);
    //    }
        /* add this */
    }

    This is the portion of code which I have added from the spis example provided by Nordic

    I have also edited the nus_data_handler as follows

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
      
      if (p_evt->type == BLE_NUS_EVT_RX_DATA)
      {
        uint32_t err_code;
        
        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
     
     //   assert(strlen((char *)m_tx_buf) < UART_TX_BUF_SIZE);   /* TSP */
        
        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
        {
          do
          { 
            //strcat((char *)m_tx_buf, (char *)p_evt->params.rx_data.p_data[i]);    /* TSP */
            temp_ble_rx[i] = p_evt->params.rx_data.p_data[i];    /* TSP  create a temp buffer for received data from phone */
            
            err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
            
            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
            {
              NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
              APP_ERROR_CHECK(err_code);
            }
          } while (err_code == NRF_ERROR_BUSY);
        }
        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
        {
          while (app_uart_put('\n') == NRF_ERROR_BUSY);
        }
      }
      
      strcat((char *)m_tx_buf, (char *)temp_ble_rx);    /*transfering temp buffer contents into m_tx_buf */
      
      
    }

Reply
  • static void spi_init(void)
    {
      //   Enable the constant latency sub power mode to minimize the time it takes
      //     for the SPIS peripheral to become active after the CSN line is asserted
      //     (when the CPU is in sleep mode).
      NRF_POWER->TASKS_CONSTLAT = 1;
      bsp_board_init(BSP_INIT_LEDS);
      
      APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
      NRF_LOG_DEFAULT_BACKENDS_INIT();
      
      printf("SPIS example");
      NRF_LOG_INFO("SPIS example");
      
      nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
      spis_config.csn_pin               = APP_SPIS_CS_PIN;    
      spis_config.miso_pin              = APP_SPIS_MISO_PIN;  
      spis_config.mosi_pin              = APP_SPIS_MOSI_PIN;  
      spis_config.sck_pin               = APP_SPIS_SCK_PIN;   
      
      APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));  
     // APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
     /*add this */
    //  while (1)
    //    {
    //      memset(m_rx_buf, 0, m_length);
    //      spis_xfer_done = false;
    //      
    //      APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
    //                               
    //      while (!spis_xfer_done)
    //      {
    //        __WFE();
    //      }
    //      
    //      NRF_LOG_FLUSH();
    //      NRF_LOG_INFO((char *)m_tx_buf);    
    //      
    //      bsp_board_led_invert(BSP_BOARD_LED_0);
    //    }
        /* add this */
    }

    This is the portion of code which I have added from the spis example provided by Nordic

    I have also edited the nus_data_handler as follows

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
      
      if (p_evt->type == BLE_NUS_EVT_RX_DATA)
      {
        uint32_t err_code;
        
        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
     
     //   assert(strlen((char *)m_tx_buf) < UART_TX_BUF_SIZE);   /* TSP */
        
        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
        {
          do
          { 
            //strcat((char *)m_tx_buf, (char *)p_evt->params.rx_data.p_data[i]);    /* TSP */
            temp_ble_rx[i] = p_evt->params.rx_data.p_data[i];    /* TSP  create a temp buffer for received data from phone */
            
            err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
            
            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
            {
              NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
              APP_ERROR_CHECK(err_code);
            }
          } while (err_code == NRF_ERROR_BUSY);
        }
        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
        {
          while (app_uart_put('\n') == NRF_ERROR_BUSY);
        }
      }
      
      strcat((char *)m_tx_buf, (char *)temp_ble_rx);    /*transfering temp buffer contents into m_tx_buf */
      
      
    }

Children
No Data
Related