interrupt for input port H using HCS12 T-board and mc9s12dp512 chip

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

interrupt for input port H using HCS12 T-board and mc9s12dp512 chip

Jump to solution
6,603 Views
dan23
Contributor III

Hi I’m new using codewarrior and the HCS12 T-board, onboard is the mc9s12dp512 chip. The chip uses TwinPeeks monitor. 

 

I want to use an interrupt when I trigger input pin 0 from port H. My program is working fine till I trigger the input. The mc9s12dp512 chip resets itself when the input is triggered, why?

What am I doing wrong?

 

 

//below are my settings for port H

PERH = 0xff;

PIEH = 0x01;

PIFH_PIFH0 = 1;

 

 

//example code to tryout an interrupt

#pragma CODE_SEG NON_BANKED //INTO  ROM_C000

interrupt 25 void intefunc(void)

{

  //while(PTH_PTH0==0);

 

  PORTB = ~0x99;

 

  delayms(1000);

 

  PIFH_PIFH0 = 1;

}                

#pragma CODE_SEG DEFAULT

 

 

Thanks in advance for every reaction.
Greetings dan23

Labels (1)
Tags (1)
0 Kudos
1 Solution
1,530 Views
dan23
Contributor III

Hi,

 

I’ve implemented the near statement into the code and my interrupts are working now.

 

Thanks.

 

Greetings dan23

View solution in original post

0 Kudos
11 Replies
1,531 Views
dan23
Contributor III

Hi,

 

I’ve implemented the near statement into the code and my interrupts are working now.

 

Thanks.

 

Greetings dan23

0 Kudos
1,530 Views
dan23
Contributor III

I forgot to mention that my isrFunc is located in the non banked memory.  

 

#pragma CODE_SEG NON_BANKED

interrupt void isrFunc(void)

{

  PORTB = ~0x99;

  delayms(1000);

 

  PIFH_PIFH0 = 1;

}                

#pragma CODE_SEG DEFAULT

 

void SetPorts(void)

{

  PERH = 0b11111111; //1 = a pull-up device is enabled.

  PPSH = 0x00;            //Falling edge on the associated port H pin sets the associated flag //bit in the PIFH register

  PIEH = 0b00000001;            //1 = Interrupt is enabled

  PIFH_PIFH0 = 1;      //Active edge on the associated bit has occurred, Writing a 1 clears //the associated flag.

                                    //an interrupt will occur if the associated enable bit is set

}

 

void main(void)

