analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 75 forks source link

can't read AIN0, AIN1, ... analog inputs using HAL #363

Closed buha closed 1 year ago

buha commented 1 year ago

Hi,

I'm trying to get some readings in with MAX32650 of AIN0, AIN1, etc. external channels.

No matter what I provide on AIN0, AIN1, pins of the FTHR board, I always get the raw value 1 as reading.

However, if I perform ADC conversions of internal channels I get meaningful values.

The seqence of calls is:

MXC_ADC_Init();
MXC_ADC_StartConversion(ch); // ch is MXC_ADC_CH_0, MXC_ADC_CH_1 etc.
MXC_ADC_GetData(&reading)

Here's the readings that I get converted to Volts using reading * 1.22V / 1024

ain0 = 0.001191 Volts
ain0/5 = 0.001191 Volts
ain1 = 0.001191 Volts
ain1/5 = 0.001191 Volts
vcore = 1.122305 Volts
vdda = 1.218809 Volts
vddb/4 = 0.795859 Volts
vddio/4 = 0.459883 Volts
vddioh/4 = 0.847090 Volts

First values are ALWAYS 1 * 1.22 / 1024 = 0x001191. The rest of the values seem correct.

buha commented 1 year ago

nevermind, the FTHR board routes AIN0, AIN1 etc. pins to an external I2C ADC, not to the embedded ADC of the microcontroller...

buha commented 1 year ago

Using the EVKIT-MAX32650 I was able to correctly read AIN0, AIN1... because those inputs are directly fed into the microcontroller analog inputs.

However I've just tried the same thing with the MAX78000 FTHR board where AIN3 and AIN4 are both connected to the microcontroller directly.

For the internal channels I get good readings, however for AIN3 and AIN4 (AIN0 through AIN7 really) I get a static, 0x2 raw value with the same code.

buha commented 1 year ago

@kevin-gillespie any idea ?

buha commented 1 year ago

Found the reason...

Board_Init() was doing nothing in my firmware and so by comparison with your example, it wasn't initializing the MXC_SYS_PERIPH_CLOCK_GPIO2 (GPIO2.3 and GPIO2.4).

https://github.com/Analog-Devices-MSDK/msdk/blob/main/Libraries/Boards/MAX78000/FTHR_RevA/Source/board.c#L85

Jake-Carter commented 1 year ago

Thanks @buha, can we close this?