I think this configuration is simple , there are only few things to check.
1-be sure of the voltage polarity.
2- be sure that the analog voltage is fed to the ADC pin,and there is no short circuit .
3- be sure that you code code is correct,pins cofigured correctely, and fuctions are correct ...
there is no way to give you inverted results . be sure that the circuit gives you what you gave to it , it is a slave and you are the master .
if you didn't get what you expect , it is because you made a mistake and you just have doubts about the microctroller operating, don't wory your microcontroller is healthy because it give you a digital reading 1023 it is a good indication that it is works well.
I know you are tired to check the pcb and the code, but this is how it works , evry project has mistakes and even with professional engineers ,but they just spend more time and efforts to debbug .

don't be lazy and verify each point , you will find your mistake.
don't forgive up .and I'm here for sure to help you
