SPI 12bits communication

Hello,

I was wondering if it was possible to send data packets of 12bits over SPI? I am using a G30 TH Module. I know that 8bits and 16bits are possible but was wondering about 12bits.

Thank You

I doubt the processor supports this. You may have to bit bang it if the device only accepts 12 bits.

With 12 bit DAC’s I use, I have found that it simply accepts 16 bits and ignores the top 4.

What device are you looking to communicate with?

2 Likes

I am trying to use LTC2308

Have you tried to use 16 bit and set the upper 6 bits and send that and get back the 12 bits in the upper 16?

I’m using a LTC186x ADC (the 12 bit variant).
It works just fine with 16 bit, ignoring the top 4 bits of the high Byte with the NETMF managed SPI API.
I’m using a G120, and lately I moved my LTC186x SPI code to RLP. SInce the CPU on the G120 supports a 12 bit mode for SPI I now only use 12 bit. But I’m not sure if G30 supports 12 bit and RLP.

You can use the register class to access SPI directly.

@ Gus - To achieve 12 bits?

@ Mr. John Smith - If the CPU Supports it it can theoretically work.

Correct

This is what I have

static SPI.Configuration ADC2_SPI = new SPI.Configuration(GHI.Pins.G30.Gpio.PC0,
               false,      // ChipSelect Active State
               0,          // CLK Setup Time
               0,          // CLK Hold Time
               false,       // Clock Idle State
               true,      // Clock Edge 
               1000,       // Clock Rate kHz
               SPI.SPI_module.SPI2);

static SPI MySPI = new SPI(ADC2_SPI);

 public static void Main()
{
double Temp_Val = 0;
ushort[] rx_data2 = new ushort[1];
ushort[] tx_data2 = new ushort[1];
ushort[] ADC_Config = new ushort[] { 0x8800 };  //Single-Ended, CH0, Unipolar, Sleep Disabled +10 bits of zeros 

MySPI.Config = ADC2_SPI;
MySPI.WriteRead(ADC_Config, rx_data2);
MySPI.WriteRead(tx_data2, rx_data2);
Temp_Val = rx_data2[0];

Thread.Sleep(10); //Breakpoint
}

I then check the contents of Temp_Val but they are random and not accurate. I ignore the bottom 4 bits.

have you read the datasheet? From my 2 second browse it seemed that you have to send a control signal for the device to start doing a conversion, wait the time required for that to complete, then and only then read the SPI data. Perhaps that’s what is causing you an issue.

But also, this seems a simple chip, so bitbanging the required signal isn’t going to be too hard. I’d mock up the same approach in a bitbang approach and test it

@ Brett - Usually NETMF is “slow enough” to simpley write read Control word, and then write read again to get the value.
The LCT1863 I use has a aquisition time and conversion time combined of 5 Micro seconds.
But may be the CS polarity or clock polarity, … are not correct?
Best way to see wht’s Happening is using an oscyloscope. one channel on CS and the 2nd 1st on clock, then mosi, then Miso.
Or if you are lucky and have a 4 channel oscyloscope, all of them at once.
But with CS as reference (or sometimes clock is good as ref too) a 2 channel is file too.

I am attaching a waveform screenshots of what I am doing.
CH1(Yellow) is the clock
CH2(Green) is MOSI
CH3(Blue) is MISO
CH4(Red) is CONV

Based on the datasheet, the input data should be latched on the rising edge of the clock so that seems to be correct. Figure 8 in the datasheet shows the timing with a long CONVST pulse which is what I am doing. The min time for tconv is 1.6us.
The output data is all over the place.
The input voltage to being sampled is 1.9V

MISO is suspicious. It’s not varying, it just changes state at a different point.
What happens when you measure 0v?

It outputs a 0x0000. But when I try to increase the DC value, it is ok for maybe 25mV before it becomes unstable and starts outputing different data.

–> I’d like to hazard a guess as that’s circuit problems. Whack a RC filter on it and see if that brings any stability in signal.