FTDI Community

General Category => Discussion - Software => Topic started by: diabloi on December 27, 2020, 09:39:58 PM

Title: MatLab and libMPSSE SPI with FT232RL
Post by: diabloi on December 27, 2020, 09:39:58 PM
Hello Community,

I have a few questions for you. I downloaded the MPSSE SPI library and install it without problems.  I have a project to complete with MatLab, I have a device from which I have to read the data (16bits) contained in it via the SPI interface. To do this I use an FT232RL as an interface between PC and device. Reading the D2XX Programmer's Guide, there are many examples, but not in MatLab.
How can I set CPOL=1 and CPHA=1? I don't understand this line of code.
Code: [Select]
ChConfig.configOptions = uint32(0); % Bit 1 is CPOL, bit 0 is CPHA.  Higher order bits configure the chip select.
This is how to sent the bits to device through FT232RL, but if I want to read the data? How can i write the code?
Code: [Select]
% Write to the SPI.
writebuffer = [15 14 13 ......... 2 1 0]; %for us it is 16 bit= 4bits address|1 Write bit| 9bits data|1 parity bit
transfer_options = 0; % No chip select used.
calllib(Libname,'SPI_Write',pChannelHandle,writebuffer,length(writebuffer),pNumBytesTransferred,transfer_options);