This is the schematic configuration of our ADC. The signals EXT_ADC_MOSI, EXT_ADC_MISO, EXT_ADC_SCK and EXT_ADC_NSS are connected to an STM32F446ZE microcontroller.
When we try to set CH0 as reading channel, we have no trouble in reading.
But if we choose another channel as reading one, the ADC seems to switch channel but we read wrong values.
For example, if we put 5V DC signal on CH1, and we try to read, we get 79 as converted value.
These are SPI configuration parameters:
In order to switch to CH1 for instance, we send 2 8-bit unsigned integers, in the second one we put the value: 0b00001000 (CH1).
Then we switch NSS to LOW state and we call this function:
HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, 1000);
where tx and rx are unsigned int 2-elements array.
And finally, we set NSS to HIGH state.
In order to get the converted sample we use this transfer function:
value = rxtmp[0] | ((uint16_t) rxtmp[1] << 8);
voltage = (float) value*5/4096;
Best regards,
Giuseppe Pota