I am using a 24-bit external ADC ADS1255 with VF50 having operating System wince6.0 & C# application designed on .Net 3.5. Consider VF50 as master and ADS1256 as slave. Reading data from ADS1256 with a baud rate 26000. Pin connected are SSPCLK, SSPFRM, SSPRXD, SSPTXD of the Iris board. Using the SPIReadWrite function inside a timer_tick function to get the data from SPI channel. ADS1256 is having 8 analog input channel. I want to use all 8 channels for data acquisition and read the DOUT of the adc on Toradex VF50.
Below is the code written to read data, only 1st byte of rxBuffer is showing some value like 244 to 255 & 2nd byte is showing 0.
Please suggest,
How should I read the data to get it properly & separate for no. of channels used on ADC?
UInt16 bytesRead, adcValue;
Byte[] txBuffer = new Byte[2];
Byte[] rxBuffer = new Byte[2];
try
{
unsafe
{
fixed (byte* txBuff = txBuffer)
{
IntPtr microVoltsPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rxBuffer));
Marshal.StructureToPtr(rxBuffer, microVoltsPtr, true);
bytesRead = (UInt16)spi.Spi_ReadWrite(ExtAdc, microVoltsPtr, (IntPtr)txBuff, 2);
Marshal.Copy(microVoltsPtr, rxBuffer, 0, 2);
Int16 data = BitConverter.ToInt16(rxBuffer, 0);
LblLoad.Text = data.ToString();
}
}
}
catch(Exception edd)
{
MessageBox.Show(edd.Message);
}