Cannot properly switch SPI MODE on ATSAME70Q21

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using SPI and the ASF library on a custom ATSAME70Q21 board.  The following code shows how the SPI is being setup and programmed.  The DAC device (DAC8851) is being accessed using SPI MODE 2.  The ADC device (CS5532) is being accessed using SPI MODE 0.

Once the SPI switches into SPI MODE 2 for the DAC access, the bus does not return to SPI MODE 0 for access of the ADC after de-selection.  The bus appears to remain in SPI MODE 2.

What might be going on here?

 

struct spi_device spi_device_conf_dac =    // DAC 
{
       .id = 0
};

struct spi_device spi_device_conf_adc =        // ADC
{
    .id = 1
}; 

void setup_spi(void)
{
    pio_configure(PIOD, PIO_PERIPH_B, (PIO_PD22 | PIO_PD21 | PIO_PD20), PIO_DEFAULT);     
    spi_master_init(SPI0);
    spi_master_setup_device(SPI0, &spi_device_conf_dac, SPI_MODE_2, SPEED_DAC, 0);
    spi_master_setup_device(SPI0, &spi_device_conf_adc, SPI_MODE_0, SPEED_ADC, 1);
    spi_enable(SPI0);
}

void send_bufffer_dac(uint8_t *buffer, size_t siz)
{
    set_spi_state_dac();
    dac_cs_state(CS_DOWN);
    spi_select_device(SPI0, &spi_device_conf_dac);
    spi_write_packet(SPI0, buffer, siz);
    spi_deselect_device(SPI0, &spi_device_conf_dac);
    dac_cs_state(CS_UP);
    
} // end

void send_buffer_adc(uint8_t *buffer, size_t siz)
{
    set_spi_state_adc();
    adc_cs_state(CS_DOWN);
    spi_select_device(SPI0, &spi_device_conf_adc);
    spi_write_packet(SPI0, buffer, siz);
    spi_deselect_device(SPI0, &spi_device_conf_adc);
    adc_cs_state(CS_UP);
} // end