AnsweredAssumed Answered

Storing Contents of a Register in a variable

Question asked by Rohan Anand on Sep 30, 2015
Latest reply on Sep 30, 2015 by Mark Butcher

I am trying to store the contents of Port Data Input Register into an array data[i].

code is as follows:

#include "MKL46Z4.h"                    // Device header

void InitLED(void)

{

  SIM->SCGC5=SIM_SCGC5_PORTD_MASK;// Enable clock to PORTD

  PORTD->PCR[5]=256;// Set pin 5 of PORTD as GPIO

  PTD->PDDR=(1u<<5);// Set pin 5 of PORTD as OUTPUT

}

void InitSYSTICK(void)

{

  SysTick->CTRL=0;//Disable the systick timer

  SysTick->LOAD=0x00FFFFFF;//Reload it to its full value 24 bits

  SysTick->VAL=0;//Write something in current register to reset it

  SysTick->CTRL=0x00000005;//101//1=bus clock,0= Disable interrupt,1= enable systick timer

}

int main()

{

  volatile unsigned long time[50];

  volatile unsigned long data[50];

  unsigned long i=0,now=0,last=0,j=0;

  InitLED();

  InitSYSTICK();

  last=SysTick->VAL;

  while(1)

  {

   

    PTD->PTOR=(1u<<5);//Toggle LED

  if(i<50)

  {

  now=SysTick->VAL;

  time[i]=(last-now);

  data[i]=PTD->PDIR;                         

  last=now;

  i++;

  }

  for(j=0;j<=800000;j++)

  {}

  }

}

When I write data[i]=PTD->PDIR; and debug, it goes to HardFault_Handler. I don't know what is the problem with this statement.Please Help?

Outcomes