|
Hi,
I have a problem with serial communication via RS232 port.
I am working with Xilinx's software (SDK) and Matlab.
I am programming a Microblaze in language C and I need to send and receive data through serial port.
I need to send Matlab and to receive to FPGA in 4.350 times. I created a loop to send and receive data, but it's only working 50 times.
Can you help me?
Can you look at my code?
====================================
In Matlab, I have (9600 bps):
====================================
s1 = serial('COM1');
set (s1, 'timeout', 60);
set (s1,''terminator',0);
set(s1,'inputbuffersize',1024);
fopen(s1);
% I have a ciclo the calculate the inputs data of the microprocessor
for i=3:N1-2 % it's 4.350
finputs = []; % for the first time the inputs are [0,0,0,0]
finputs = [y(i-1);y(i-2);u(i-1);u(i-2)];
ynew = nnoutput(NetDeff,W1f,W2f,finputs);% ynew = 1.9965e-004 here is a floating point
ynew2 = num2str (ynew); % here I convert floating point to string, because in the microprocessor only receive string
y(i)= ynew;
fprintf(s1,ynew2); %here I send the string to microprocessor
% I must receive the data of the microprocessor. The microprocessor sends to Matlab a string
unew = fscanf(s1,'%f'); %here I convert the string to floating point
u(i)= unew;
end
fclose (s1)
plot (u);
plot(y);
delete(s1)
clear s1
====================================
In SDK, I have:
====================================
//LOOP TO SEND AND TO RECEIVE
for(ind = 0; ind < size_ind; ind++)
{
ReceivedCount = 0;
ReceivedCount = XUartLite_Recv(&UartLite, RecvBuffer, TEST_BUFFER_SIZE); //I'm receiving here
double entr2 = atof(RecvBuffer);
...
result = neur->activ;
char data[15];
sprintf(data,"%f",result);
print(data);
SentCount = XUartLite_Send(&UartLite, SendBuffer,TEST_BUFFER_SIZE); //I'm sending here
}
=====================================
Thanks
|