Other Parts Discussed in Thread: C2000WARE
Tool/software: Code Composer Studio
Hi all,
I am fairly new to embedded development and am working on acquiring the data from an 18-bit ADC over SPI. I understand that the C2000's architecture is designed to handle 16-bit data. In fact, I was able to acquire the 16-bit SPI data using a 16-bit ADC I had haandy. But for this application I'm working on, I definitely need 18 bit ADC's and need to read this 18-bit adc data over SPI. How can I go about doing it?
The following is the initialization code I have set up for simple 16-bit transfers. How do I now tell the processor to handle 18-bit transfers?
#include "Lab.h" // Main include file
#include "F2837xD_device.h"
//#define SPI_INT_ENABLE 1 //Comment to disable SPI interrupts
//Data rate selection
#define DataRate_1_7_MBPS 1 //14.28 MHz Serial Clock
//#define DataRate_2_0_MBPS 1 //16.66 MHz Serial Clock
//#define DataRate_2_5_MBPS 1 //20 MHz Serial Clock
void InitSPI(void)
{
SpiaRegs.SPICCR.bit.SPISWRESET = 0; //Reset the SPI peripheral
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; //Configure C2000 as an SPI master
//SpiaRegs.SPICCR.bit.SPILBK = 1; //Disable Loopback
//SpiaRegs.SPICTL.bit.TALK = 1;
//Referring to LT2338 Clock Polarity is 0: ie, clock signal is zero when no transfers are taking place
//The clock phase refers to which clock edge the data is captured on and which clock edge does the data change.
//Refer to your microcontroller’s data sheet for the bit value for the clock phase.
//According to this and referring to the data transfer waveform diagram provided in the datasheet
//of LT2338 ADC IC it is found that the data has to be stable at the falling edge and can change at the
// rising edge.
//Referring to Table 18-3 on Pg 2060 of the technical refernce manual of F28379D, the appropriate settings is
//Rising edge without delay
//i.e. CLKPOLARITY 0 and CLK_PHASE 0
SpiaRegs.SPICCR.bit.CLKPOLARITY = 0; //Based on the previous explanation
SpiaRegs.SPICTL.bit.CLK_PHASE = 0; //Based on the previous explanation
//Baud rate settings
//Core clock at 200MHz
//LSPCLK @100MHz
EALLOW;
ClkCfgRegs.LOSPCP.bit.LSPCLKDIV = 1; //LSPCLK = / 2 (default on reset)
EDIS;
#if DataRate_2_5_MBPS
SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 0x04; //SPI Baud Rate = LSPCLK/7 (20 MHz)
#endif
#if DataRate_2_0_MBPS
SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 0x05; //SPI Baud Rate = LSPCLK/7 (16.66 MHz)
#endif
#if DataRate_1_7_MBPS
SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 0x06; //SPI Baud Rate = LSPCLK/7 (14.28 MHz)
#endif
SpiaRegs.SPICCR.bit.SPICHAR = 0xF; //16-bit word
//Clear the flags
SpiaRegs.SPISTS.bit.OVERRUN_FLAG = 1; //clear the SPI Receiver Overrun Flag
#if SPI_INT_ENABLE
//Interrupt Settings
SpiaRegs.SPICTL.bit.OVERRUNINTENA = 0x1; //Enable Receiver Overrun
SpiaRegs.SPICTL.bit.SPIINTENA = 0x1; //Enable SPI Interrupt
#endif
//Reset Release
SpiaRegs.SPICCR.bit.SPISWRESET = 1; //Release the SPI peripheral from RESET State
}
__interrupt void epwm1_isr(void)
{
static volatile Uint16 GPIO34_count = 0; // Counter for pin toggle
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; // Must acknowledge the PIE group
EPwm1Regs.ETCLR.bit.INT = 1; //clear the EPWM interrupt flag
#if LTC1864
//Start a SPI data transmit
//Pull the pin high; starts the conversion on the chip
GpioDataRegs.GPASET.bit.GPIO19 = 1; //GPIO Set
DelayUs(3); //wait for 2.75 us for conversion to take place
GpioDataRegs.GPACLEAR.bit.GPIO19 = 1; //GPIO Clear
//SPI communication begins
SpiaRegs.SPITXBUF=0xAAAA; // Send data. This is a dummy byte
//The above step automatically starts an SPI data transmit and a subsequent receive
// WAIT FOR THE BYTE TO BE SENT AND THE OTHER BYTE TO BE RECEIVED AND PLACED IN THE RXBUF REGISTER
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0);
if(SpiaRegs.SPISTS.bit.INT_FLAG == 1);
{
if(GPIO34_count++ > 25000) // Toggle slowly to see the LED blink
{
GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // Toggle the pin
GPIO34_count = 0; // Reset the counter
}
rxdata1 = SpiaRegs.SPIRXBUF;//extarct the data (automatically clears the interrupt flag)
}
#endif
}
Any help would be greatly appreciated!
Thank you.
