send and receive multiple data using GUI

Create new topics, add your comment, remark, bugs...
odedyech
Posts: 5
Joined: Sun Feb 05, 2012 1:49 pm

send and receive multiple data using GUI

Postby odedyech » Sun Feb 05, 2012 2:31 pm

Hello lubin,

I am tring to send and receive data thru UART from dsPIC30F4011 to the comp.
I am using your block "Tx Output Multiplexed For Matlab-Labview" and I was wondering what are the variables I need to insert in order to send data thru this block to the dspic (instead of sending with the send 1 and send 2 buttons), and to split data comming into diffrent channels in the "Tx Output Multplexed for Matlab-Labview" block to different graphs.

Thanks in advance,

Oded

Saeed
Posts: 12
Joined: Thu Feb 09, 2012 1:18 pm

Re: send and receive multiple data using GUI

Postby Saeed » Wed Feb 29, 2012 11:28 pm

Hello there,
Would you please tell me how to build a simulink model where a user-defiend-type data is read from MATLAB workspace into the dsPIC demo board through UART peripheral and rs232 connection?
And what are the limitations in this regard!?

odedyech
Posts: 5
Joined: Sun Feb 05, 2012 1:49 pm

Re: send and receive multiple data using GUI

Postby odedyech » Thu Mar 01, 2012 8:53 am

Hello Saeed,
There are a few options for sending data from the Matlab/Simulink to the dsPIC:
1. Open a serial port in the Matlab command line using "serial" command, and send data using "fwrite" command.
Pros: you can create a GUI.
Cons: you need a good understanding in Matlab.
2. send data using simulinks Real time Windows target: you have a veriety of block such as: Packet input/ouput, Stream input/ouput, and so on. I recomend Packet input for sending int/uint/double and so on (not strings)
Note - if you want to use these blocks you need to change in the "Simulink Configuration"->"Real Time Workshop"->"system target file"->Change file to rtwin.
Pros: Easy to use, and you can check connectivity (using the test button) of your device.
Cons: If you want to send and recieve a big amount of data, this might be a bit difficult.
3. you can use Lubin's "Tx Output Multiplexed For Matlab-Labview" block to send arrays.
Pros: Easiest to use.
Cons: you can send only one array which is quite limmiting. I cant seem to send "serious" data using GUI.

I hope this answers your question.
Oded

Saeed
Posts: 12
Joined: Thu Feb 09, 2012 1:18 pm

Re: send and receive multiple data using GUI

Postby Saeed » Tue Mar 06, 2012 1:40 am

Hello to you dear odedyech,
I am realy thankful for your kind well organised reply.
Your advices are really fascinating! :D
I tried your first proposed method.
However, it didn't work.
I tried to send a variable with unit value (say, A=1) by "fwrite" function. If this transmission was succesful, the LED of the dsPIC board would be turned ON.
But, It didn't work. :(
Would you plz kindly take a look at the project (an mdl file I uploaded)
By The way, besides using serial port connection through rs232 with dsPIC UART, there is a USB connection possibility through SPI periphral of the PIC.
Do you have any idea about that (Pros/Cons)?
Do you know how to manage data import through USB port of SPI from matlab interface?
Attachments
Matlab2PICDataPr.mdl
(28.81 KiB) Downloaded 194 times

odedyech
Posts: 5
Joined: Sun Feb 05, 2012 1:49 pm

Re: send and receive multiple data using GUI

Postby odedyech » Tue Mar 06, 2012 9:26 am

Hello Saeed,

I see that you used Lubin's rs232 GUI block. If you wish to use this block you need to open it (by the way, you dont have to burn it on the dsPic's block diagram) select the COM Port you have connected your device to (the dsPIC or other device)
select the BaudRate (this is important!! you must define the same BR everywhere! in the block diagram you defined UART 2 to be 19200 thus you must define the BR as well to 19200) and press the "connexion" button. wait untill it is purple (the connexion button) and the you can press the "send" button to send your data.

I have attached an example code of how to open a COM PORT in the matlab command line.

I also attached a Real Time Target model model. if you cant find the Real Time Target blocks write in the command line "rtwin -setup".
after you finished defining the configurations (as described in the PDF file) build the model and press play.
you will then (hopefully :D ) see the dsPIC LED lit (Port A2 in the dsPIC). if you will change the constant (in the real time model) the LED will turn off (all in Real time - you dont need to rebuild)

Good Luck

Oded
Attachments
Real time target.pdf
Real time target setup explanation
(173.09 KiB) Downloaded 315 times
RealTimeTarget.mdl
RTW model
(34.37 KiB) Downloaded 194 times
rs232 example.m
(245 Bytes) Downloaded 221 times

