<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf52832+SPI+AD5940 cannot get ad5940id</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81564/nrf52832-spi-ad5940-cannot-get-ad5940id</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Nov 2021 13:24:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81564/nrf52832-spi-ad5940-cannot-get-ad5940id" /><item><title>RE: nrf52832+SPI+AD5940 cannot get ad5940id</title><link>https://devzone.nordicsemi.com/thread/338183?ContentTypeID=1</link><pubDate>Tue, 09 Nov 2021 13:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbe84203-b8c6-456f-ab38-125824014224</guid><dc:creator>edicui</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static const nrf_drv_spi_t ad5940_spi_handler = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**&amp;lt; SPI instance. */
static volatile bool ad5940_spi_xfer_done;  /**&amp;lt; 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-&amp;gt;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(&amp;amp;ad5940_spi_handler, &amp;amp;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(&amp;amp;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();
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>