Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 7 months ago.
CANnucleo: not receiving interruptions
Dear all.
I'm using the CANnucleo library successfully (send/receive) when I use it creating directly an object , however, I'm having problems with the interruption reception when using it from a pointer. I'm able to correctly instantiate it and write messages in the bus, but I cannot receive any interruption, so I don't know when to read the bus. To clarify a little bit the explanation:
Code working
CAN can(RX, TX); can.frequency(1000000); can.attach(onMsgReceived, CAN::RxIrq);
Code NOT working
//Somewhere in the .h file CAN * can_; //Constructor can_ = new CAN(RX, TX); can_->frequency(1000000); can_->attach(this, &Motor::onMsgReceived, CAN::RxIrq);
I have been inspecting the code (mainly "can_api.cpp/.h") and it seems that the problem could come from the way the interruption is attached, because the "can_irq_set" is not called. Anybody knows why this function is commented out? Has anybody experienced the same problem?
template<typename T> void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { if((mptr != NULL) && (tptr != NULL)) { _irq[type].attach(tptr, mptr); // can_irq_set(&_can, (CanIrqType)type, 1); } // else { // can_irq_set(&_can, (CanIrqType)type, 0); // } }
1 Answer
8 years, 7 months ago.
Hello,
As you correctly pointed out, the implemenatation of CAN member function template<typename T>
void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq)
was incomplete. However, it's fixed now. So updating to the latest revision of CANnucleo library should allow you to attach member functions as interrupt handler. Please let me know how it works. Thanks.
Zoltan