UART on Explore16

Create new topics, add your comment, remark, bugs...
Post Reply
resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

UART on Explore16

Post by resodad » Tue Feb 09, 2010 6:58 pm

Hello, I am trying to use UART2. It is very simple: send sequence 0, 1, 2, 3...15 repeating to UART2 at 9600/8/1/none/none.
Result:
Terminal program on computer --cursor jumps from position to position, but no text or numbers.
I am generating code through MPLAB.
versions:
Windows vista
MPLAB v8.36
C30 v3.20
MATLAB r2009a
no build errors
I will attach model and source code
Thanks,
John
Attachments
UARTtest2.zip
(32.77 KiB) Downloaded 435 times

Bobes
Posts: 36
Joined: Wed Nov 25, 2009 11:27 am
Location: Brno, CZE
Contact:

Re: UART on Explore16

Post by Bobes » Wed Feb 10, 2010 1:15 pm

than it is probably working right
look at the ASCII table http://www.asciitable.com/

hyperterminal is "translating" to ascii

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Wed Feb 10, 2010 6:26 pm

YES! THANKS Bobes
of course you are correct. I changed the input to [0:255} and now have the entire ASCII set
Cheers,
John

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Fri Feb 26, 2010 12:51 am

Lubin, I have a new problem on this effort: When I run the program it will very quickly halt:
Running...
Target halted
I am not aware of changing anything. If I attempt to import all source files into MPLAB and rebuild, I get:
Link step failed.
.
.
.
BUILD FAILED

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

Re: UART on Explore16

Post by LubinKerhuel » Fri Feb 26, 2010 5:07 pm

Hey,

