コード例 #1
0
ファイル: spi_slave_example.c プロジェクト: ChicoSlim/BLEKey
/**@brief Function for SPI slave event callback.
 *
 * Upon receiving an SPI transaction complete event, LED1 will blink and the buffers will be set.
 *
 * @param[in] event SPI slave driver event.
 */
static void spi_slave_event_handle(spi_slave_evt_t event)
{
    uint32_t err_code;
    
    if (event.evt_type == SPI_SLAVE_XFER_DONE)
    { 
        led_toggle();
        
        //Check if buffer size is the same as amount of received data.
        APP_ERROR_CHECK_BOOL(event.rx_amount == RX_BUF_SIZE);
        
        //Check if received data is valid.
        bool success = spi_slave_buffer_check(m_rx_buf, event.rx_amount);
        APP_ERROR_CHECK_BOOL(success);
        
        //Set buffers.
        err_code = spi_slave_buffers_set(m_tx_buf, m_rx_buf, sizeof(m_tx_buf), sizeof(m_rx_buf));
        APP_ERROR_CHECK(err_code);          
    }
}
コード例 #2
0
/**@brief Function for SPI slave event callback.
 *
 * Upon receiving an SPI transaction complete event, LED1 will blink and the buffers will be set.
 *
 * @param[in] event SPI slave driver event.
 */
static void spi_slave_event_handle(nrf_drv_spis_event_t event)
{
    uint32_t err_code;
    
    if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
    {
        err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
        APP_ERROR_CHECK(err_code);
        
        //Check if buffer size is the same as amount of received data.
        APP_ERROR_CHECK_BOOL(event.rx_amount == RX_BUF_SIZE);
        
        //Check if received data is valid.
        bool success = spi_slave_buffer_check(m_rx_buf, event.rx_amount);
        APP_ERROR_CHECK_BOOL(success);
        
        //Set buffers.
        err_code = nrf_drv_spis_buffers_set(&m_spis, m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_rx_buf));
        APP_ERROR_CHECK(err_code);          
    }
}