2014-02-04 01:53 PM
Gents (and maybe Ladies),
My goal is to wait until a certain amount of data has been received. I have setup an interrupt (Can Bus) and when it is triggered it stuffs the message into an Array. I'm using the following code to wait until all the data is received. However, while in the loop, the CAN interrupt does not trigger. This loop is inside input interrupt, and is after the EXTI flag has been cleared. (There is an infinite loop in the main function) What is the best way to achieve this? Thanks! -Mattint
recCount = CanDriver::CacheCount();
while
(recCount < 100)
{
recCount = CanDriver::CacheCount();
}
CanRxMsg RxMessageArray[200];
int
ArrayCounter = 0;
int
recCounter = 0;
extern
''C''
void
CAN1_RX0_IRQHandler(
void
)
{
GPIO_WriteBit(GPIOD, GPIO_Pin_3, Bit_SET);
CanRxMsg rxMessage;
CAN_Receive(CAN1, CAN_FIFO0, &rxMessage);
CanDriver::StuffCanMsg(rxMessage);
recCounter++;
CAN_ClearITPendingBit(CAN1, CAN_IT_TME);
GPIO_WriteBit(GPIOD, GPIO_Pin_3, Bit_RESET);
}
void
CanDriver::StuffCanMsg(CanRxMsg RxMessage)
{
RxMessageArray[ArrayCounter++] = RxMessage;
}
std::vector<CanRxMsg> CanDriver::ReceiveCache(
bool
empty
/*= true*/
)
{
std::vector<CanRxMsg> returnMessages;
returnMessages.assign(RxMessageArray, RxMessageArray + ArrayCounter);
if
(empty)
{
ArrayCounter = 0;
recCounter = 0;
}
return
returnMessages;
}
int
CanDriver::CacheCount()
{
return
recCounter;
}
#nvic #nvic
2014-02-05 07:26 AM
What is the priority of the EXTI and CAN interrupts? If EXTI is a higher priority then the CAN interrupt is never handled.
Jack Peacock2014-02-05 11:34 AM
Hi Jack,
Thanks for the reply!The EXTI is 2, and the CAN interrupt is 0.I cant figure this one out. As the the EXTI flag is cleared as soon as the irq is handled.-Matt2014-02-05 02:12 PM
2014-02-05 02:59 PM
Thats for the reply! Thats an awesome idea! Typically (i'm a c# guy) i've handled the complete routine in the event handler. I will try the flag thing out later tonight and report back.
Thanks again!