Hi;
I am new with PICOLLO and Embedded coding. I am using TMS320F28027PT, using CH4(AIO4) to read an analog input and I need to use a 12 bit DAC
MCP4921 that should output the analog signal read by ADC.
I am using SPI 3 wire connection. Active low CS of the DAC is connected to the GPIO0/EPWM1A, GPIO16 is connected to DAC's SDI(Serial Data in)-input, and
DAC's SCk is connected to GPIO18 as an SPICLK.
Since the ADC gives right justified result 12 bit, so I left shifted 4 times the ADC result, to do left justified before transmitting. and the reced. data
is andded with 0fffh , now after this MY DAC's OUTPUT is Completely zero (and all Gpio's are never active in simulation )obviously I am doing smth wrong with
SPI or With GPIO Which I cannot fix. IF you Can Please help.I am Using Proteus to simulate all this. the code compiles with no error.
Here I paste my Code and Schematic
Thanks,
Ahmad
*****************************************************************************************
#include "F2802x_Device.h" // Headerfile Include File
#include "f2802x_examples.h"
#define ADC_usDELAY 1000L
void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*Device_cal)();
EDIS;
EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference
AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC
AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select internal BG
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
GpioCtrlRegs.AIOMUX1.bit.AIO4 = 2; // Configure AIO4 for A4 (analog input) operation
AdcRegs.ADCSOC0CTL.bit.CHSEL = 4; // Convert channel ADCINA4 (ch4); set SOC0 channel select to ADCINA4
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; // Acquisition window set to (6+1)=7 cycles
AdcRegs.INTSEL1N2.bit.INT1E = 1; // Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINTs trigger at end of conversion
AdcRegs.INTSEL1N2.bit.INT1SEL = 6; // //EOC6 triggers ADCINT1
AdcRegs.ADCINTSOCSEL1.bit.SOC0 = 1; //ADCINT1 starts SOC0
EDIS ;
DELAY_US(ADC_usDELAY); // Delay before converting ADC channels
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.all =0x009F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a) //before it was Uint16 a
{
SpiaRegs.SPITXBUF=a;
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x2044;
SpiaRegs.SPIFFCT.all=0x0;
}
void InitGpio(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1; // Disable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; // Disable pull-up on GPIO16 (EPWM1A)
//GpioCtrlRegs.GPAPUD.bit.GPIO17 = 1; // Disable pull-up on GPIO0 (EPWM1A)
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 1; // Disable pull-up on GPIO0 (EPWM1A)
//GpioDataRegs.GPASET.bit.GPIO0 = 1; // condition for GPIO0 to be an output
//GpioDataRegs.GPACLEAR.bit.GPIO0 = 1;
//GpioDataRegs.GPASET.bit.GPIO16 = 1;
//GpioDataRegs.GPACLEAR.bit.GPIO16 = 1;
//GpioDataRegs.GPASET.bit.GPIO18 = 1;
//GpioDataRegs.GPACLEAR.bit.GPIO18 = 1;
GpioCtrlRegs.GPADIR.bit. GPIO0 = 1;// GPIO0 is output
GpioCtrlRegs.GPADIR.bit.GPIO16 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO18 = 1;
EDIS;
}
char DAC(unsigned int value )
{
EALLOW;
char rdata, mask;
InitGpio();
GpioDataRegs.GPADAT.bit.GPIO0 = 0; //ChipSelect = 0; for Enable DAC
spi_init();
spi_fifo_init();
spi_xmit(value);// write to DAC
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
rdata = SpiaRegs.SPIRXBUF;
mask = rdata & 0x0FFF;
GpioDataRegs.GPADAT.bit.GPIO0 =1; //ChipSelect = 1; //Disable DAC
return(mask);
}
void main() {
#ifdef _FLASH
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif
InitSysCtrl();
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; //enable XCLOCKOUT through GPIO mux
SysCtrlRegs.XCLK.bit.XCLKOUTDIV = 2; //XCLOCKOUT = SYSCLK
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
int16 temp, shift;
for(;;)
{
InitAdc();
//Wait for end of conversion.
while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){} //Wait for ADCINT1
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1
temp = AdcResult.ADCRESULT0;
shift = temp << 4;
DAC(shift);
}
return ;
}
*****************************************************************************************************************