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

nrf52832+SPI+AD5940 cannot get ad5940id

Hi,I am trying to use nrf52832 to drive the ad5940 chip, but using the function in the SPIM driver library to initialize the ad5940, I have been unable to get the ID of the chip. If I use gpio to simulate spi, I can get the ID smoothly. What is the reason? My ad5940 transplant code as follows.

SDK ver:17.1.0_DDDE560

static const nrf_drv_spi_t ad5940_spi_handler = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */ static volatile bool ad5940_spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */ void ad5940_spi_event_handler(nrf_drv_spi_evt_t const *p_event,void *p_context) {     if(p_event->type == NRF_DRV_SPI_EVENT_DONE)     {         ad5940_spi_xfer_done = true;     } } static void ad5940_spi_init(void) {     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 = AD5940_SPI_MISO_PIN;     spi_config.mosi_pin = AD5940_SPI_MOSI_PIN;     spi_config.sck_pin  = AD5940_SPI_SCLK_PIN;     spi_config.frequency = NRF_DRV_SPI_FREQ_8M;     spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;     spi_config.mode     = NRF_DRV_SPI_MODE_0;     APP_ERROR_CHECK(nrf_drv_spi_init(&ad5940_spi_handler, &spi_config, ad5940_spi_event_handler, NULL)); } void AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length) { APP_ERROR_CHECK(nrf_drv_spi_transfer(&ad5940_spi_handler, pSendBuffer, length, pRecvBuff, length)); while(!ad5940_spi_xfer_done); ad5940_spi_xfer_done = false; } uint32_t ad5940_port_Init(void) { ad5940_spi_init(); ad5940_int0_init(); return 0; } uint32_t AD5940_MCUResourceInit(void *pCfg) { nrf_gpio_cfg_output(AD5940_SPI_CS_PIN); nrf_gpio_cfg_output(AD5940_SPI_SCLK_PIN); nrf_gpio_cfg_output(AD5940_SPI_MOSI_PIN); nrf_gpio_cfg_input (AD5940_SPI_MISO_PIN,NRF_GPIO_PIN_PULLUP); nrf_gpio_cfg_output(AD5940_RESET_PIN); AD5940_CsSet(); AD5940_RstSet(); return ad5940_port_Init(); }

Parents
  • static const nrf_drv_spi_t ad5940_spi_handler = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    static volatile bool ad5940_spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
    
    
    void ad5940_spi_event_handler(nrf_drv_spi_evt_t const *p_event,void *p_context)
    {
        if(p_event->type == NRF_DRV_SPI_EVENT_DONE)
        {
            ad5940_spi_xfer_done = true;
        }
    }
    
    static void ad5940_spi_init(void)
    {
        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 = AD5940_SPI_MISO_PIN;
        spi_config.mosi_pin = AD5940_SPI_MOSI_PIN;
        spi_config.sck_pin  = AD5940_SPI_SCLK_PIN;
        spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
        spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        spi_config.mode     = NRF_DRV_SPI_MODE_0;
    
        APP_ERROR_CHECK(nrf_drv_spi_init(&ad5940_spi_handler, &spi_config, ad5940_spi_event_handler, NULL));
    }
    
    void AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length)
    {
    
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&ad5940_spi_handler, pSendBuffer, length, pRecvBuff, length));
        while(!ad5940_spi_xfer_done);
        ad5940_spi_xfer_done = false;
    
    }
    
    uint32_t ad5940_port_Init(void)
    {
        ad5940_spi_init();
        ad5940_int0_init();
        return 0;
    }
    void AD5940_CsClr(void)
    {
        AD5940_CS_CLEAR();//
    }
    
    void AD5940_CsSet(void)
    {
        AD5940_CS_SET();
    }
    void AD5940_RstClr()
    {
        nrf_gpio_pin_clear(AD5940_RESET_PIN);//
    }
    
    void AD5940_RstSet()
    {
        nrf_gpio_pin_set(AD5940_RESET_PIN);//
    }
    
    void AD5940_Delay10us(uint32_t time)
    {
        time/=100;
        if(time == 0) time =1;
        nrf_delay_ms(time);
    }
    uint32_t AD5940_GetMCUIntFlag(void)
    {
       return ucInterrupted;
    }
    
    
    uint32_t AD5940_ClrMCUIntFlag(void)
    {
       ucInterrupted = 0;
       return 0;
    }
    
    uint32_t  AD5940_MCUResourceInit(void *pCfg)
    {
        nrf_gpio_cfg_output(AD5940_SPI_CS_PIN);
        nrf_gpio_cfg_output(AD5940_SPI_SCLK_PIN);
        nrf_gpio_cfg_output(AD5940_SPI_MOSI_PIN);
        nrf_gpio_cfg_input (AD5940_SPI_MISO_PIN,NRF_GPIO_PIN_PULLUP);
    
        nrf_gpio_cfg_output(AD5940_RESET_PIN);
    
        AD5940_CsSet();
        AD5940_RstSet();
        return ad5940_port_Init();
    }
    

