AnsweredAssumed Answered

SPI RX Buffer Delayed By One Read Cycle ADSP-21489

Question asked by epalaima on Aug 23, 2017
Latest reply on Sep 13, 2017 by epalaima

Hi, I am using the ADSP-21489 Ez-Kit, and have it communicating with an MCP3208 ADC via SPIB for analog inputs. This is working great, except for one weird issue, that being that the reads from the RXSPIB register are being delayed by one read cycle (that is to say, one call of the read function I have made, which does one 32 bit transfer). I have in my main function a for-loop which cycles through reading each of the ADC's 8 inputs, and the value from input 0 goes to the array slot for input 1 if the for-loop counts up, and vice versa if the for loop counts down (e.g. input 7 going to array slot 6 and input 0 going to array slot 7). Since it changes direction with the for-loop I am certain this is not a hardware issue, but rather has to do with how I am reading the SPI receive buffer. I based my functions off of the I2S Talkthrough project, with some modifications. Here is the relevant code, please let me know if you can see anything amiss, or have any suggestion for what might be causing this. 

 

in main:

unsigned int readMCP[8];

setupMCP3208SPI();

while(1){
for(int i = 7; i >= 0; i--){
readMCP[i] = readMCP3208(i);
}
}

 

in MCP3208SPI.c:

 

//SPIB read function

 

unsigned int readMCP3208(unsigned char channel){

unsigned int val;
unsigned int read;

unsigned int spiselect = DS0EN;

SELECT_SPIB_SLAVE(spiselect);

val = (0B11000000 + (channel << 3)) << 24;

*pTXSPIB = val;

while ((*pSPISTATB & TXS)){
NOP();
}

while (!(*pSPISTATB & SPIF)){
NOP();
}
while (!(*pSPISTATB & SPIFE)){
NOP();
}
Delay(10);

read = (*pRXSPIB >> 13) & 4095;// >> 5;

DESELECT_SPIB_SLAVE(spiselect);

Delay(100);

return read;
}

 

//SPIB Setup Functions

 

void setupSPIBDPI(void){

SRU(SPIB_MOSI_O, DPI_PB11_I); //Connect MOSI to DPI PB11 IN
SRU(DPI_PB12_O, SPIB_MISO_I); //Connect MISO to DPI PB12 OUT
SRU(SPIB_CLK_O, DPI_PB13_I); //Connect CLK to DPI PB13 IN
SRU(SPIB_FLG0_O, DPI_PB14_I); //Connect CS0 to DPI PB14 IN

//Connect DPI PBEnable to SPI Peripheral PBEnable Registers
SRU(SPIB_MOSI_PBEN_O, DPI_PBEN11_I);
SRU(SPIB_MISO_PBEN_O, DPI_PBEN12_I);
SRU(SPIB_CLK_PBEN_O, DPI_PBEN13_I);
SRU(SPIB_FLG0_PBEN_O, DPI_PBEN14_I);

}

void setupMCP3208SPI(void)
{
setupSPIBDPI();
// Configure the SPI Control registers
// First clear a few registers
*pSPICTLB = (TXFLSH | RXFLSH);
*pSPIFLGB = 0;

// Setup the baud rate
*pSPIBAUDB = 400;

// Setup the SPI Flag register using the Flag specified in the call
*pSPIFLGB = (CLEAR_DSXEN_BITS|DS0EN);

// Now setup the SPI Control register
*pSPICTLB = (SPIEN | SPIMS | WL32 | MSBF | TIMOD1 | CPHASE | CLKPL | SMLS|GM);

}

Outcomes