How to read data from FTDI FT2232H using FT245 FIFO Mode
Show older comments
Hello dear colleagues,
I am using FTDI's FT2232H chip with MATLAB to write commands from PC to FT2232H chip and then reading the response from a hardware (an ASIC in my case) which is througed to the port via MATLAB accordingly. Here's what I am actually doing.
%% load d2xx library and open channel #0
[~,~] = loadlibrary('ftd2xx.dll', 'ftd2xx.h', 'alias', 'd2xx');
libfunctionsview d2xx;
FT_OK=0;
deviceId = uint32(0);
ftHandle = libpointer('voidPtrPtr', 0);
oc_status = calllib('d2xx', 'FT_Open', deviceId, ftHandle);
if oc_status==FT_OK
disp('Device connected & opened successfully!');
elseif oc_status==1
disp('Device invalid handle!');
elseif oc_status==2
disp('Device not found!');
elseif oc_status==3
disp('Device not opened!');
end
Mode = uint8(0); %% Reset mode
Mask = uint8(255);
bitmode_status = calllib('d2xx','FT_SetBitMode',ftHandle,Mask,Mode);
pause(0.00010); %% 10ms delay
Mode = uint8(64); %% Sync FIFO Mode
LatencyTimer = uint8(16); %% Setting Latency Timer
InTransferSize = uint32(2710);
OutTransferSize = uint32(2710);
FT_FLOW_RTS_CTS = uint8(256);
bitmode_status = calllib('d2xx','FT_SetBitMode',ftHandle,Mask,Mode);
if oc_status == FT_OK
status = calllib('d2xx','FT_SetLatencyTimer',ftHandle, LatencyTimer);
status = calllib('d2xx','FT_SetUSBParameters',ftHandle,InTransferSize,OutTransferSize);
status = calllib('d2xx','FT_SetFlowControl',ftHandle,FT_FLOW_RTS_CTS,11,13);
end
dataTx = [55,0,0,0,0,0]; %% Test Command here
WriteBufferPtr = libpointer('voidPtr', uint8(dataTx));
bytesToWrite = uint16(numel(dataTx));
sizeTransferredPtr = libpointer('voidPtr', 0);
isEndTransaction = true;
[write_status write_buffer bytes_write num_bytes] = calllib('d2xx','FT_Write',ftHandle,WriteBufferPtr,bytesToWrite,sizeTransferredPtr);
if write_status==FT_OK
disp('Data written successfully!');
elseif write_status==1
disp('Data not written. Please reconnect FITPix!');
end
I am using D2XX library here. The problem is, whenever I try to retrieve information from write_buffer to access the data write buffer but I am getting something like libpointer as a value. How can I use the value in this variable, simply.
Moreover, how can I read the data from FT2232H chip using D2XX FT_Read command in FT245 FIFO mode? I means I simply wanna access the data in read buffer. I tried but it still gave me libpointer and not the value. Any idea and help 'ld be highly appreciated please. Thanks in advance.
Answers (0)
Categories
Find more on Time Series Events 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!