Reply
  • static const nrf_drv_spi_t ad5940_spi_handler = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    static volatile bool ad5940_spi_xfer_done;  /**< Flag used to indicate that SPI instance completed the transfer. */
    
    
    void ad5940_spi_event_handler(nrf_drv_spi_evt_t const *p_event,void *p_context)
    {
        if(p_event->type == NRF_DRV_SPI_EVENT_DONE)
        {
            ad5940_spi_xfer_done = true;
        }
    }
    
    static void ad5940_spi_init(void)
    {
        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 = AD5940_SPI_MISO_PIN;
        spi_config.mosi_pin = AD5940_SPI_MOSI_PIN;
        spi_config.sck_pin  = AD5940_SPI_SCLK_PIN;
        spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
        spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
        spi_config.mode     = NRF_DRV_SPI_MODE_0;
    
        APP_ERROR_CHECK(nrf_drv_spi_init(&ad5940_spi_handler, &spi_config, ad5940_spi_event_handler, NULL));
    }
    
    void AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length)
    {
    
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&ad5940_spi_handler, pSendBuffer, length, pRecvBuff, length));
        while(!ad5940_spi_xfer_done);
        ad5940_spi_xfer_done = false;
    
    }
    
    uint32_t ad5940_port_Init(void)
    {
        ad5940_spi_init();
        ad5940_int0_init();
        return 0;
    }
    void AD5940_CsClr(void)
    {
        AD5940_CS_CLEAR();//
    }
    
    void AD5940_CsSet(void)
    {
        AD5940_CS_SET();
    }
    void AD5940_RstClr()
    {
        nrf_gpio_pin_clear(AD5940_RESET_PIN);//
    }
    
    void AD5940_RstSet()
    {
        nrf_gpio_pin_set(AD5940_RESET_PIN);//
    }
    
    void AD5940_Delay10us(uint32_t time)
    {
        time/=100;
        if(time == 0) time =1;
        nrf_delay_ms(time);
    }
    uint32_t AD5940_GetMCUIntFlag(void)
    {
       return ucInterrupted;
    }
    
    
    uint32_t AD5940_ClrMCUIntFlag(void)
    {
       ucInterrupted = 0;
       return 0;
    }
    
    uint32_t  AD5940_MCUResourceInit(void *pCfg)
    {
        nrf_gpio_cfg_output(AD5940_SPI_CS_PIN);
        nrf_gpio_cfg_output(AD5940_SPI_SCLK_PIN);
        nrf_gpio_cfg_output(AD5940_SPI_MOSI_PIN);
        nrf_gpio_cfg_input (AD5940_SPI_MISO_PIN,NRF_GPIO_PIN_PULLUP);
    
        nrf_gpio_cfg_output(AD5940_RESET_PIN);
    
        AD5940_CsSet();
        AD5940_RstSet();
        return ad5940_port_Init();
    }
    

Children
No Data
Related