Seriously follow the code and understand the operation of an SPI before you make wild assumptions?
I was hoping he would work thru it and learn but you have clouded the water so I will detail the answer.
So here is his code to read the first MSB A value .. .follow what it does
int PmA_read() // For reading MSB of power value
HiByte = SPI2BUF;
The big hint here is I GUARANTEE you he doesn't read what he thinks he is ... the return is JUNK
What he actually returns is the junk word that came in when he wrote 0x80B1.
Even funnier he has one WORD left completely in the buffer which came in when he wrote 0x0.
When he reads the LSB he will get that junk word and again leave another extra exchange in the fifo.
The code can't work and is continually overflowing the RX FIFO. All he is seeing is the cycle between reading junk values and when it lines up that he reads a value but probably from another phase. It is called failure to understand how an SPI bus works .... AKA you write twice you need to read twice.
Need I add the code is stupidly dangerous you have to make delay_rx stupidly long to guarantee you got the RX before you slam the CS line back high. If he tests the right flag he doesn't even need that delay. Also note the soft_reset likely leaves junk in the FIFO as well.
post edited by LdB_ECM - 2020/08/07 07:47:55