![]() |
CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
|
Spi for relays drivers, ADC and Pga DACS
SUMMARY:
SPI communication follows the same approach adopted for I2C and CAN bus: exploitation of the CMSIS drivers. To this aim there is available a set of functions:
So that an example of their use is the following:
To use the SPI first of all we need to intialize it and this is done by SPI_Inizialize() that collects a few functions between those listed above. SPI is used by the relay drivers, the ADC and the DAC of the PGA. It is therefore set according to them. As an instance, the relay drivers communicate with 8 bits, while the DAC with 16 bits. The core of SPI_Inizialize() is the setting of some bits and the clock by calling SPIdrv->Control(). The setting bits for SPIdrv->Control() are defined at SPI_control_for_relay_driver (the meaning of the bits can be verified at Bits meaning for SPI settings) with the speed spi_clock_for_relais, this is the defaul setting.
Every time we manage the realis or the DAC we need to set the SPI accordingly to the parallelism and the speed. For their setting 2 macros are defined: SPI_control_for_DAC with SPI_DAC_SPEED for the DAC and SPI_control_for_relay_driver with spi_clock_for_relais for the relais. An example for their setting is here:
Where SPI_control_for_relay_driver is:
while spi_clock_for_relais is:
Transmission and reception is done with SPIdrv->Send() and SPIdrv->Receive(), and the polling at SPIdrv->GetStatus().busy. SPIdrv->GetStatus() ia a structue:
Data Fields | ||
---|---|---|
uint32_t | busy: 1 | Transmitter/Receiver busy flag. |
uint32_t | data_lost: 1 | Data lost: Receive overflow / Transmit underflow (cleared on start of transfer operation) |
uint32_t | mode_fault: 1 | Mode fault detected; optional (cleared on start of transfer operation) |
uint32_t | reserved: 29 |
We explooit the field busy, that remains "1" till the SPI operation has concluded.
The SPI_callback() is called after SPI operation has concluded, as a result of the interrupt. If necessary there is available the global evento_SPI which can be alternatively checked in polling, or to verify if a problem has occurred. evento_SPI can take the following values:
Parameter event | Bit | Description supported when ARM_SPI_CAPABILITIES |
---|---|---|
ARM_SPI_EVENT_TRANSFER_COMPLETE | 1 << 0 | Occurs after call to ARM_SPI_Send, ARM_SPI_Receive, or ARM_SPI_Transfer to indicate that all the data has been transferred. The driver is ready for the next transfer operation. |
ARM_SPI_EVENT_DATA_LOST | 1 << 1 | Occurs in slave mode when data is requested/sent by master but send/receive/transfer operation has not been started and indicates that data is lost. Occurs also in master mode when driver cannot transfer data fast enough. |
ARM_SPI_EVENT_MODE_FAULT | 1 << 2 | Occurs in master mode when Slave Select is deactivated and indicates Master Mode Fault. The driver is ready for the next transfer operation. |
Here an example of use of the polled transmission with DAC:
The functions invoked within the fw are the following:
First and only function to be used is the SPI_Inizialize():
The codes for SPI is at: