主题中讨论的其他器件:ADS131M08、
工具与软件:
您好!
我有 MSP-EXP432E401Y Launchpad 和 ADS131M08评估模块。 我能够在 ADS 模块(SPI 接口)中写入并重新读取已写入的寄存器。 有一个 TI 提供的示例代码。
20多年来、我与任何节目都不接触。 因此、我希望得到一些帮助。 我参考该示例函数来读取数据(下面的代码)。
我应该在第40行中为函数提供什么作为函数参数? 它是一个指针、但参数必须是什么? 如何在第40行调用该函数? 我看到它存储了来自所有通道的状态和数据值、但我需要向该函数提供什么参数? 是通道编号、还是数组的地址或其他东西?
bool bit_status = ReadData (??);//通道编号?
//****************************************************************************
//
// 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);
}
谢谢
RAM。