My S32K148 SPI2 peripheral was previously working but something seems to be misconfigured now.
I am communicating with an ADS8028 ADC chip.
When I try to send a write command, the MOSI line goes high and stays high, instead of sending data.
int16_t get_MCC_ADC_tempC_x10(){
uint16_t adc_tx_buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint16_t adc_rx_buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint32_t baudCalc;
lpspi_state_t masterState;
LPSPI_DRV_MasterInit(SPI2, &masterState, &SPI2_MasterConfigADCs);
LPSPI_DRV_MasterConfigureBus(SPI2, &SPI2_MasterConfigADCs, &baudCalc);
LPSPI_DRV_SetPcs(SPI2,LPSPI_PCS1,LPSPI_ACTIVE_LOW);
adc3_temp_conv_complete = false;
adc_tx_buf[0] = (adcconf | TSENSE_ON ); // ADC3 temp sense, no averaging
adc_tx_buf[1] = (adcconf | AIN0);
LPSPI_DRV_MasterTransferBlocking(SPI2, (uint8_t *)&adc_tx_buf, (uint8_t *)&adc_rx_buf, 2*BUFFER_SIZE*2U, ADC_TIMEOUT);
// while(!adc3_temp_conv_complete){} //Flag set by ISR externally
// Port A interrupt will set this true when conversion is completed.
// Now read back temp data word:
adc_tx_buf[0] = 0;
LPSPI_DRV_MasterTransferBlocking(SPI2, (uint8_t *)&adc_tx_buf, (uint8_t *)&adc_rx_buf, 2*BUFFER_SIZE*1U, ADC_TIMEOUT);
adc3_temp_conv_complete = false;
...
}
You might think that the buffer is mistakenly filled with 0xFFFF, however I can confirm the value of (adcconf | T_SENSE) is 0x8020, and the value of (adcconf | AIN0) is 0xA000.
Solved! Go to Solution.
This looks more like the MOSI or MISO ports are not configured correctly, or check if the hardware of these two ports is affected.
This looks more like the MOSI or MISO ports are not configured correctly, or check if the hardware of these two ports is affected.
I was making a measurement error, and also confusing input and output.
I wish the manual used MOSI/MISO instead of SOUT/SIN, somehow that always trips me up.
Anyway, thanks for the support!!!
In terms of configuration, not sure what to check. SPI2 is set to the correct pins, and I also believe the PEX settings are fine.
I can't see any problem with the configuration. You can only test the SPI port on the MCU side, disconnect the MCU and Slave side, and test the output waveform.