I3MPS - Exercise 8: LDD With SPI

Introduction
In this exercise a driver for the on-board DAC7612 digital to analog converter will be made. SPI will be used to control the converter. An example driver for the on-board ADC7870 is provided.

ADC7870 driver code files
ads7870.c

ads7870.h

ads7870-core.c

ads7870-core.h

ads7870-spi.c

ads7870-spi.h

Makefile

a) Voltage divider
The voltage divider is build out of 1 10k ohm and 5 2k ohm resistors, like this.



b) Testing voltage divider and ADC driver
The divider is connected to +5 V, GND and ADC0.

The driver, ADS7870mod.ko is loaded on the devkit8000 and cat is used to measure the voltage.

Result: The different points measured with voltmeter:

A: 2.60 V

B: 2.08 V

C: 1.56 V

D: 1.04 V

E: 0.52 V

Measuring the voltage using cat:

root@beagleboard:~# cat /dev/adc7870

Using less makes it easier to read the numbers.



c) The DAC driver
Generel information regarding the addon board can be found here devkit8000addon homepage

The schematics show that the dac7612 is using the SPI interface and chip select 3. The interface page shows the pins on connector J4 the dac7612 is using.

Changing numbers in the code
The chip select is changed from 0 to 3. The datasheet for the dac7612 states that the spi speed can go as high as 20 MHz, but it is kept at the same 15MHz as the adc driver for now. The dac uses the same polarity as the adc, so that is also the samme.

The numbers of bits that need to be sent to the dac is 14, 2 bits for address and 12 bits for value.

The driver was changed to use the major number 65 (at this point in the exercise mostly to have the possibility to have both the adc and the dac driver loaded in the core).

d) Using init to test DAC driver
The write function in dac7612_spi.c file:

The following lines are added to set a value on the DAC in the init and exit functions of the dac7612-core.c file.

The following defines where added to dac7612-core.h

Testing the program on devkit8000
A multimeter was connected to the J4 connector PIN 2 and PIN 15. It measured 1.005 V when the driver was inserted and 2.01 V when the driver was removed.

e) Implementing write
The write method mostly consist of the code already supplied in the adc driver.

Testing 2000 mV:

root@beagleboard:~# echo 2000 > /dev/dac7612 2000 Jan 1 00:25:54 beagleboard [ 1558.599487] Writing to dac7612 [Minor] 0 root@beagleboard:~# cat /dev/adc7870 | less

gives a lot of spam of the following:

@2000@2004@2005@2004

Testing 1000 mV:

root@beagleboard:~# echo 1000 > /dev/dac7612 2000 Jan 1 00:30:34 beagleboard [ 1838.337585] Writing to dac7612 [Minor] 0 root@beagleboard:~# cat /dev/adc7870 | less

gives

@1002@1003@1001@1002@

General comments to the exercise
Nothing atm.

Source code
dac7612.c

dac7612.h

dac7612-core.c

dac7612-core.h

dac7612-spi.c

dac7612-spi.h