Okay changed the code and getting closer. The data is read as 4 bytes and with the union put into an unsigned int. I then need to manipulate the data to get an int that is constructed from bits 28-4 of those 32 bits. Something in my code doesnt seem to be working because the results vary greatly from one reading to the next.
#include "mbed.h"
DigitalOut CS(p8);
SPI device(NC, p6, p7); // mosi, miso, sclk
union {
unsigned int i_data;
char data[3];
} u_data;
unsigned int ADC;
int main() {
device.format(8,0);
device.frequency(500000);
// CS=1;
// wait(.2);
printf("\n\rADC SPI Reading\n\r");
CS=0;
wait(.2);
for (int i=0;i<4;i++) {
u_data.data[i] = device.write(0xFF);
}
CS=1;
ADC = u_data.i_data<<4;
ADC = ADC>>8;
printf("result= %u\n\r",ADC);
}
sample output:
ADC SPI Reading
result= 16416946
ADC SPI Reading
result= 14319794
ADC SPI Reading
result= 2785458
ADC SPI Reading
result= 11165874
ADC SPI Reading
result= 12214450
ADC SPI Reading
result= 15356082
ADC SPI Reading
result= 1720498
ADC SPI Reading
result= 2764978
Hello
I am trying to setup and read 32bit data from an LTC2400 device. The manual for the device can be found here -> http://cds.linear.com/docs/Datasheet/2400fa.pdf It's a 3 wire SPI.
Anyway from the datasheet I gathered the mode was CPOL=0, CPHA=0 and setup the SPI accordingly. I figured since the device has no MISO I could just use the SPI instead of SPIHalfDuplex and not connect the MISO. When CS goes low the device clocks out 32bits of data automatically without sending anything to the device. So I have the following code which doesnt seem to be working. I'm sure I am doing something dumb and one of you nice individuals can help.
Just as a sanity check I used the commented out code to Bit-Bang the SPI port with 32 clock transitions reading the MISO pin of the device. This works as expected and gives proper data bits.
Thanks