{  

  SetPorts();

 

  // install portH pseudo vector in RAM

  // (if running with TwinPEEKs monitor)

  *((unsigned char *)0x3fb5) = 0x25; // JMP opcode

  *((void (**)(void))0x3fb6) = isrFunc;

                       

  EnableInterrupts;

 

  for(;:smileywink:{

  ………………

  }

}

 

But the MCU still doesn’t call my isrFunc when I switch portH.0 . When I switch portH.0 the program stops running and it does nothing.

What am I doing wrong.

 

Greetings dan23

0 Kudos
1,530 Views
kef
Specialist I
You should not change JMP ext opcode constant, it's 6 and not 0x25.
 
Since it's a banked memory model, you should use near keyword like this:
 
  *((void (* near *)(void))0x3fb6) = isrFunc;
0 Kudos
1,530 Views
CrasyCat
Specialist III
Hello
 
The appropriate pragma to specify you want to allocate the function in section NON_BANKED is
 
#pragma CODE_SEG __NEAR_SEG NON_BANKED
And as the function pointer is a near function pointer you need to initialize it as follows:
 

*((unsigned char *)0x3fb5) = 0x6; // JMP opcode
*((void (*near*)(void))0x3fb6) = isrFunc;
 
CrasyCat
0 Kudos
1,530 Views
dan23
Contributor III

I’ve adjusted my interrupt function to "interrupt void isrFunc()".

 

*((unsigned char *)0x3fee) = 0x06; // JMP opcode

*((void (**)(void))0x3fb5) = isrFunc;

 

I’ve changed address 0x3fef to 0x3fb5 because that is the address where twinpeeks wants the function. I found this information in the T-board manual on page 32.

 

I do not really know how this piece of code works.

 

When I switch an input to trigger the interrupt it didn’t call my interrupt function but he jammed and didn’t do anything. I had to reset the HCS12 board to get a reaction from it.

   

Greetings dan23

0 Kudos
1,530 Views
dan23
Contributor III

I’ve removed the interrupt vector number and included this code,

 

*((unsigned char *)0x3fee) = 0x06; // JMP opcode

*((void (**)(void))0x3fef) = isrFunc;

 

in my main() before EnableInterrupts.

 

I get the error “isrFunc not declared”.

 

When I try to load my previous .phy file directly into the MCU, I got the error from twinpeeks:

Invalid S-record

 

I use banked memory in codewarrior and convert it to linear in SRecCvt.

 

When I use this code:

*((unsigned char *)0x3fee) = 0x06; // JMP opcode

*((void (**)(void))0x3fef) = isrFunc;

 

How do I declare witch function has to be called when an interrupt is triggered?

 

Greetings dan23

0 Kudos
1,530 Views
CrasyCat
Specialist III
Hello
 
Well as far as I can tell isrFunc is the name of the function which should be triggered when an IRQ arises.
 
CrasyCat
0 Kudos
1,530 Views
dan23
Contributor III

Hi,

 

I use SRecCvt to align my s19 file. I’ve always aligned the .phy file from codewarrior and I couldn’t find my interrupt addresses in the out.s19 file from SRecCvt when I aligned the .phy file. So I tried to align the s19 file generated by codewarrior and I get the following warning in oc-console:  

 

20>l

loading …

*******************

Write error at BFC0

20>FFFFFFFFFFFFFFFC01536

Argument missing!

20>FFFFFFFFFFFFFFFFC0003B

Argument missing!

20>

 

My main program is still working but when I call my interrupt by switching input port H pin 0 the MCU stops running and nothing happens.

 

I use the SRecCvt GUI and my settings are:

 

Device = MC9S12Dx512

Memory = flash

Operation = convert

Output File Format = linear

S-record Size = 16

 

 

I don’t know what causes this problem.

 

What kind of s19 file is TwinPeeks expecting and how do I get the right file?

 

Greetings dan23

0 Kudos
1,530 Views
dan23
Contributor III

Hi,

 

I think I’ve found a explanation of the error that occur in oc-console. I found this piece of text in the HCS12 manual.   

 

Redirected Interrupt Vectors

 

The interrupt vectors of the HCS12 are located at the end of the

64KB memory address range, which falls within the protected monitor code space. Therefore, the application program can not modify the interrupt vectors directly. To provide an alternative way, the monitor redirects all vectors (except the reset vector) to RAM. The procedure is similar to how the HC11 behaved in Special Bootstrap Mode.

 

The application program can set the required interrupt vectors during runtime (before global interrupt enable!) by placing a jump instruction into the RAM pseudo vector. The following example shows the steps to utilizy the IRQ interrupt:

 

For a C program, the following sequence could be used:

// install IRQ pseudo vector in RAM

// (if running with TwinPEEKs monitor)

*((unsigned char *)0x3fee) = 0x06; // JMP opcode

*((void (**)(void))0x3fef) = isrFunc;

 

 

I implemented the C – code of this example in my main.c but it didn’t compile. I think the example code isn’t for codewarrior but for ICC12.

How do I translate it into codewarrior code? Or is there another way to solve this problem?

 

Greetings dan23

0 Kudos
1,530 Views
CrasyCat
Specialist III
Hello
 
Some questions here.
What is the error message you are getting?
 
Are you building your code in small or banked memory model?
Where is the function isrFunc allocated in memory?
 
CrasyCat
0 Kudos
1,530 Views
kef
Specialist I
Using TwinPeeks you don't have to align S-records. *.phy file from CW should be fine.
 

interrupt 25 void intefunc(void)

Also you should remove interrupt vector number from ISR declaration, since TwinPEEKs has vector area protected and TwinPEEKs won't load anything to write protected areas. Instead of vector number after interrupt keyword, put this code into main() before asm cli or interruptenable

*((unsigned char *)0x3fee) = 0x06; // JMP opcode

*((void (**)(void))0x3fef) = isrFunc;

0 Kudos