Saeed
Posts: 12
Joined: Thu Feb 09, 2012 1:18 pm

Re: send and receive multiple data using GUI

Postby Saeed » Tue Mar 06, 2012 1:03 pm

Dear Oded,
Thank you for your support. It is appreciating.
How ever, I did as you explained. But there is something wrong when the packet target begins to connect to the board.
Although I succeeded to read data from the board through rs232 in MATLAB in another project suggesting that my cable connection is ok.
I attached snapshots of the error occurred.
It is kind of you if taking a look at them.
My comment is that, probably there is somthing wrong with send capability of USBSerial cable, (it is not realy full duplex... cause I used the fwrite command, the data was sent and ValuesSent:1, but ValuesReceived:0)
Attachments
SerialPort.rar
SerialPort2PIC
(218.09 KiB) Downloaded 275 times

odedyech
Posts: 5
Joined: Sun Feb 05, 2012 1:49 pm

Re: send and receive multiple data using GUI

Postby odedyech » Sat Mar 10, 2012 11:45 am

Hello again,

I can see that the BaudRate in your dsPIC is 19200, and in the Real-Target the BaudRate is 9600. You should change the settings (Serial Port, and BaudRate) until the test passes.
Are you sure that the Serial Port is COM2?
You can check that by going to Manage, and check the PORT connections.

Saeed
Posts: 12
Joined: Thu Feb 09, 2012 1:18 pm

Re: send and receive multiple data using GUI

Postby Saeed » Sat Mar 10, 2012 7:30 pm

Hello odedyech,
Thank you, you are right!
Finally I accomplished to send and receive single data (A=1) through rs232 .
As you suggested I used fwrite/fread MATLAB commands and now I have a good understanding of the procedure.
I uploaded an mdl file, the goal is to send a series of data from MATLAB workspace and then receive the same from PIC in MATLAB.
Would you please take a look and kindly modify the project so that answers my troubles as following.
1- How is it possible to send a series of data from MATLAB (e.g. a column matrix) and then receive the same from PIC in MATLAB and see the result?
2- How is it possible to apply a delay between receive and transmit of data by Rx and Tx (it seems that the delay is necessary)?
3- Is using SPI as a digital input/output recommended in these conditions (if yes would you add a SPI and adjust it)?
My email is saeedrezaee83@yahoo.com; it is honourable sending a message to this email so as to have your Email.
Attachments
SerialConnection.mdl
(31.13 KiB) Downloaded 211 times

odedyech
Posts: 5
Joined: Sun Feb 05, 2012 1:49 pm

Re: send and receive multiple data using GUI

Postby odedyech » Sat Mar 10, 2012 8:36 pm

Hi again Saeed,
I am not sure that this block you used (Data Store Write) is suitable for burning on the dsPIC.. remember that this block is transferred to C code.
Again I am not sure, I started using these blocks just a few months ago as well.

As for your questions:
1. I attached 2 simulink models: a. a model that will be burned on the dsPIC. In this model data is received via UART2 Rx and enter port A0, and sent via UART2 Tx.
b. Real Time Target model: In this block I send a repeating sequence with RS232. The sequence is: 0 1 0 2 0 3 0 4 0 5 0 6. This sort of sequence could turn on/off a LED connected to Port A0 (for example).
In this model I receive the data and display it, and send it to the Workspace.
Note- Dont forget to configure the blocks Packet Input/Output correctly :wink:

2. I am not sure for what a delay is needed for but, you can change the "sample Time" in most blocks. I think that the dimensions are in seconds (e.g. if you will enter '1' every sec there will be an execution of the block, '2' means 2 sec etc.)
also there is a block "Delay" (write Delay in the search line you will find it)

3. For my understanding SPI is used to get 2 (or more) different micro-controllers to communicate. I am not sure this is what you need (unless it is)
Attachments
RealTimeTarget.mdl
(36.24 KiB) Downloaded 204 times
SerialConnection.mdl
(29.29 KiB) Downloaded 217 times

Saeed
Posts: 12
Joined: Thu Feb 09, 2012 1:18 pm

Re: send and receive multiple data using GUI

Postby Saeed » Sat Mar 10, 2012 10:03 pm

Dear odedyech,
Thank you. Although whenever I use send or receive package in MATLAB I get error (I think its related to the MATLAB version), but fwrite/fread works.
But, the problem still exits :(
See, suppose you have measured the weather degree of a place during one month and you have 15000 samples in a form of MAT file (1st column time, 2nd column value);
How do you build a project to import these values successively in to PIC to be prcessed (e.g. some data processing on the inserted value)?


Return to “General Remark and Questions”

Who is online

Users browsing this forum: No registered users and 1 guest