Hey all,
This is probably a ridiculously simple question for 32bit C programmers:
I have an ADC attached to an F28334 via McBSP SPI. The ADC data is read as a 32 bit word or rather 2 16 bit words via McbspbRegs.DRR1 and McbspbRegs.DRR2. The ADC sends its data as a signed 32 bit word. The question is how to take the 2 16 bit registers and turn them into a signed long? My initial approach was:
while( McbspbRegs.SPCR1.bit.RRDY == 0 ) {} // wait for this SPI transaction to clear
adc_dat = McbspbRegs.DRR2.all << 8;
adc_dat <<= 8;
adc_dat += McbspbRegs.DRR1.all;
signed_adc_dat = (signed long)adc_dat;
The shift was done in two parts because a shift count of 16 is too big. This seems klunky to me besides the fact that I'm not sure this even works for negative numbers. Anyone have an elegant solution to this?
Tom C