
VMX51C1020
_________________________________________________________________________________________________
www.ramtron.com
page 50 of 80
SPI Frame Select Control
It’s also possible to generate a positive pulse on
the CS3 pin of the SPI interface by setting the
FSONCS3 bit of the SPICONFIG register. This
feature can be used to generate a Frame Select
signal required by some DSP compatible
devices without requiring the use of a separate
I/O pin.
Note that when both the SPILOAD and
FSONCS3 are selected, the internal logic give
priority to the Frame Select pulse.
SPI Interface to 16-bit D/A Example
The following is a code example for doing 16-bit
transfers over the the SPI interface.
//---------------------------------------------//
// VMIX_SPI_to_dac_interface. c //
//---------------------------------------------//
//
// This demonstration program show the how to interface a 16-bit D/A
// to the VMX51C1020 SPI interface.
//
#pragma SMALL
#include <vmixreg.h>
// --- function prototypes
//Function Prototype: Send Data to the 16 bit D/A
void send16bitdac( unsigned char valhigh, unsigned char vallow);
// Bit definition
sbit SPI_TX_EMPTY = USERFLAGS^0;
//------------------------------------------------------------------------------//
// MAIN FUNCTION //
//-----------------------------------------------------------------------------//
at 0x0100 main (void) {
unsigned char dacvall=0;
unsigned char dacvalh=0;
DIGPWREN |= 0x08;
//*** Initialise the SPI interface ****
P2PINCFG |= 0x68;
//LSB of current DAC value
//MSB of current DAC value
//ENABLE SPI INTERFACE
// config I/O port to allow the SPI
//interface to access the pins
// In this application we only need to configure the 5 upper bit of P2PINCFG
// P2PINCFG bit 7 - SDIEN = 0 -> INPUT (NOT USED)
// P2PINCFG bit 5 - SCKEN = 1 -> OUTPUT TO DAC SCK PIN
// P2PINCFG bit 4 - SSEN = 0 -> INPUT (NOT USED)
// P2PINCFG bit 3 - CS0EN = 1 -> OUTPUT TO DAC CS PIN
// P2PINCFG bit 2 - CS1EN = 0 -> INPUT (NOT USED)
// P2PINCFG bit 0 - CS3EN = 0 -> INPUT (NOT USED)
SPICTRL = 0x25;
// SPI ctrl: OSC/16, CS0, phase=0, pol=0, master
// SPICK BIT 7:5 = 001 -> SPI CLK SPEED = OSC/2
// SPICS BIT 4:3 = 00 -> CS0 LINE IS ACTIVE
// SPICKPOL BIT 1 = 0 SPI CLOCK POLARITY
// SPIMA_SL BIT 0 = 1 -> SET SPI IN MASTER MODE
SPICONFIG = 0x00;
// SPICSLO BIT 7 = 0 AUTOMATIC CHIP SELECT CONTROL
// UNSUSED BIT 6 = 0
// FSONCS3 BIT 5 = 0 Do not send FrameSelect Signal on CS3
// UNUSED BIT 3 = 0
// SPIRXOVIE BIT 2 = 0 Dont enable SPI RX Overrun IRQ
// SPIRXAVIE BIT 1 = 0 Dont enable SPI RX AVAILLABLE IRQ
// SPITXEMPIE BIT 0 = 0 Dont Enable SPI TX EMPTY IRQ
SPISIZE = 0x0F;
// SPI SIZE: 16-bits
// GENERATE A TRIANGLE WAVE ON THE DAC OUTPUT
while(1){
do{
dacvall = dacvall + 1;
if( dacvall==0xff)
{
dacvalh = dacvalh +1;
dacvall = 0x00;
}
send16-bitdac( dacvalh, dacvall);
}while( (dacvall != 0xff) && (dacvalh != 0xff) );
do{
dacvall = dacvall - 1;
if( dacvall==0x00)
{
dacvalh = dacvalh - 1;
dacvall = 0xff;
}
send16-bitdac( dacvalh, dacvall);
}while( (dacvall != 0x00) && (dacvalh != 0x00) );
};
}// End of main()...
//-----------------------------------------------------------------------//
// Send16-bitdac - Send data to 16 bit D/A Converter //
//-----------------------------------------------------------------------//
void send16-bitdac( unsigned char valhigh, unsigned char vallow){
//
USERFLAGS = 0x00;
//
while(!SPI_TX_EMPTY){USERFLAGS = SPIIRQSTAT;}
SPIRX2TX1 = vallow;
//Put LSB of value in SPI transmit buffer
//-> trigger transmission
//Put MSB of value in SPI transmit buffer
//-> trigger transmission
SPIRX3TX0 = valhigh;
}//end of send16-bitdac
do{ //Wait SPI TX empty flag to be activated
USERFLAGS = P2;
USERFLAGS &= 0x08;
}while( USERFLAGS == 0);