ADC read from INA139 current sensor on STM32F03 - too high readings
Hi guys,
I have an issue reading a current sensor based on INA139 ic on an STM32F03 mcu - the readings I'm getting are too high. I cannot understand what is wrong with my setup. I really hope someone can help.
The current meter based on INA139 ic is outputing about 23.5mV per 1 amp.

The above is my first setup and with less that 1A to the load the STM32F03 is reading about 47Amps. When I test the current meter output alone with a multimeter I can see few millivolts indeed. When I test the PIN9 output with a multimeter (nothing connected to it) my multimeter shows about 3.6v. When current sensor is connected to the MCU multimeter shows 1.1V (which were indeed about 47 Amps if INA139 would have been outputing 1.1v, but it is not). And the question is why is this happening?
With my second setup I use a LM358A opamp in between them like in the picture (same design as here http://forembed.com/creating-the-current-sensor-board.html and as the datasheet suggest to use a buffer to improve the accuracy of the readings):

This time (load less that 1A) but MCU readings are about 25Amps, and multimeter readings on pin 9 is 0.6V. But when testing INA139 + LM358 setup alone the output of the opamp is correct (about 23 mV for 1 Amp load).
Note that if I attach to pin 9 a resistor divider 10k 1k and input 12v then the readings on that pin is very close to correct readings.
The code that I'm using is about right:
(some pieces of code)
IO_CONFIG(GPIO_Mode_AN, 0, GPIO_OType_OD, GPIO_PuPd_NOPULL)
sampleTime = ADC_SampleTime_601Cycles5
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256); // 72 MHz divided by 256 = 281.25 kHz
there is even calibration procedure
Entire code is here https://github.com/betaflight/betaflight/blob/4.0.4/src/main/drivers/adc_stm32f30x.c starting with line 112.
So my question is why STM32F03 can't read rather low values from INA139, and my multimeter is showing such high voltages on the pin itself when INA139 output seems to be correct?
Thank you in advance.