rs232gui and PIC32 starter kit

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

rs232gui and PIC32 starter kit

Postby salemimoh » Mon Nov 01, 2010 12:27 pm

Dear Lubin,
I want to download a matlab application to the PIC32 using PIC32 starter kit. I looked at the rs232gui. It only has the com ports but no USB port, which is used on the starter kit to program the PIC32. Is there a way to how I could get round this problem? What about if I am using the PIC32 I/O expansion board.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Mon Nov 01, 2010 2:59 pm

Matlab/Simulink are used for generating the code and compile it into a .hex file.
Once you have this file, use the microchip MPLAB IDE to load the .hex file and to download it into your target through your own hardware (PIC32 starter kit, or ICD2, ICD3, REAL ICE...)

You may also use a bootloader.

Anyway, Matlab has not the capacity to download your application into your hardware.

rs232gui is used to view variable in real time through an UART interface.

Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Fri Nov 05, 2010 8:11 pm

Thank you lubbin.
I tried to find a way how to downlad the hex file using PIC32 starter kit from MPLAB but I did not find out how to do it. So I tried to import the file into MPLAB using TOOLS then MATLAB/SIMULINK then specify the file name which was opened successfully.
Then GENERATE CODE which is generated successfully.
" ================================================================"
"*** Embedded Target for dsPIC by Lubin KERHUEL - http://www.kerhuel.eu"
" | Licence Accorded to Demonstration Version |"
" | RTWdsPIC@kerhuel.eu |"
" | Companie : Author : Lubin KERHUEL |"
" | WEBSITE : http://www.kerhuel.eu/wiki |"
" | |"
" | SIRENE : 503 920 456 |"
" | SIRET : 503 920 456 00012 |"
" | Financial Service : Demo |"
" | Contact Demo |"
" | Lubin KERHUEL |"
" | 1, rue Alfred Fredet |"
" | 38100 Grenoble |"
" | FRANCE |"
" | Version 3.2c 23-Jul-2010 |"
" | For Matlab 7.8 R2009a |"
" ================================================================"
"*** Created "executable": ..\../train1.elf"
''pic32-bin2hex ..\../train1.elf
"*** Created "executable": ..\../train1.hex"
### Successful completion of Real-Time Workshop build procedure for model: train1
C32 Compiler found
C32 Compiler found
E |"
" | Version 3.2c 23-Jul-2010 |"
" | For Matlab 7.8
BUILD EXECUTION COMMAND COMPLETED


When I tried to import it using IMPORT GENERATED CODE I get this message:

Error : Accessing generated files information from Matlab. Try regenerating code.

Failed to Import Generated Files. Check the Build Window to know the Status of Build

I tried without success to find out the error but I could not.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Fri Nov 05, 2010 8:26 pm

Ok,

1) in MPLAB, select your programmer with the programmer menue.
2) choose the chip you are using
3) import with : file==> import
and choose the .hex file you just generated !

then download it, that's it !

Please, keep an eye on the website as the next release of the blockset will probably have new interresting stuff that will simplify integration with MPLAB.
(expected within few weeks or days)

Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Sat Nov 06, 2010 1:41 pm

Thank you Lubin for your valuable info.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Tue Nov 09, 2010 12:34 am

Latest blockset version (3.3) create the MPLAB project file properly configured. Give it a try !

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Tue Nov 09, 2010 11:23 pm

Lubbin,
I have tried the new version 3.3 but it is still giving me the same error message:
Load Main Project (or) Set Main Project as Active Project

Failed to import Generated Files. Check the Build Window to know the Status of Build. No message was reported in the matlab build window??

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Wed Nov 10, 2010 8:31 am

What is the operation that generate this error ?
Note that you do not need the MPLAB MATLAB plugin !

first, compile the project with MATLAB. (do not open MATLAB through MPLAB)
Then, open MPLAB separately !

