- Ameba defines the PHA
With the SPI, the clock polarity (SCPOL) configuration parameter determines whether the inactive state of the serial clock is high or low. To transmit data, both SPI peripherals must have identical serial clock phase (SCPH) and clock polarity (SCPOL) values.
- CPOL = 0 SCK is Low when SPI is inactive.
- CPOL = 1 SCK is High when SPI is inactive.
- SCPH = 0 the SS toggle every frame. Indicates that the signal is received in first edge (Rising, when CPOL=0. Falling, when CPOL=1.).
- SCPH = 1 the SS toggle at start and stop. Indicates that the signal is received in second edge (Rising, when CPOL=1. Falling, when CPOL=0.).
When SCPH = 0 the chip select toggle every frame. If other devices do not accept this setting, you can use another GPIO pin to control CS just toggle at start and stop.
There are four possible transfer modes on the DW_apb_ssi for performing SPI serial transactions. For transmit and receive transfers (transfer mode field of the Control Register = 2’b00), data transmitted from the DW_apb_ssi to the external serial device is written into the transmit FIFO. Data received from the external serial device into the DW_apb_ssi is pushed into the receive FIFO.
*Default is mode 3.
Please check example spi to check how to set SCPOL_INACTIVE & SCPH_TOGGLES.
/* SCPOL_INACTIVE_IS_LOW & SCPH_TOGGLES_IN_MIDDLE */ spi_format(&spi_master, 8, 0, 0); /* SCPOL_INACTIVE_IS_LOW & SCPH_TOGGLES_AT_START */ spi_format(&spi_master, 8, 1, 0); /* SCPOL_INACTIVE_IS_HIGH & SCPH_TOGGLES_IN_MIDDLE */ spi_format(&spi_master, 8, 2, 0);
Interrupt mode and DMA mode
- Interrupt mode
Please check example spi & spi_multislave to check how to set interrupt mode.
/* send & recv one frame*/ spi_master_write(&spi_master, TestData); spi_slave_read(&spi_slave); /* send & recv target length data use interrupt mode */ spi_master_write_stream(&spi_master, TestBuf, TEST_BUF_SIZE);
- DMA mode
If using high-speed SPI, it is recommended to use DMA mode instead of interrupt mode to reduce the consumption of CPU resources.
Please check example spi_stream_twoboard to check how to set DMA mode.
/* send & recv target length data use DMA mode */ spi_master_write_stream_dma(&spi_master, TestBuf, TEST_BUF_SIZE); spi_slave_read_stream_dma(&spi_slave, TestBuf, TEST_BUF_SIZE);