nRF52832 SPI使用

2018年7月20日

nRF52832中使用SPI
只是最簡(jiǎn)單TWI初始化,沒有用SDK中提供的TWI transaction managerTWI Sensor module.

SPI初始化比較簡(jiǎn)單,直接nrf_drv_spi_init函數(shù)初始化即可:

#define SPI_INSTANCE  1 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
   nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = NRF_DRV_SPI_PIN_NOT_USED;
    spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    

    spi_config.frequency=NRF_DRV_SPI_FREQ_8M;  //速度
    spi_config.mode=NRF_DRV_SPI_MODE_2;          //模式

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

需要注意的是,ret_code_t nrf_drv_spi_init ( nrf_drv_spi_t const *const p_instance,nrf_drv_spi_config_t const * p_config,nrf_drv_spi_evt_handler_t handler,void * p_context )函數(shù)中,參數(shù)nrf_drv_spi_evt_handler_t handler如果為NULL,則SPI會(huì)運(yùn)行為阻塞模式,讀寫函數(shù)完成后才會(huì)返回值,如果不為NULL,則調(diào)用讀寫函數(shù)后會(huì)立刻返回,在回調(diào)函數(shù)中返回執(zhí)行結(jié)果

SPI讀寫SDK直接封裝好了接口函數(shù):nrf_drv_spi_start_task_get,很簡(jiǎn)單了,不多說(shuō)了.

__STATIC_INLINE ret_code_t nrf_drv_spi_transfer (   nrf_drv_spi_t const *const  p_instance,uint8_t const *  p_tx_buffer,uint8_t     tx_buffer_length,uint8_t *  p_rx_buffer,uint8_t     rx_buffer_length )

[in]    p_instance  Pointer to the driver instance structure.
[in]    p_tx_buffer Pointer to the transmit buffer. Can be NULL if there is nothing to send.
        tx_buffer_length    Length of the transmit buffer.
[in]    p_rx_buffer Pointer to the receive buffer. Can be NULL if there is nothing to receive.
        rx_buffer_length    Length of the receive buffer.

注意sdk_config.h的配置

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容