Getting started with MC9S12XDP512

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting started with MC9S12XDP512

2,339 Views
BJA
Contributor I
Hi,
 
    I have been trying to work with the MC9S12XDP512 (AdaptS12X)  mcu module. I purchased this module from technologicalarts. I wrote a simple program - in assembly-  to  make Port PA7 high. This port is connected in series with a resistor and a diode. So when it goes high, the diode will be on. When I load the program using codewarrior, nothing happens ( There are also no errors generated). I've also tried using ubug12x to load the s19 file generated by codewarriror onto the module. It keeps giving an flash/eeprom error. I was told to convert the s19 file from codewarrior which is banked to a linear one and then tried to load it. This procedure gave me "Index was outside the bounds of the array" error and sometimes an unkonwn error. I have pasted a copy of my *.asm file.
 
   I need help getting started!!!!!!!!
 
 
 
;*****************************************************************
;* This stationery serves as the framework for a                 *
;* user application (single file, absolute assembly application) *
;* For a more comprehensive program that                         *
;* demonstrates the more advanced functionality of this          *
;* processor, please see the demonstration applications          *
;* located in the examples subdirectory of the                   *
;* Freescale CodeWarrior for the HC12 Program directory          *
;*****************************************************************
; export symbols
            XDEF Entry            ; export 'Entry' symbol
            ABSENTRY Entry        ; for absolute assembly: mark this as application entry point
; include derivative specific macros
            INCLUDE 'mc9s12xdp512.inc'
ROMStart    EQU  $4000  ; absolute address to place my code/constant data
; variable/data section
            ORG RAMStart
 ; Insert here your data definition.
Counter     DS.W 1
FiboRes     DS.W 1

; code section
            ORG   ROMStart
           
Entry:      BSET DDRAB_DDRA7, #%00000001
            BSET PORTA_PA7, #%00000001
            MOVB #0, DDRJ_DDRJ0
            MOVB #0, PTJ_PTJ0
           
            LDS   #RAMEnd+1       ; initialize the stack pointer
            CLI                   ; enable interrupts
mainLoop:
            LDX   #1              ; X contains counter
couterLoop:
            STX   Counter         ; update global.
            BSR   CalcFibo
            STD   FiboRes         ; store result
            LDX   Counter
            INX
            CPX   #24             ; larger values cause overflow.
            BNE   couterLoop
            BRA   mainLoop        ; restart.
CalcFibo:  ; Function to calculate fibonacci numbers. Argument is in X.
            LDY   #$00            ; second last
            LDD   #$01            ; last
            DBEQ  X,FiboDone      ; loop once more (if X was 1, were done already)
FiboLoop:
            LEAY  D,Y             ; overwrite second last with new value
            EXG   D,Y             ; exchange them -> order is correct again
            DBNE  X,FiboLoop
FiboDone:
            RTS                   ; result in D
            END
;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
           ORG   $FFFE
            DC.W  Entry           ; Reset Vector
Labels (1)
0 Kudos
2 Replies

501 Views
mculater
Contributor III
There are several problems:

First, you misunderstand the mask definitions for port and data direction registers in mc9s12xdp512.inc.  They indicate the bit number in the byte, useful in some cases to assist the programmer in creating self-documenting code.  Your code is:
            BSET DDRAB_DDRA7, #%00000001
            BSET PORTA_PA7, #%00000001

To use bit masks, it should be more like this (note the "m" prefix):
            BSET DDRAB, #mDDRAB_DDRA7
            BSET PORTAB, #mPORTAB_PA7

But the definitions for PORTAB and DDRAB are meant to be used with Word instructions, allowing you to set parameters of both PortA and PortB simultaneously. For byte operations (such as the BSET instruction), you should use the byte-oriented PORTA and DDRA designations instead.  However, my advice to you is to take advantage of the existing user LED on PortP (PP7).  That will eliminate any chance of mis-counting pin numbers on the header or wiring errors on your part when hooking up your LED.  Also, bit masks and BSET instructions are tricky for beginners.  There's no harm in defining the entire port as outputs and setting all the bits high.  In that case, the correct code would be:
            MOVB #$FF, DDRP
            MOVB, #$FF, PORTP

(By the way, there's a similar problem using bit masks with the two MOVB instructions that follow in your code.  I suggest you just use the CLR instruction:  CLR DDRJ, followed by CLR PORTJ).

Secondly, you are not using a BDM pod, therefore you must rely on the Serial Monitor to load your program into Flash.  The Serial Monitor resides in the top 2K of flash, in a protected block.  This block is also where the vectors reside (e.g. Reset Vector).  The Serial Monitor implements a User Vector Table, just below the protected Flash block, to deal with this issue.  Therefore you must change the ORG directive at the end of your program to $F7FE.  The way it is now, your resulting s-record file references an address in the protected Flash block, so you get the "can't write Flash/EEPROM" error in uBug12X.

The complete CW project for the demo program for this board (in assembler) can be found at
http://support.technologicalarts.ca/docs/Adapt9S12X/Code/S12XCWDemo.rar
It's a good place to start (i.e. modifying a "known-good" working program).
An App Note for using CW with this board can be found at:
http://support.technologicalarts.ca/docs/Adapt9S12X/Using%20CodeWarrior%20Assembler%20with%20Adapt9S...

I suggest you use uBug12X to load the demo, to get some experience with uBug12x.  The modified version of the demo s19 file, with UserVectors to work with the Serial Monitor, can be found at:
http://support.technologicalarts.ca/docs/Adapt9S12X/Code/s12xSM-demo.s19
Ignore the "out of bounds error" and you'll find that it has loaded and runs when you switch to Run and press Reset.  Use a terminal program set to 115Kbaud, and press <ENTER> to interact with the demo menu.

Best regards,
Carl Barnes
www.technologicalarts.com
A complete selection of HC11/HC12/HCS12(X) modules!


--
Alban Edit: modified links to be clickable



Message Edited by Alban on 2007-10-15 08:15 AM
0 Kudos

501 Views
BJA
Contributor I
Carl,
 
 Do you know how I could change the ORG directive in C/C++? Better yet, do you know how I could talk straight to my MCU with codewarrior.  Right now dowloading code to my board is a three step process. Firstly, I compile the code with codewarrior, then I use the sreccvt to convert the s19 file from banked to linear, then I use MiniIde to talk to the MCU through a BDM pod.
 
BJA
0 Kudos