Matlab SPI write with ESS

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
sanjosanjo
Posts: 4
Joined: Wed Jan 11, 2012 2:00 pm

Matlab SPI write with ESS

Post by sanjosanjo »

I'm having trouble using the .NET Matlab interface to write to the SPI interface using the extended mode (ESS). I verified the standard SPI write was working using the example code, then modified it to try ESS (see below). I get the error "No method 'SPI_Transfer_Ess' with matching signature found for class 'Xdimax.Sub20'


------------------------------------------------------------------------------------------------------
disp 'SUB-20 SPI sample. Configures SPI and exchanges data with SPI slave(SS=2)'
TransferSize = 3;
NET.addAssembly('C:\Program Files\SUB-20\bin\sub20dnc.dll');
sub20 = Xdimax.Sub20();
% Open first available SUB-20 device
if ~ sub20.Open(0)
break;
end
% Set SPI configuration
if ~ sub20.SPI_SetConfig(sub20.SpiEnable + sub20.SpiCpolRise + ...
sub20.SpiSmplSetup + sub20.SpiMsbFirst + sub20.SpiClk_4MHz )
break;
end
% Create .NET data array
Data = NET.createArray('System.Byte', TransferSize);
% Fill up the array with data bytes to be sent
Data.Set(0, hex2dec('2a'));
Data.Set(1, hex2dec('2b'));
Data.Set(2, hex2dec('2c'));
% Exchange data with SPI slave(SS=2). SS signal stays high
%if ~ sub20.SPI_Transfer(Data, 2, sub20.SpiSS_H)
% break;
%end
if ~ sub20.SPI_Transfer_Ess(Data, 2, '2L^-vL^-v')
break;
end

% Close SUB-20 device
sub20.Close()

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: Matlab SPI write with ESS

Post by serg »

Hi sanjosanjo,

The SPI_Transfer_Ess method accepts two parameters: data array and a control string. The SS is controlled by specifying 0,1,2,3 in the control string. See the 3.5.3 sub_spi_transfer_ess section of the User Manual for more info. We are going to add the _Ess methods into the .NET document in the next release. Besides the SPI_Transfer_Ess you can also use the following methods:
SPI_Read_Ess(Array Data, String ss_mode)
SPI_Write_Ess(Array Data, String ss_mode)
So, in your code just remove the second parameter(2)

Code: Select all

  
   if ~ sub20.SPI_Transfer_Ess(Data, '2L^-vL^-v')
       break;
    end

sanjosanjo
Posts: 4
Joined: Wed Jan 11, 2012 2:00 pm

Re: Matlab SPI write with ESS

Post by sanjosanjo »

Okay, things are improving. The function executes and I get SPI activity as described by '4vHvHvHv-^v', which is the sequenceI need. However, the SS1 pin has the activity. I've tried
'1vHvHvHv-^v', '2vHvHvHv-^v', '3vHvHvHv-^v', '4vHvHvHv-^v' and '5vHvHvHv-^v' and the activity is always on the SS1 pin, never any other pin.

Any ideas?

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: Matlab SPI write with ESS

Post by serg »

Hi sanjosanjo,
Yes, this is a bug in the firmware which we already fixed but didn't release yet. Please update your firmware with the attached file. This should fix the problem. Sorry for any inconvenience.
Attachments
SUB-20_FW_0.3.7.zip
SUB-20 FW v0.3.7
(69.39 KiB) Downloaded 1606 times

Post Reply