create unsigned char array to get the spi data from ADC , which is connected through usb to SPI converter to matlab

1 view (last 30 days)
i am using a 24 bit ADC with SPI output, i need to interface it to MATLAB so im using MCP2210( usb to SPI converter working)
my board working and i am able to configure it.
Problem.... To receive SPI data from pc(matlab)<-converter<-ADC, i need to use TxferSpiData function in .dll of mcp2210.
below i have shown Coding in C++ to tx and Rx two 8-bit data.
how can i create this array in matlab to receive 27 bytes of data in 27 array(8 channel ADC of 24 bit resolution) , i have used cell to receive it not working.
i have added my code.m and Guide to use MCP2210 TxferSpiData function( page no 16) *
out = gcnew array<unsigned char>(2) {0x00,0x00};
in = gcnew array<unsigned char>(2) {0x00, 0x00};
intret = UsbSpi->Functions->TxferSpiData(out, in);
how to create a unsigned char array (similar to c++ code above in matlab) to receive this data into matlab with TxferSpiData function in dll. Guide page no:16
Thanks & Regards
Ikram khan.S.I

Answers (1)

Walter Roberson
Walter Roberson on 29 Mar 2013
Receive unsigned char as uint8(), and then if necessary char() it to convert to characters.
  2 Comments
ikram khan
ikram khan on 30 Mar 2013
Edited: ikram khan on 30 Mar 2013
thanks for the replay... i need to get array of 27 bytes using TxferSpiData function used in .Dll of usb to SPI converter.
each time i call this function i will receive 27 bytes of data,so i need a array of unsigned char as per c++ code in last message.
Info given in converter datasheet
Name: TxferSpiData
Purpose: Transfer the specified SPI data Parameters:
Inputs: dataTx (array<Byte>^) - Array of SPI data to send to device. This array should be at least the same size as numBytes or larger.
*Outputs*: dataRx (array<Byte>^) Array that contains SPI data received. This array should be at least the same size as numBytes or larger.
Returns:
int - Return value:
negative = error
0 = success
in last msg i have shown code in c++ to use TxferSpiData function. how to do the same in matlab.
sorry for my poor English.
Thanks & Regards
Ikram khan.S.I
Walter Roberson
Walter Roberson on 30 Mar 2013
buffer = uint8(28,1);
success = TxferSpiData(buffer);
if success == 0
spi_chars = char(buffer(1:27));
else
fprintf('TxferSpiData returned error: %d\n', success);
end

Sign in to comment.

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!