Arrays in struct

cancel
Showing results for 
Search instead for 
Did you mean: 

Arrays in struct

345 Views
Contributor I

Hello,

i am new with lpc1549 in the om13056 board. I am using it for one of my master's project and i am having few problems.

In some part i am calculating a controller and for that i new some values, i took this part froma bigger code and it works in another microcontroller but apparently not with this one.

this is the part:

typedef struct{
   uint16_t KP[4];
   uint16_t KI[4];
   uint16_t KD[4];
}Regelparameter_t;

for(i=0; i<4; i++)
{
   Regelparameter_ptr->KP[i] = 0x0064;
   Regelparameter_ptr->KI[i] = 0x0064;
   Regelparameter_ptr->KD[i] = 0x0064;
}

The code is okay but whenthe program start to run there is an error and it jumps to this part:

__attribute__ ((section(".after_vectors")))
void HardFault_Handler(void)
{ while(1) {}
}

I have no idea to fix this because if i change this struct it will need to change everything and acording to my project i cant do it.

Thanks in advance.

0 Kudos
5 Replies

100 Views
Contributor IV

How do you set up Regelparameter_ptr? what is its value? My guess is that you have not set the pointer correctly. 

0 Kudos

100 Views
Contributor I

Hey, it is a big code and i did not wanted to write everything, Regelparameter_ptr was defined, that is not the problem

volatile Regelparameter_t *Regelparameter_ptr;

The thing is that the very same exact lines worked for an ATmega microcontroller and thaat here it doesnt work. belive me the code should work but it doesnt and the problem is in the for loop or KP, KI and KD definitions.

0 Kudos

100 Views
Contributor IV

You've defined it, but what have you initialised the pointer to? Have you used malloc() or something?

0 Kudos

100 Views
Contributor I

I have tried malloc() and it doesnt work, same error as before, and tthe thing is that this code worked before in another microcontroller.

0 Kudos

100 Views
Contributor IV

Just because it works on another (8-bit?) micro controller does not mean it is going to work on a different 32-bit micro-controller.

So, it looks like you are going to have to debug it then... But, my guess is that you have not correctly allocated memory for your Regeparameter_ptr. Start by looking at its value, just before you start using it.

0 Kudos