AnsweredAssumed Answered

Overwritten memory; MC9S08AW60

Question asked by Jan R. on Aug 1, 2013
Latest reply on Aug 2, 2013 by bigmac

Hello,

I try to tesst my programm with the True time simulator.

However after sbufferpos = 15 (after 15 times ISR_Interrupt) some parts of the buffer array will be overwritten.

Then there occurs an error:

Error: At location 0057 -

Error: Attempt to execute from unimplemented (--) ROM

 

Do you have any idea how to fix this problem?

 

// Includes ----------------------------------------------------------------------------------------

#include <hidef.h> /* for EnableInterrupts macro */

#include "derivative.h" /* include peripheral declarations */

#include "SPIDriver.h"

 

 

// Variablen ---------------------------------------------------------------------------------------

static volatile int sbufferpos = 0;

byte buffer[33];

 

// Prototypen --------------------------------------------------------------------------------------

void BefehlsbufferErstellen(int takt);

void SendeBuffer(byte b);

 

// Main --------------------------------------------------------------------------------------------

void main(void) {

 

 

 

      spi_init();

      spi_setMode(Master, FallingEdge, LeadingEdge, MSBfirst);

    spi_selectChip(true,0);

    BefehlsbufferErstellen(27);

      spi_enableInterrupt(true);

 

      for(;;)

        {    

            __RESET_WATCHDOG();

        } 

   }

 

 

// Interruptroutinen ---------------------------------------------------------------------------------

__interrupt VectorNumber_Vspi1 void ISR_SPI() {

   

           if((SPI1S&(SPI1S_SPRF_MASK)) == 0) {

           }

           else{

              SPI1S;

              SPI1D;

           }

           if((SPI1S&(SPI1S_SPTEF_MASK)) == 0){ 

           }

           else{

                spi_enableInterrupt(false);

                if(sbufferpos > sizeof(buffer) - 1) {

                 sbufferpos = 0;

                } else{

                SendeBuffer(buffer[sbufferpos]);

                sbufferpos++;

                spi_enableInterrupt(true);

                }

            }

}

 

// Funktionen -----------------------------------------------------------------------------------------

void BefehlsbufferErstellen (int takt) {

 

 

  if(takt== 27) {

 

  buffer[0]= 0x9F;    // Set Address

  buffer[1]= 0x24;    // 36d

  buffer[2]= 0x40;    // Write

  buffer[3]= 0x4F;    // 4Fh

 

  buffer[4]= 0x9F;    // Set Address

  buffer[5]= 0x28;    // 40d

  buffer[6]= 0x40;    // Write

  buffer[7]= 0x00;    // 00h

 

  buffer[8]= 0x9F;    // Set Address

  buffer[9]= 0x29;    // 41d

  buffer[10]= 0x40;   // Write    

  buffer[11]= 0x02;   // 02h

 

  buffer[12]= 0x9F;   // Set Address

  buffer[13]= 0x30;   // 42d

  buffer[14]= 0x40;   // Write    

  buffer[15]= 0x9F;   // 0x9Fh

 

  buffer[16]= 0x9F;   // Set Address

  buffer[17]= 0x32;   // 44d

  buffer[18]= 0x40;   // Write    

  buffer[19]= 0x00;   // 00h

 

  buffer[20]= 0x9F;   // Set Address

  buffer[21]= 0x33;   // 45d

  buffer[22]= 0x40;   // Write    

  buffer[23]= 0x0D;   // 0Dh

 

  buffer[24]= 0x9F;   // Set Address

  buffer[25]= 0x35;   // 47d

  buffer[26]= 0x40;   // Write    

  buffer[27]= 0x00;   // 00h

 

  buffer[28]= 0x9F;   // Set Address

  buffer[29]= 0x36;   // 48d

  buffer[30]= 0x40;   // Write    

  buffer[31]= 0x0D;   // 0Dh

 

 

  }

  else if(takt == 26){

 

  buffer[0]= 0x9F;    // Set Address

  buffer[1]= 0x24;    // 36d

  buffer[2]= 0x40;    // Write

  buffer[3]= 0x3D;    // 3Dh

 

  buffer[4]= 0x9F;    // Set Address

  buffer[5]= 0x28;    // 40d

  buffer[6]= 0x40;    // Write

  buffer[7]= 0x20;    // 20h

 

  buffer[8]= 0x9F;    // Set Address

  buffer[9]= 0x29;    // 41d

  buffer[10]= 0x40;   // Write    

  buffer[11]= 0x95;   // 95h

 

  buffer[12]= 0x9F;   // Set Address

  buffer[13]= 0x30;   // 42d

  buffer[14]= 0x40;   // Write    

  buffer[15]= 0xFF;   // FFh

 

  buffer[16]= 0x9F;   // Set Address

  buffer[17]= 0x32;   // 44d

  buffer[18]= 0x40;   // Write    

  buffer[19]= 0x03;   // 03h

 

  buffer[20]= 0x9F;   // Set Address

  buffer[21]= 0x33;   // 45d

  buffer[22]= 0x40;   // Write    

  buffer[23]= 0xE8;   // E8h

 

  buffer[24]= 0x9F;   // Set Address

  buffer[25]= 0x35;   // 47d

  buffer[26]= 0x40;   // Write    

  buffer[27]= 0x03;   // 03h

 

  buffer[28]= 0x9F;   // Set Address

  buffer[29]= 0x36;   // 48d

  buffer[30]= 0x40;   // Write    

  buffer[31]= 0xE8;   // E8h

 

  }

  else {

  }

}

 

 

void SendeBuffer(byte b) {

 

__RESET_WATCHDOG();

spi_sendData(b);

 

}

Outcomes