Hi,
I have a problem with my SPIM read buffer. As you can see below, my SPI device received bytes correctly and answer correctly
My code is based on SPI example SDK 12.1.
SPI initialisation
void SPI_init(nrf_drv_spi_t* spi_inst, uint32_t pin_ss, nrf_drv_spi_mode_t mode, nrf_drv_spi_frequency_t freq)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = pin_ss;
spi_config.miso_pin = MISO_PIN;
spi_config.mosi_pin = MOSI_PIN;
spi_config.sck_pin = SCLK_PIN;
spi_config.frequency = freq;
spi_config.mode = mode;
APP_ERROR_CHECK(nrf_drv_spi_init(spi_inst, &spi_config, spi_event_handler));
}
SPI default config
#define NRF_DRV_SPI_DEFAULT_CONFIG \
{ \
.sck_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.mosi_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.miso_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.ss_pin = NRF_DRV_SPI_PIN_NOT_USED, \
.irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY, \
.orc = 0xFF, \
.frequency = NRF_DRV_SPI_FREQ_4M, \
.mode = NRF_DRV_SPI_MODE_0, \
.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST, \
}
SPI read / write function
void SPI_write_read_block(nrf_drv_spi_t* inst, uint8_t* ptx, uint8_t* prx, uint8_t m_length)
{
APP_ERROR_CHECK(nrf_drv_spi_transfer(inst, ptx, m_length, prx, m_length));
while (!spi_xfer_done)
{
__WFE();
}
spi_xfer_done = false;
}
SPI read / write used
static uint16_t POT_read(TAD5144* ad, uint16_t reg)
{
ad->tx_dat[0] = HI_UINT16(reg);
ad->tx_dat[1] = LO_UINT16(reg);
SPI_write_read_block(ad->inst_spi, ad->tx_dat, NULL, 2);
SPI_write_read_block(ad->inst_spi, NULL, ad->rx_dat, 2);
return BUILD_UINT16(ad->rx_dat[1], ad->rx_dat[0]);
}
Questions
- On SPI MISO, my data is correct, what kind of problem could be occured that MISO pin will not copy the data through easyDMA on buffer (RXD.PTR correctly initialized)
- What I doing wrong ?
- Something isn't correclty configured ?
SPIM0 register configuration