Master SPI chip select SAME70 demo doesnt work

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using spi example project for the SAME70 and have verified that clock and data are coming out. However, I am not getting chip select coming out from the demo board. Can someone point in the right direction how to configure and determine the chip select pin?

 

/* Chip select. */

#define SPI_CHIP_SEL 0

#define SPI_CHIP_PCS spi_get_pcs(SPI_CHIP_SEL)

 

static void spi_master_initialize(void)

{

g_uc_role = MASTER_MODE;

puts("-I- Initialize SPI as master\r");

/* Configure an SPI peripheral. */

spi_enable_clock(SPI_MASTER_BASE);

spi_disable(SPI_MASTER_BASE);

spi_reset(SPI_MASTER_BASE);

spi_set_lastxfer(SPI_MASTER_BASE);

spi_set_master_mode(SPI_MASTER_BASE);

spi_disable_mode_fault_detect(SPI_MASTER_BASE);

spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_PCS);

spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);

spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);

spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL,

SPI_CSR_BITS_8_BIT);

spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL,

(sysclk_get_peripheral_hz() / gs_ul_spi_clock));

spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS,

SPI_DLYBCT);

spi_enable(SPI_MASTER_BASE);

}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi ,

You should initial SPI Chip Selection Pin first before you using it.

For example, in init.c you can find in void board_init(void):

#ifdef CONF_BOARD_SPI

ioport_set_pin_peripheral_mode(SPI0_MISO_GPIO, SPI0_MISO_FLAGS);

ioport_set_pin_peripheral_mode(SPI0_MOSI_GPIO, SPI0_MOSI_FLAGS);

ioport_set_pin_peripheral_mode(SPI0_NPCS0_GPIO, SPI0_NPCS0_FLAGS);

ioport_set_pin_peripheral_mode(SPI0_SPCK_GPIO, SPI0_SPCK_FLAGS);

#endif

 

After SPI NPCS IO get initialized, you can use spi_select_device/spi_deselect_device to set/clear spi chip selection before sending data.

Here is a simple example.

status_code_t spi_write_then_read(Spi* port, uint32_t cs_indx, uint8_t* wbuf, uint8_t* rbuf, uint32_t len)
{
    status_code_t ret = STATUS_OK;
    
    spi_select_device(port,&spi_device_conf);
    ret = spi_transceive_packet(port, wbuf, rbuf, len);
    spi_deselect_device(port,&spi_device_conf);
    return ret;
}

 

Hope it's helpful for you.

Best Rds