Extended Use of SPI on AG32

The AG32 supports two SPI interfaces, namely: SPI0 and SPI1;

Both interfaces are functionally equivalent and only support SPI-Master mode.

SPI is a full-duplex synchronous serial communication protocol that supports high-speed data transmission.

Determine whether to use the “extended mode”:

The default SPI driver in the SDK is encapsulated for use with flash memory and cannot be used for general peripherals like the generic SPI from ST.

If you want to use it for other peripherals, the device must meet certain timing requirements (refer to the detailed description in the datasheet).

Timing constraints:

1. The first segment of SPI interaction must be tx (it cannot be rx);

2. Receiving and sending cannot occur simultaneously (you must finish sending before receiving);

3. There cannot be any tx after rx (rx must be the last segment of a single interaction);

Please confirm whether the peripheral meets the above constraints before using SPI:

If it does, you can simply use the sample code from example_spi_common.c.

If it does not meet the requirements, for example, if the first action is to receive data from SPI, you must use the extended SPI mode described here.

(Note: If possible, please try to use the sample from example_spi_common.c. The extended SPI mode here requires additional CPLD integration, which can be cumbersome to implement.)

The functionality here corresponds to the example in SDK1.5.2 located at \examples\spi\full_duplex_spi.

Functions extended from the “extended mode”:

Original functions provided in example_spi_common.c:

1. Send: Simply sends data, with no limit on the number of bytes;

2. SendAndRecv: Sends a segment of data and then receives a segment of data within a single chip select cycle; the maximum send length is 4 bytes, while the receive length is unlimited.

(If you need to send longer lengths, please extend it in the C driver.)

Here, two additional functions are extended:

1. Recv: Simply receives data, with a length limit of less than 124 bytes;

2. SendWithRecv: Sends data while receiving (bidirectional transmission), rather than sending all data before receiving.

The lengths of the received and sent data must be equal.

Additionally, new settings for SPI have been added: polarity, phase, and endianness.

Extended Use of SPI on AG32Extended Use of SPI on AG32

Leave a Comment