void AD738x_dataConversion(void) { int16_t adcResults[NUM_CHANNELS]; int32_t transferOK; uint8_t txBuf[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t rxBuf[8] = { 0 }; MIBSPI_Transaction spiTransaction; spiTransaction.count = 8; // 4 channels x 16 bits = 8 bytes spiTransaction.txBuf = (void *)txBuf; spiTransaction.rxBuf = (void *)rxBuf; spiTransaction.peripheralIndex = 0U; spiTransaction.arg = NULL; DebugP_log("Starting AD738x data conversion loop...\n"); for (int i = 0; i < NUM_SAMPLES; i++) { // data conversion, first read commands transferOK = MIBSPI_transfer(gMibspiHandle[MSS_SPIB_J16], &spiTransaction); if ((transferOK != SystemP_SUCCESS) || (spiTransaction.status != MIBSPI_TRANSFER_COMPLETED)) { DebugP_log("AD738x SPI data conversion first read failed!\r\n"); DebugP_assert(FALSE); return; } // Parse channels from received buffer adcResults[0] = ((int16_t)rxBuf[0] << 8) | rxBuf[1]; // Ch1 adcResults[1] = ((int16_t)rxBuf[2] << 8) | rxBuf[3]; // Ch2 adcResults[2] = ((int16_t)rxBuf[4] << 8) | rxBuf[5]; // Ch3 adcResults[3] = ((int16_t)rxBuf[6] << 8) | rxBuf[7]; // Ch4 // Store results in adcBuffer for (int ch = 0; ch < NUM_CHANNELS; ch++) { adcBufferRaw[i][ch] = adcResults[ch]; } } for (int i = 0; i < NUM_SAMPLES; i++) { DebugP_log("%4d\n", adcBufferRaw[i][0]); } DebugP_log("Finished data conversion loop, stored %d samples.\n", NUM_SAMPLES); }