Other Parts Discussed in Thread: DAC8568
Hi,
I have some problems on interfacing my Piccolo MCU controlSTICK with the DAC8568 via SPI.
The programm is based on the flashinglight example given in the ControlSuit and parts of code I found here. With the scope I can't see any clock like signal on the SPICLK and also no data signal on SPISIMOA. Both show nice high signal. So I think that the initialisation of the SPI interface is already wrong. I am using the Piccolo MCU controlStick (F28027 @ 10MHz) and CCS4.
Thank a lot for helping me!
here the source code:
#include "PeripheralHeaderIncludes.h"
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// FUNCTION PROTOTYPES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void DeviceInit(void);
void InitFlash(void);
void MemCopy(Uint16 *SourceAddr, Uint16* SourceEndAddr, Uint16* DestAddr);
// SPI Function Prototypes
void InitSPI(void); // This function initializes the SPI
void InitSpiaGpio(void); // This function initializes the SPI Gpio
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Used for running BackGround in flash and the ISR in RAM
extern Uint16 RamfuncsLoadStart, RamfuncsLoadEnd, RamfuncsRunStart;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// MAIN CODE - starts here
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void main(void)
{
int b=0;
//=================================
// INITIALISATION - General
//=================================
DeviceInit(); // Device Life support & GPIO mux settings
// Only used if running from FLASH
// Note that the variable FLASH is defined by the compiler (-d FLASH)
#ifdef FLASH
// Copy time critical code and Flash setup code to RAM
// The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
// symbols are created by the linker. Refer to the linker files.
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
InitFlash(); // Call the flash wrapper init function
#endif //(FLASH)
// Initialise Period of Cpu Timers
// Timer period definitions found in PeripheralHeaderIncludes.h
// CpuTimer0Regs.PRD.all = mSec500; // 500ms * 2(# of LED states) = 1s blink rate
CpuTimer1Regs.PRD.all = mSec1000;
// CpuTimer2Regs.PRD.all = mSec5000;
//=================================
// INTERRUPT INITIALISATION (not needed in this example)
// (best to run this section after other initialisation)
//=================================
// Enable Peripheral, global Ints and higher priority real-time debug events:
// IER |= M_INT3;
// EINT; // Enable Global interrupt INTM
// ERTM; // Enable Global realtime interrupt DBGM
// SPI Initialisation
InitSpiaGpio();
InitSPI();
//Software Reset
SpiaRegs.SPITXBUF = 0x1C00;
SpiaRegs.SPITXBUF = 0x0000;
//Turn Internal Reference always on
SpiaRegs.SPITXBUF = 0x090A;
SpiaRegs.SPITXBUF = 0x0000;
//=================================
// Forever LOOP
//=================================
for(;;) //infinite loop
{
if(CpuTimer1Regs.TCR.bit.TIF == 1)
{
CpuTimer1Regs.TCR.bit.TIF = 1; // clear flag
//-----------------------------------------------------------
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; //Toggle GPIO34 (LD2)
//-----------------------------------------------------------
//Ein
if(b==0)
{
SpiaRegs.SPITXBUF = 0x02FF; // command
SpiaRegs.SPITXBUF = 0xFFF0; // data
b=1;
}
//Aus
else if(b==1)
{
SpiaRegs.SPITXBUF = 0x02F0; // command
SpiaRegs.SPITXBUF = 0x0000; // data
}
}
}
} //END MAIN CODE
void InitSPI(void)
{
SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x000E; // Enable master mode, shift phase,
// enable talk, and SPI int disabled.
SysCtrlRegs.LOSPCP.bit.LSPCLK = 5; // SYSCLKOUT / 10 = 1 MHz
SpiaRegs.SPIBRR = 99; // SPICLK = LSPCLK / (1 + 99) = 10 kHz
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
SpiaRegs.SPICCR.bit.SPISWRESET = 1; // Release the SPI from reset
}
void InitSpiaGpio(void)
{
EALLOW;
/* Configure SPI-A pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be SPI functional pins.
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA
EDIS;
}