XMC 4500 stops working with interrupts and sd card

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,

I'm trying to make a project that reads a file in a SD card every second. I've managed to make it read a file and I've managed to make it do something every second with interrupts.
However I'm having issues when I put the two things together: the interrupt and the file read...

I have tried two things: open the file in main function and open the file in the interrupt called function. If I open the file in main it runs smoothly, but it only opens the file once. If I do it the other way it hangs...

Here are two parts of the codes: the first that runs fine, and the second that have problems:

int main(void)
{
float Vo[31], soc_real[50], i[50];

DAVE_STATUS_t status;

status = DAVE_Init();

if(status == DAVE_STATUS_SUCCESS)
{
/* Register work area */
res = f_mount(&fs, "0", 1);
res = f_open(&fil_r, "route1.txt", FA_OPEN_ALWAYS| FA_READ);
res = f_lseek(&fil_r, pos);
res = f_read(&fil_r, &buff_r[0], 25, &br);
if (res == FR_OK){
f_close(&fil_r);
}
if (res != FR_OK)
{
while (1U){}
}
}

while (1)
{
}

}

[...]

void algorithm(void){
[...]
}


void interval_handler(void)
{
/* Acknowledge the period match interrupt*/
TIMER_ClearEvent(&TIMER_0);
TIMER_SetTimeInterval(&TIMER_0, TIMER_1S);

algorithm();

TIMER_Start(&TIMER_0);
}



int main(void)
{
//float Vo[31], soc_real[50], i[50];

DAVE_STATUS_t status;

status = DAVE_Init();

while (1)
{
}

}


void interval_handler(void)
{
/* Acknowledge the period match interrupt*/
TIMER_ClearEvent(&TIMER_0);
TIMER_SetTimeInterval(&TIMER_0, TIMER_1S);
/* Register work area */
res = f_mount(&fs, "0", 1);
res = f_open(&fil_r, "route1.txt", FA_OPEN_ALWAYS| FA_READ);
res = f_lseek(&fil_r, pos);
res = f_read(&fil_r, &buff_r[0], 25, &br);
if (res == FR_OK){
f_close(&fil_r);
}

algorithm();

TIMER_Start(&TIMER_0);
}


All the variables posted here are global variables, not specific for some functions, so there must be no problem at all.
I've also tried to mount the drive inside the main and then open the file inside the funcion but it didn't work either.

And, by the way, I know it hangs for two reasons:
1- I have one LED "ticking" during the process (it turns on in the beggining and turns off in the end of the process) that stays on if I run the "faulty" code;
2- When I'm traveling throw break points, the DAVE console shows me this without moving on the file manipulation breakpoint:



Hope that someone can help me.
0 Likes
1 Reply
Not applicable
Does anyone have any idea of how can I "trick" this fail?

Could this be something about more than one instance sharing the same clock?
0 Likes