In matlab, try to compile the example given in the blockset directory that use a C32 pic.
Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Sun Nov 21, 2010 11:01 pm

Hi Lubin,
I wrote a small program in simulink just as a test, which reads a couple of switches and sends them back to a couple of LEDs. Then I compiled it, and imported it into MPLAB using hex file and it works perfectly. But When I created a MPLAB project and tried to link the bits and pieces as it is shown in the attached file.
When built, it gives the following errors. It looks though there are few files were not created for some reason. such as timer.h, probably rtlibscr.h library files etc.
Is that correct or there is another reason?


Debug build of project `C:\Program Files\Microchip\MPLAB C32\pic32_mplab.mcp' started.
Language tool versions: pic32-gcc.exe v1.05, pic32-ld.exe v1.05, pic32-ar.exe v1.05
Preprocessor symbol `__DEBUG' is defined.
Target debug platform is `__MPLAB_DEBUGGER_PIC32MXSK=1'.
Mon Nov 22 00:13:16 2010
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\Microchip\MPLAB C32\bin\pic32-gcc.exe" -mprocessor=32MX360F512L -x c -c "C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\test1_main.c" -o"test1_main.o" -MMD -MF"test1_main.d" -D__DEBUG -D__MPLAB_DEBUGGER_PIC32MXSK=1 -g
In file included from C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\/test1_private.h:33,
from C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\test1_main.c:28:
C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\/timer.h:42:29: GenericTypeDefs.h: No such file or directory
In file included from C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\/test1_private.h:33,
from C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\test1_main.c:28:
C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\/timer.h:66: error: syntax error before "dwCount"
C:\Documents and Settings\Admin\My Documents\MATLAB\test1_dspic\sources\/timer.h:67: error: syntax error before "ms"
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Program Files\Microchip\MPLAB C32\pic32_mplab.mcp' failed.
Language tool versions: pic32-gcc.exe v1.05, pic32-ld.exe v1.05, pic32-ar.exe v1.05
Preprocessor symbol `__DEBUG' is defined.
Target debug platform is `__MPLAB_DEBUGGER_PIC32MXSK=1'.
Mon Nov 22 00:13:17 2010
----------------------------------------------------------------------
BUILD FAILED
Attachments
test.doc
(87 KiB) Downloaded 171 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Mon Nov 22, 2010 12:49 am

Hi,

Did you created by yourself the MPLAB project, or
did you open the project (.mcp file) created by the latest blockset version ?

The latest blockset version (from v3.3) creates the MPLAB project file. Thus, project can be opened within MPLAB and recompiled from there if needed.

Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Mon Nov 22, 2010 8:40 pm

Dear Lubin,
Thank you very much for your help.
Yes I finally got to the final hurdle, where I loaded the application into MPLAB and compiled it successfully as you mentioned then loaded it into the PIC32 and it worked fine. But I have a small problem. I am trying to follow the program using step by step in the debug mode using the generated machine language (or the un-assembled program if you like) and ir is ok; but I could not trace the C subroutines including the main subroutine; because tracing generated machine language is very tedious and time consuming and is not evident to be followed easily especially in my application where I am implementing relatively long program.
My question is : is there a way by which we can trace step by step in the debug mode the C subroutines such as the main subroutine for instance?

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Mon Nov 22, 2010 11:11 pm

Great that you get it working!
salemimoh wrote:My question is : is there a way by which we can trace step by step in the debug mode the C subroutines such as the main subroutine for instance?

It's a very long time I have not use the debug trace of MPLAB. Thus, I may not be able to help on that point.
The only things I know is that there is two ways:
- Either you use the sim module that will simulate in the PC only the code and you can then check registry values (but not interfere with real signals)
- Or you use the trace system that makes you able to trace the code in the target (I guess you are talking about this method).

I think that capabilities of the second method depends on the programmer you are using (ICD2, real ice) and of the cable connection you are using with the target.
Anyway, using breakpoint is usually the way to stop the program where you want to. Removing compiler optimization may help to trace the code. There are also options to generate debug information at compilation time. I have no recent experience to tell how to switch from assembly tracing to C tracing (anyway, I remember doing this few years ago)
However, it happens that the code run in unexpected ways.

I find myself more time consuming to track bug this way than having the code running in real time and sending debug values through UART.

However, MPLAB has now interesting function. It may be possible to change values of some hard coded variable in hardly real time! I did not test this yet but it might be very useful.

Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Tue Nov 23, 2010 11:03 am

Thank you Lubin,
I will give it a try and see.

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Sun Nov 28, 2010 8:22 pm

Dear Lubin,
I am using rs232gui to read data from the PIC32 through its UART. Because I am using LAPTOP where it only has USB connections, the data could only be read through com3 as it is specified on your site.
Things which I did and the connection was established:

Connecting... May take few seconds...
Port COM3 successfully open at 115200............OK
redefinition SerialCOM
I press PLOT buffer to get the graphic screen. Which it comes through; But When I press start, i do not get any graph.
My question is: Have you got any idea why is that?

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Sun Nov 28, 2010 10:01 pm

Hello
salemimoh wrote: the data could only be read through com3 as it is specified on your site

Could you provide the link ? (I do not remember the whys and wherefores I wrote it)

Anyway, you may test first is the dsPIC is sending data to the PC using an hyperterminal. Most recent windows do not have hyperterminal by default, you may download free version, or alternatively download the pretty good realtermsoftware (free).
Check that the PC is receiving data (you should see characters appearing in the term).

Lubin

salemimoh
Posts: 23
Joined: Tue Apr 08, 2008 1:01 pm

Re: rs232gui and PIC32 starter kit

Postby salemimoh » Mon Nov 29, 2010 8:14 pm

Dear Lubin,
I am sure of the link but I think this is the one:
http://lubink.free.fr/projelectro/Proto ... ew_FR.html
It says I quote:"Les ports COM disparaissant peu à peu des PC et notamment des portables, on peut utiliser des adaptateurs série=>USB avec leur driver de port série virtuel. Un tel adaptateur a été ici utilisé : le port COM 5 est un port COM virtuel."
Though it mentions com5, the only com which com which connects with the controller is com3.

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Marseille - France
Contact:

Re: rs232gui and PIC32 starter kit

Postby LubinKerhuel » Mon Nov 29, 2010 9:00 pm

That is my old French website (beautiful, but perhaps not accurate enough)

Anyway, when you are using a virtual COM port, for example a USB adaptator, this one can take any number of COM port. It usually remains stable. You have to check your computer config (easiest way is to use the list of hardware peripheral installed on your computer. You can browse them with windows

salemimoh wrote:Port COM3 successfully open at 115200............OK
)
This does not mean that COM 3 corresponds to your USB adaptator. Thus, you should check that your COM3 correspond to your USB adaptator.
There is a high probability that this is it !

Then, you may check that your dsPIC is running. try to have make a led blinking to make sure it is running. If it runs properly, you may check that it is blinking at the right frequency (either use a scope, or use a slow blinking frequency like 1 or 2 Hz).

Provided you have a scope, check the Tx line of the microcontroller. It should be changing at pretty high frequency. If you do not have a scope, you can try to send data continuously and use a voltmeter. The voltage read should be about half VDD. If you read VDD or 0, something's wrong.

Ok, From the other side, check that your USB adaptator is working. Use real term, connect to your port COM (COM3), short circuit the UART Rx and Tx pins of the USB adaptator and send characters through the terminal. If the character appears on the terminal, they are sent and receive properly. Adaptator should be OK. If you see nothing when you write something within the terminal screen, it means that nothing is received on the Rx pin. Use a scope to check what's happening then...

I hope theses few ideas will help.
Lubin


Return to “Advanced Simulink & RTW Questions”

Who is online

Users browsing this forum: No registered users and 2 guests