- check that your programmer (ICD2 ?) is not in debug mode while loading the program.
(it shouldn't as you compiled inside matalb and not directly into mplab).

- check your hardware, specificaly the quartz signal ; do you use a pin MCLR, if so, is it tight to "1" properly. running time is it always the same or does it changes from one try to another ?

last things, trap error could be caused by division by 0 or so, check that point.

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Fri Feb 26, 2010 8:49 pm

I am new to MPLAB; I'm not sure what to do. So far I have used the ICD3 only in degugger mode. I am thinking the procedure is build the model directly in matlab, add the .hex file to the MPLAB project and then in MPLAB:
programmer > select programmer > ICD3
programmer > program
and the program will start running.
This is what I am trying and there is no output from the dsPIC

I am not using MCLR
I is not a divide by zero problem.

This program was working earlier.

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

Re: UART on Explore16

Post by LubinKerhuel » Fri Feb 26, 2010 10:36 pm

resodad wrote:programmer > select programmer > ICD3
programmer > program
between theses two step, load the .hex file, or the .coff file (I guess that's already done)

Two more ideas :

- Check the dsPIC configuration bits programmation : MPLAB can use either the configuration that is in the .hex/.coff file, or the configuration bytes defined in the MPLAB interface. It must be set to use the .hex/.coff information, or you must configure theses bytes carefully in MPLAB.

- MPLAB has a release signal (connected to MCLR) that (sometimes) allows to start/stop the program.

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

Re: UART on Explore16

Post by LubinKerhuel » Mon Mar 01, 2010 10:54 pm

One more remarks : Do not compile anything within MPLAB. Just load the hex file :

In the case you use the blockset, you import the .hex (or .coff) binary file into MPLAB and you must directly program without compiling within the MPLAB interface. Otherwise, you compile the current project that does not correspond to code generated by Simulink.
Thus, order is :
--> Select chip in MPLAB
--> Select programmer
--> Load your Hex/coff file generated within Matlab/Simulink into MPLAB
--> Check dspic configuration bits settings (see post up)
--> load the program into the chip through ICD2 / ICD3 / Real ice or equivalent
--> press "release" button if necessary. Sometimes it is necessary to disconnect the cable.

You cannot do debugging with this method as the project with c files and so is not configured within MPLAB.

Another method is to configure a new project, importing c files and library from the simulink's model subdirectory. Then compile the project as a usual project. With this last solution, you can debug using mplab tools.

Lubin

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Tue Mar 02, 2010 9:10 pm

Thanks, I still have no output from dsPIC
Attached is an image of my configuration bits, and the latest simulink model. I cannot find a configuration bit regarding MCLR. I don't know how to set / clear. I am not sure what you mean by "release button;" I assume you mean Programmer menu > release from reset? Does this make the program run?

MCLR pin (pin 13 of dsPIC33FJ256GP710) measures 3 volts with voltmeter.

See warnings 1 and 2 from Matlab upon opening model file below. I got these at different times opening the simulink model:

Code: Select all

warning 1:
C30 Compiler found
Warning: dsPICdrivers.mdl, line 47: block_diagram does not have a parameter named
'CovForceBlockReductionOff'. 
  In general\private\openmdl at 13
  In open at 154
  In uiopen at 196
Warning: The *System Target File must be defined to dsPIC Real Time workshop (Simulation ==>
Configuration Parameters ==> Real Time workshop. 
  In general\private\openmdl at 13
  In open at 154
  In uiopen at 196
Warning: Error evaluating 'LoadFcn' callback of Master block (mask) 'Master'. The *System
Target File must be defined to dsPIC Real Time workshop (Simulation ==> Configuration
Parameters ==> Real Time workshop. 
  In general\private\openmdl at 13
  In open at 154
  In uiopen at 196
Warning: In instantiating linked block 'UARTtest4/Master' : Invalid setting in Master block
(mask) 'Master' for parameter 'MCLR'. 
  In general\private\openmdl at 13
  In open at 154
  In uiopen at 196
PT>>

Code: Select all

warning 2:
>> clear all
C30 Compiler found
Warning: In instantiating linked block 'UARTtest4/Master' : Invalid setting in Master block
(mask) 'Master' for parameter 'MCLR'. 
  In general\private\openmdl at 13
  In open at 154
  In uiopen at 196
PTPTPTPNumber of I/O PINs used : 6
TPTTPTPT>>
Attachments
config bits
config bits
UARTtest4.zip
simulink model
(8.45 KiB) Downloaded 393 times

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

Re: UART on Explore16

Post by LubinKerhuel » Wed Mar 03, 2010 12:42 am

Good news, as I think I found the problem and solution is very simple.
Few elements first
resodad wrote:See warnings 1 and 2 from Matlab upon opening model file below. I got these at different times opening the simulink model
I can't get a ride of them yet but theses warning are not a problem.

If you get at the end of compilation

Code: Select all

*** Created executable: ..\../UARTtest4.coff
''pic30-bin2hex ..\../UARTtest4.coff  
*** Created executable: ..\../UARTtest4.hex
### Successful completion of Real-Time Workshop build procedure for model: UARTtest4
C30 Compiler found
C30 Compiler found
PTPTPNumber of I/O PINs used : 6
it's Ok.

I check model's logic, it's all fine. (Port A should work), you may replace the Repeating Sequence Stair block with a simple 8 bit counter.

The problem is in MPLAB :
In the picture you present here, the .hex file is not loaded correctly as you added the file to a project and this is not the way to do.
You can see in the config bits that is presented on the screenshot that for example the oscillator mode (FNOSC) is set to Internal Fast RC. It should be set instead to primary oscillator w/PLL as demanded on the simulink file. (Configuration bits set in code checkbox is set correctly here.)

From MPLAB,
- First close any open project (Project ==> Close) (it is not necessary, but it will make things more clear)
- Select programmer (ICD2, and the set configurations bits set in code checkbox) etc...
- Load the .hex file : (File ==> Import, no add into project or other way ) You may see the checksum below the menu to change. <== This is the Solution that will solve the problem
- you may check that the .hex file is properly imported throws the configurations bits, for example check the Oscillator mode (FNOSC), should be set automatically to primary oscillator w/PLL.
- program as usual, without compiling anything within MPLAB ; that's it !

Note that you must Import again the .hex file each time the simulink model is compiled in Matlab, in order to program the last binary result into the dsPIC.

Please, feel free to edit the wiki at the place where it would have helped you. It seems be missing right now!

Lubin

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Wed Mar 03, 2010 5:55 pm

Excellent work Lubin, thank you much.
This project is working now on Explorer16 with sdPIC33FJ256GP710. I was adding the file to a MPLAB Project instead of importing.
One minor problem: The simulink source "repeating sequence stair" does not work as I expect now, but it's not a big deal since the source "limited counter" set to 127 is working. Do you have any ideas about this?
I have also duplicated the project on Evidence Flex which I wil post separately.

resodad
Posts: 71
Joined: Tue Jul 07, 2009 1:06 pm
Location: West Point, New York

Re: UART on Explore16

Post by resodad » Wed Mar 03, 2010 11:15 pm

I am attaching an example for the Flex board
Attachments
UART7.zip
Simulink model and .hex file
(9.3 KiB) Downloaded 459 times
Serial Communications with Microchip dsPIC33.pdf
Example on FLEX with oscilloscope image
(193.06 KiB) Downloaded 504 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 29 guests