PDA

View Full Version : SPI Use inside a Timer interrupt



kynix
Feb 27th, 2017, 07:57 PM
Microcontroller: XMC4700 (http://www.kynix.com/Parts/3958415/XMC4700E196F1536AAXQMA1.html)
Interface: DAVE
I would like to send an SPI sequence to an another board in different time intervals. To do that I'm using Dave 4.3.2, the Timer APP and the Interrupt APP. I connected the time event to the interrupt and changed the SPI receiving and transmitting settings to direct.

I tried different possibilities. The timer without the SPI works. As soon as I add the SPI Transmit it doesn't anymore.

Is it possible to start an SPI Transmit in an Interrupt? Here are the seetings and the code :
https://i.stack.imgur.com/CMQFx.png
https://i.stack.imgur.com/fHecP.png
the code for the timer interrupt:

void Time_Interval_Event(void)
{
/* Acknowledge Period Match interrupt generated on TIMER_CCU_1 */
TIMER_ClearEvent(&TIMER_0);
/* When we Arrive at the end of the send values we repeat*/
if (index_count == NumValues){
index_count = 0;
}
/* if the new time starts, send the signal */
if (Timer_Tick_Count == 0){
SPI_MASTER_TransmitWord(&SPI_MASTER_0,IArr[index_count]);// send the wanted current Value

}

Timer_Tick_Count++;

/* when the current time step ends, reset the tick count, change the maximum tick count to the new value and move to the next current value */
if (Timer_Tick_Count == Max_Tick_Count ){
Timer_Tick_Count = 0;
index_count++;
Max_Tick_Count = idxMAXValues[index_count];
//new Max_Tick_Count value
}

/*disable CS to latch data */
TIMER_Start(&TIMER_0);
}
I thought about not putting the SPI in the timer event and trigger the SPI transmit every time the timer finishes. It is also a possibility. I would like though to understand why it is not working in this setting. I tried placing break points to see what happens. But it is not going through the values

Is it possible in principle to place the PSI inside the Interrupt?

thanks for the Help.

aurixuser
Feb 28th, 2017, 02:51 AM
My opinion: It is possible to place any code inside the interrupt, given the code doesn't rely on another interrupt whose priority is lower than the host ISR. Otherwise there will be dead lock.
Does your SPI routine work outside this interrupt?

xmc_Nes
Mar 1st, 2017, 02:27 AM
Hi Kynix,

first thanks for using my code word for word:)
Did you place a break point on the loop where you do the SPI Transmit?
In this configuration it should work definitely. Just sheck that you define the counters right. I remeber changing some stuff in there because the condition of tick count = 0 didn't occur.

I hope it works.

I'm still struggling with the function but if I have an amelioration I'll let you know.







Microcontroller: XMC4700 (http://www.kynix.com/Parts/3958415/XMC4700E196F1536AAXQMA1.html)
Interface: DAVE
I would like to send an SPI sequence to an another board in different time intervals. To do that I'm using Dave 4.3.2, the Timer APP and the Interrupt APP. I connected the time event to the interrupt and changed the SPI receiving and transmitting settings to direct.

I tried different possibilities. The timer without the SPI works. As soon as I add the SPI Transmit it doesn't anymore.

Is it possible to start an SPI Transmit in an Interrupt? Here are the seetings and the code :
https://i.stack.imgur.com/CMQFx.png
https://i.stack.imgur.com/fHecP.png
the code for the timer interrupt:

void Time_Interval_Event(void)
{
/* Acknowledge Period Match interrupt generated on TIMER_CCU_1 */
TIMER_ClearEvent(&TIMER_0);
/* When we Arrive at the end of the send values we repeat*/
if (index_count == NumValues){
index_count = 0;
}
/* if the new time starts, send the signal */
if (Timer_Tick_Count == 0){
SPI_MASTER_TransmitWord(&SPI_MASTER_0,IArr[index_count]);// send the wanted current Value

}

Timer_Tick_Count++;

/* when the current time step ends, reset the tick count, change the maximum tick count to the new value and move to the next current value */
if (Timer_Tick_Count == Max_Tick_Count ){
Timer_Tick_Count = 0;
index_count++;
Max_Tick_Count = idxMAXValues[index_count];
//new Max_Tick_Count value
}

/*disable CS to latch data */
TIMER_Start(&TIMER_0);
}
I thought about not putting the SPI in the timer event and trigger the SPI transmit every time the timer finishes. It is also a possibility. I would like though to understand why it is not working in this setting. I tried placing break points to see what happens. But it is not going through the values

Is it possible in principle to place the PSI inside the Interrupt?

thanks for the Help.