AN1921 Motorola / Freescale Semiconductor, AN1921 Datasheet - Page 11

no-image

AN1921

Manufacturer Part Number
AN1921
Description
AN1921 General DSP568xx Interface Examples using the Embedded SDK
Manufacturer
Motorola / Freescale Semiconductor
Datasheet
}
When compiled and executed on the target EVM, the code in
bi-directionally between the application code and the ADC chip, using the DSP’s SPI0 port.
The Embedded SDK header files spi.h and bsp.h appear in procedure InitTLC2543.c and provide the
data structures and other defines required for this code to interface to the processor in general and to
the SPI port in particular. The data structure SpiParams is defined from the data type
spi_sParams. The variable SPIMaster is used to store the SPI ports handle. In this example, the
variable ADcmd is both defined and set to a value 0x8c00. ADcmd is the command word sent to the
TLC2543 ADC chips data input. In the upper 8-bit portion of the word, it specifies use of the eighth
analog input port on the ADC; a 16-bit word format, MSB first; and unsigned integer format for
output.
To indicate that the DSP’s SPI0 port will be the master device, a field (.bSetAsMaster) in the data
structure SpiParams is set . A call is made to open() to allocate the SPI0 port, a handle to the port is
returned in the variable SPIMaster. Several calls to the procedure ioctl() are used to further refine the
SPI0 port’s attributes. The first call sets the bit block rate from the PHI clock by providing a divisor
term, SPI_PHI_DIVIDER_32. This controls the clock rate of the timing pulses by dividing the clock
rate by 32. Next, the command word SPI_DATAFORMAT_RAW specifies that data transfers
between the SPI and the slave device will be 16 bits long. The next call to ioctl() specifies that the
generated SS signal directed to the chip’s CS port be left low between the word’s byte components.
All the SPI port’s attributes have been set. An infinite loop now follows to exercise the link between
the SPI0 and the TLC2543 ADC. To average out the possible errors in the reading of the integrated
pressure sensor, MPX4115A, 64 measurements of the ADC are done, one millisecond apart. For a
description of the MPX4115A integrated pressure sensor, see
The loop that performs the actual measurement consists of a call to write() to send the variable ADcmd
to the TLC2543. A call to read() follows to read the previous sampling period’s count from the sensor.
The result is placed in Datain. The data (Datain) read must be shifted to the right by 4 bits, since it is a
12-bit result placed in a 16-bit word. A call to nanosleep() puts the process to sleep for one
millisecond.
BaroPress = (Vcount >> 2) + (Vcount >> 6) + (Vcount >> 8)
}
close(SPIMaster);
Since the sensors measures absolute pressure the units can
be converted to more recognizable units of millibars. The
conversion factors is 1 millibar = 100 Pa applied to the
last equation yields
which is source of coded equation. The four shifts
in the coded form of equation produce an approximation
of 0.2715 */
P = 0.0271*Vcount + 10.555 (kPa)
P = 0.271*Vcount + 105.55
Interface Examples Using the Embedded SDK
+ (Vcount >> 9 ) + 105;
Interfacing to Serial Devices Using the SPI Port
Appendix E.
Code Example 2
shows that data flows
11

Related parts for AN1921