SPI_rack


class spirack.SPI_rack(port=None, baud=None, timeout=None, use_lock=True)

The SPI rack class is used to interface with the SPI rack controller unit. It implements the protocol used to read and write data and set an active module. Use the writeData/readData functions instead of the read/write functions of the serial library.

An instance of SPI rack needs to be passed to every module object. Only one instance per SPI Rack.

Parameters:

  • port (string) - serial port used by SPI rack controller unit
  • baud (int) - baud rate value for the virtual serial port
  • timeout (int) - data receive timeout in seconds
  • use_lock (bool) - use a lock for threading purposes, default true

Methods

get_temperature()

Returns the temperature in the C1b module. Reads the temperature from the internal C1b temperature sensor. Does not work for the C1. Accuracy is +- 0.5 degrees in 0-70 degree range.

Returns - temperature in Celsius (float).


get_battery()

Returns battery voltages. Calculates the battery voltages from the ADC channel values. Currently only works for the C1b/C2 combination.

Returns - list of floats: [VbatPlus, VbatMin].


get_firmware_version()

Returns the firmware version of the C1/C2 as a string in the format: ‘version - compilation date - author’. This has only been added from firmware version v1.5 onwards for the C2 and v1.3 for the C1.

Returns - firmware version (string)


trigger_now()

Sends a trigger signal to the backplane on trigger 1 immediately. Only works on the C1b/C2 combination for now.


trigger_arm()

Sends a trigger signal to the backplane on trigger 1 at the next write_data or read_data call. Timing is assured by the C2 unit. Only works on the C1b/C2 combination for now.


unlock()

Unlocks SPI communication. After power-up of the Arduino DUE, SPI write communication is blocked as a safety precaution when working with DAC Modules. By preventing SPI write actions to be performed, the current DAC state is preserved and can be read back by the user.


lock()

Locks SPI communication. Prevent SPI write actions. See unlock.


set_ref_frequency(frequency)

Set the reference frequency present on the backplane (Hz). The reference frequency is shared between all modules. This info can be used by other modules for calculation, for example the s5i RF generator module needs to know the frequency for external reference use.

Parameters:

  • frequency (int) - the reference frequency on the backplane (in Hz)

write_data(module, chip, SPI_mode, SPI_speed, data)

Write data to selected module/chip combination.

Parameters:

  • module (int) - module number that data needs to be send to
  • chip (int) - chip in the module that the data needs to be send to
  • SPI_mode (int) - SPI mode of the chip to be activated
  • SPI_speed (int) - SPI clock speed of the chip to be activated
  • data (bytearray) - array of data to be send

read_data(module, chip, SPI_mode, SPI_speed, data)

Read data from selected module/chip combination

Parameters:

  • module (int) - module number that data needs to be send to
  • chip (int) - chip in the module that the data needs to be send to
  • SPI_mode (int) - SPI mode of the chip to be activated
  • SPI_speed (int) - SPI clock speed of the chip to be activated
  • data (bytearray) - array of data to be send

Returns - Bytes received from module/chip (list of integers).


write_bulk_data(module, chip, SPI_mode, SPI_speed, data)

This function allows for the writing of large amount of data. The control of the chip select line is done by the PC, which makes it uncertain. The data is split in chunks of 60 bytes, as this is the maximum amount that can be send in one transfer to the controller. This also adds a slight uncertainty in the timing between the packets of 60 bytes. Use with caution.

Parameters:

  • module (int) - module number that data needs to be send to
  • chip (int) - chip in the module that the data needs to be send to
  • SPI_mode (int) - SPI mode of the chip to be activated
  • SPI_speed (int) - SPI clock speed of the chip to be activated
  • data (bytearray) - array of data to be send

read_bulk_data(module, chip, SPI_mode, SPI_speed, data)

This function allows for the reading of large amount of data. The control of the chip select line is done by the PC, which makes it uncertain. The data is split in chunks of 60 bytes, as this is the maximum amount that can be send in one transfer to the controller. This also adds a slight uncertainty in the timing between the packets of 60 bytes. Use with caution.

Parameters:

  • module (int) - module number that data needs to be send to
  • chip (int) - chip in the module that the data needs to be send to
  • SPI_mode (int) - SPI mode of the chip to be activated
  • SPI_speed (int) - SPI clock speed of the chip to be activated
  • data (bytearray) - array of data to be send

Returns - Bytes received from module/chip (list of integers).


_set_active(module, chip, SPI_mode, SPI_speed)

Set the current module/chip to active on controller unit. By writing ‘c’ and then chip/module combination, this chip will be set active in the SPI rack controller. This means that all the data send after this will go to that chip. This method is for internal use only!

Parameters:

  • module (int) - module number to set active
  • chip (int) - chip in module to set active
  • SPI_mode (int) - SPI mode of the chip to be activated
  • SPI_speed (int) - SPI clock speed of the chip to be activated

read_adc(channel)

Reads the ADC for battery voltage: it reads the given ADC channel. These channels are connected to the raw power supply of the battery. Output needs to calculated due to voltage divider. This method is for internal use only!

Parameters:

  • channel (int) - the ADC channel to be read

Returns - 12-bit ADC data (int).


Attributes

Attribute Info
active_module Keeps track of which module is currently active
active_chip Keeps track of which chip in a module is currently active
active_speed Keeps track of the current SPI speed the controller is set to
ref_frequency The current external reference frequency (in Hz)