5 years, 2 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.attach(onMsgReceived, CAN::RxIrq);

Code NOT working

//Somewhere in the .h file
CAN * can_;

can_ = new CAN(RX, TX);
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

5 years, 2 months ago.

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.


Accepted Answer

Dear Zoltan,

Thank you for your fast reply, and also, thank you for your effort solving this issue so diligently. I've just tried your new revision and it works perfectly, it will help me to keep the organization and coherence in my project code.

Best regards.

posted by M B 20 May 2016