How to transmit the data between PC and FPGA using serial ports

9 vues (au cours des 30 derniers jours)
Sainath
Sainath le 8 Mar 2011
Réponse apportée : Samar le 17 Fév 2025
UART transmitter core running on FPGA sending the data to PC.
Hai,
Can you explain the procedure of writing & reading the data from MATLAB GUI to FPGA bord using serial ports.
For Example: Plotting the simple sine wave in MATLAB GUI by reading the data from FPGA board and When we change the frequency of the sai wave by inputting the value from MATLAB GUI the sin wave which is present previously on the board should change with given input data.
Can you help me with needed information so that I will get some idea on the things how to read/write the data from MATLAB GUI using serial ports and it will helps me in implementing my things...
Thank you,
Regards, Sai.....

Réponses (1)

Samar
Samar le 17 Fév 2025
Hello @Sainath,
Data can be transmitted between FPGA and MATLAB GUI using MATLAB’s fread and fwrite functions. In order to implement the transmission, the following steps mentioned below:
  • Open a figure window with the required title and position. Define its axes. This code snippet can be referred to do so:
Code
f = figure('Name', 'Sine Wave Control', 'NumberTitle', 'off', 'Position', [300, 300, 600, 400]);
ax = axes('Parent', f, 'Position', [0.1, 0.3, 0.8, 0.6]);
xlabel(ax, 'Time');
ylabel(ax, 'Amplitude');
grid on;
  • Implement the function uicontrol to create the user interface control. Using the “callback” attribute, add the function to change the frequency to the uicontrol object.
  • Setup the serial port using the serialport function. Setup the timer object and start the timer for continuous data reading.
  • Create a function which will read data from the serial object and plot it. I have added an example code below for reference.
  • Do the required cleanups like stopping and deleting the timer object, closing and deleting the serial object and closing the figure window.
Reference code:
function readAndPlotData(serialObj, axesHandle)
if serialObj.BytesAvailable > 0
data = fread(serialObj, serialObj.BytesAvailable, 'uint16');
plot(axesHandle, data);
drawnow;
end
end
To access the documentation for any of the functions used, you can type “doc <functionName>” in the command window.
Regards,
Samar

Community Treasure Hunt

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

Start Hunting!

Translated by