This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LP-AM243: Variable Length MCPSI?

Part Number: LP-AM243
Other Parts Discussed in Thread: ADS131M06

So the ADS131m06 ADC operates with variable data lengths and I am trying to implement their quasi code into CCS. By default the data length is set to 24bits.

bool adcRegisterWrite(unsigned short addrMask, unsigned short data,
unsigned char adcWordLength){
unsigned char shiftValue; // Stores the amount of bit shift based on
 // ADC word length
if(adcWordLength==16){
shiftValue = 0; // If length is 16, no shift
}else if(adcWordLength==24){
shiftValue = 8; // If length is 24, shift left by 8
}else if(adcWordLength==32){
shiftValue = 16; // If length is 32, shift left by 16
}else{
return false; // If not, invalid length
}
SPI.write((WREG_OPCODE | // Write address and opcode
addrMask) << shiftValue);// Shift to accommodate ADC word length

SPI.write(data << shiftValue);// Write register data
while(SPI.isBusy()); // Wait for data to complete sending
return true;
}

Before this they use "SPI.wordLengthSet(24);" and later they set the word length to 32. Is there a MCSPI library command I can use to change word length like so?

Also how would you recommend implementing variable data frames? In this code it calls SPI.write() multiple times to receive the data, but MCSPI has this buffer system that is probably more convenient. Should I have different TX/RX buffers with different array widths to implement this or can I specify how many elements of the TX/RX array are used? Maybe with the .count variable.

CCS Code:

 /* Initiate transfer */
    spiTransaction.channel  = gConfigMcspi0ChCfg[0].chNum;
    spiTransaction.count    = APP_MCSPI_MSGSIZE / (gConfigMcspi0ChCfg[0].dataSize/8);
    spiTransaction.txBuf    = (void *)gMcspiTxBuffer;
    spiTransaction.rxBuf    = (void *)gMcspiRxBuffer;
    spiTransaction.args     = NULL;
    transferOK = MCSPI_transfer(gMcspiHandle[CONFIG_MCSPI0], &spiTransaction);

  • Hi Dylan,

    The MCSPI frame size was configured in example.syscfg "MCSPI Channel Configuration 0" Data Frame Size (bits):

    gConfigMcspi0ChCfg[0].dataSize will be your data frame size. spiTransaction.count will be how many data frames (each one has the data frame size) you want to read/write for each MCSPI_transfer().

    Best regards,

    Ming