Saturday, April 8, 2023

Controlling the SPI link on the Cyclone V is fairly different from Arduino, Raspberry Pi and others

OTHER SYSTEMS USE CALLS TO SPI LIBRARIES TO ABSTRACT HARDWARE REGISTERS

Although SPI on all those systems ultimately are controlled by setting bits and values in control registers, plus storing or fetching from other registers, the programmer has handy libraries that simplify this. On the Arduino the object SPISettings will define CPOL, CPHA and the clock rate - as well as what bit order a word is transmitted in. SPI.BeginTransaction() will actually configure and start the link with these settings. 

The Raspberry Pi Pico uses a call to spi_init to set the clock rate and assigned pins (the pins are fixed on the Arduino). spi_set_parameters is the call to control CPOL, CPHA and other parameters. Similar in nature but different from the Arduino. Both of these convert the calls to manipulating bits in control registers. 

CYCLONE V UNDER LINUX DOES NOT USE LIBRARY CALLS

The SPI hardware is controlled by hardware registers, much as are the others, but those registers are memory mapped to the 4GB address space such that they are set or read by fetch and store to memory locations. As I determine the frame size, CPOL/CPHA, clock rate and other characteristics, I have to set those bits/values in locations that map to the control registers.

Deviating from the practice of the other systems, where a general purpose IO pin is written to assert or release the 'slave select' line for a given remote destination, on the Cyclone V bits in a control register turn on or off the SS lines. Thus by storing into a memory location I cause the SS line to be controlled. 

The SPI system of the Cyclone V also has support for multiple types of interrupts, DMA operation and other sophistications that I won't need, all of them controlled by writes to the memory mapped control registers. 

Finally, writing from the Cyclone to the LCD module is done by storing data in a memory location. The status location tells me when the transfer is complete and I can pick up the returned word from that same memory location. The actual writing and reading will be very straightforward and clean, once I initialize all the memory locations to appropriate values. 

No comments:

Post a Comment