The firmware

The are two versions of the firmware:

  1. UART-enabled
  2. SPI-enabled

Current UART- and SPI-version differ mainly in the communication protocol used.¹ For UART the data-rate is 115.2 kbps so transmission a full dataset takes 640 ms to complete. For SPI the data-rate is 16 Mbps so transmission of a full dataset takes 4 ms.

The consequence is that with SPI, frame rates of at least 75 Hz is feasible², whereas the UART firmware can’t read the CCD much faster than 1.25 Hz.

Because SPI and UART are different and behave differently, there are also small differences in main() and some of the interrupts. Look in the source code if you’re interested in specific details.

The fM-frequency is 2.0 MHz by default, but can be changed by editing main.h and recompiling.

The user LED on the nucleo boards flashes with the ICG-frequency. The feature may be disabled by editing stm32f4xx_it.c but it can be useful for debugging (or simply checking if the upload went well).


Connections

The CCD should be connected to the nucleo board through the following GPIO’s:

  1. fM connects to PB0
  2. SH connects to PA1
  3. ICG connects to PA0
  4. Output connects to PC0

look at the howto for more details.


Interface (UART)

The UART-enabled firmware can communicate with any  pc over the nucleo’s USB connection. You can use the software presented on this site, or the Jens-Ulrich Fröhlich’s java-based GUI.

You can of course also do it your own way, it should be fairly straightforward with something like LabVIEW or MATLAB. Daniele Zannoni wrote a matlab script for the TCD1304 firmware.

Here’s how to communicate with the UART-firmware:

To request a recording with an integration time of t_int, send the following 12 bytes to the nucleo:

0x45 0x52 0xSS 0xTT 0xUU 0xVV 0xKK 0xLL 0xMM 0xNN 0x01 0xYY

The two first are simply a key (the letters ‘ER’) for the nucleo to recognize. The data ends up in a circular buffer, so it’s necessary to know where to start reading.

The next 2x 4 bytes constitute the two 32-bit numbers holding the SH- and ICG-period respectively. The SH-period defines the integration time:

t_int = SH-period / 2.0 MHz

To satisfy the timing requirements of the CCD, make sure the following is obeyed:

ICG-period = n·SH-period ≥ 14776

The 11th byte is the pc ready flag (it’s actually not needed, except for compatibility reasons), and the 12th byte is the number of integrations to average. The firmware can collect and average up to 15 integrations.

Upon completion of UART-reception an interrupt is generated after which the firmware flushes the CCD, reconfigures the timers driving the CCD and collects the desired number of integrations.

When done reading, the nucleo transmits 7388 bytes, which must be combined on the receiving side to 3694 16-bit values.


Interface (SPI)

The SPI-version must be connected to a raspberry pi (or something else with an SPI-controller).

The SPI firmware will only work with a CLI or GUI written specifically for SPI, and similarly for UART. It’s entirely possible to connect a nucleo with the UART-fw to a raspberry pi, but the rpi must then use the programs written for UART.

You can of course also do it your own way, it should be fairly straightforward. Here’s how to communicate with the SPI-firmware:

To request a recording with an integration time of t_int, send 7388 bytes to nucleo of which the first 12 must conform to this format:

0x45 0x52 0xSS 0xTT 0xUU 0xVV 0xKK 0xLL 0xMM 0xNN 0x01 0xYY

The two first are simply a key (the letters ‘ER’) for the nucleo to recognize, whether  the user is requesting a new integration or not.

The next 2x 4 bytes constitute the two 32-bit numbers holding the SH- and ICG-period respectively. The SH-period defines the integration time:

t_int = SH-period / 2.0 MHz

To satisfy the timing requirements of the CCD, make sure the following is obeyed:

ICG-period = n·SH-period ≥ 14776

The 11th byte is the pc ready flag (it’s actually not needed, except for compatibility reasons). The 12th is not used in the SPI-enabled firmware.

Upon completion of SPI-reception an interrupt is generated after which the firmware flushes the CCD, reconfigures the timers driving the CCD and collects one integration.

The user must then send another 7388 bytes, to collect the data from the CCD. Finally the 7388  8-bit values must be combined on the receiving side to 3694 16-bit values.


About the SH-period

For reasons unknown to me, odd SH-periods cause periodic noise, so I recommend you stick with even numbers for the SH-period.


¹ Prior to March 2017, the SPI-enabled firmware used other GPIO’s than the UART.

² At 2.0 MHz the CCD read-out time is 7.4 ms and the theoretical transmission time is 3.7 ms. This gives a theoretical frame-rate of:
(7.4ms + 3.7ms)⁻¹ = 89 Hz.
The experimental transmission time is 4.2 ms corresponding to a practical limit of 86 Hz. With an fM of 4.0 MHz the read-out time is 3.7 ms, giving a practical frame-rate of 126 Hz.
If an even faster frame-rate is needed, the ADC-DMA can be set up in double-buffering mode. The STM32F401RE will then be able to transmit and collect data simultaneously, yielding a frame-rate of:
(4.2 ms)⁻¹ = 238 Hz
If a faster SPI-controller than the rpi’s is used, the frame-rate can be as high as (3.7ms)⁻¹ = 270 Hz, but probably not higher, as the TCD1304 is specified to run with a maximum clock of 4.0 MHz.

Advertisements