Part Number: MSP-EXP432E401Y
Other Parts Discussed in Thread: ADS131M08,
Tool/software:
Hi,
I have a MSP-EXP432E401Y Launchpad and an ADS131M08 Evaluation module. I am able to Write and re-read a written register in the ADS module (SPI Interface). There is a sample code provided by TI.
I have been out of touch with any programming for over 2 decades. Thus, I would like some help. I refer to this example function to read data (code below).
What should I be providing as a function argument for the function in Line 40? It is a pointer, but what must be the argument? How do I call this function on line 40? I am seeing that it stores the status and the data values from all the channels, but what is the argument I need to provide to the function? Is it the channel number, or an address of a array or something?
bool bit_status = readData(??); // channel number?
//****************************************************************************
//
// Channel data structure
//
//****************************************************************************
typedef struct
{
uint16_t response;
uint16_t crc;
int32_t channel0;
#if (CHANNEL_COUNT > 1)
int32_t channel1;
#endif
#if (CHANNEL_COUNT > 2)
int32_t channel2;
#endif
#if (CHANNEL_COUNT > 3)
int32_t channel3;
#endif
#if (CHANNEL_COUNT > 4)
int32_t channel4;
#endif
#if (CHANNEL_COUNT > 5)
int32_t channel5;
#endif
#if (CHANNEL_COUNT > 6)
int32_t channel6;
#endif
#if (CHANNEL_COUNT > 7)
int32_t channel7;
#endif
} adc_channel_data;
bool readData(adc_channel_data *DataStruct)
{
int i;
uint8_t crcTx[4] = { 0 };
uint8_t dataRx[4] = { 0 };
uint8_t bytesPerWord = getWordByteLength();
#ifdef ENABLE_CRC_IN
// Build CRC word (only if "RX_CRC_EN" register bit is enabled)
uint16_t crcWordIn = calculateCRC(&DataTx[0], bytesPerWord * 2, 0xFFFF);
crcTx[0] = upperByte(crcWordIn);
crcTx[1] = lowerByte(crcWordIn);
#endif
/* Set the nCS pin LOW */
setCS(LOW);
// Send NULL word, receive response word
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->response = combineBytes(dataRx[0], dataRx[1]);
// (OPTIONAL) Do something with the response (STATUS) word.
// ...Here we only use the response for calculating the CRC-OUT
//uint16_t crcWord = calculateCRC(&dataRx[0], bytesPerWord, 0xFFFF);
// (OPTIONAL) Ignore CRC error checking
uint16_t crcWord = 0;
// Send 2nd word, receive channel 1 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(crcTx[i]);
}
DataStruct->channel0 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#if (CHANNEL_COUNT > 1)
// Send 3rd word, receive channel 2 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel1 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 2)
// Send 4th word, receive channel 3 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel2 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 3)
// Send 5th word, receive channel 4 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel3 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 4)
// Send 6th word, receive channel 5 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel4 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 5)
// Send 7th word, receive channel 6 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel5 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 6)
// Send 8th word, receive channel 7 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel6 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
#if (CHANNEL_COUNT > 7)
// Send 9th word, receive channel 8 data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->channel7 = signExtend(&dataRx[0]);
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
#endif
// Send the next word, receive CRC data
for (i = 0; i < bytesPerWord; i++)
{
dataRx[i] = spiSendReceiveByte(0x00);
}
DataStruct->crc = combineBytes(dataRx[0], dataRx[1]);
/* NOTE: If we continue calculating the CRC with a matching CRC, the result should be zero.
* Any non-zero result will indicate a mismatch.
*/
//crcWord = calculateCRC(&dataRx[0], bytesPerWord, crcWord);
/* Set the nCS pin HIGH */
setCS(HIGH);
// Returns true when a CRC error occurs
return ((bool) crcWord);
}
Thanks
Ram.