pierremolinaro / acan2515

MCP2515 CAN Controller Driver for Arduino
MIT License
77 stars 30 forks source link

ACAN2515::begin() hangs if it is called the 3rd time. #4

Open qwec01 opened 5 years ago

qwec01 commented 5 years ago

In some caces, I have to change the filters and masks of one of my MCP2515s (yes I have 2, and they have to work together), after that, I have to recall the "begin" method. In the LoopBackDemo, when I tried to call begin again with "settings.mReceiveBufferSize = 31;" (Just for testing), the Arduino hangs. Then, I tried setting "settings.mReceiveBufferSize = 8;", and discovered that I can call begin twice, it hangs at the 3rd call. So I think when begin is called, this driver allocates the recieve buffer to a new space of RAM, not using the old space, and this filled the RAM up. Maybe I'm wrong, I'm not familiar with C++. Any solutions? Or I just missed something?

pierremolinaro commented 5 years ago

Hello,

So I think when begin is called, this driver allocates the recieve buffer to a new space of RAM, not using the old space, and this filled the RAM up.

You are right, when ACAN2515::begin is called, the receive and transmit buffers are allocated, and current release does not deallocate them before allocation. On the first ACAN2515::begin call it is ok because the buffers are not allocated.

A workaround is to insert the deallocation instruction in the ACANBuffer16.h file : public: bool initWithSize (const uint16_t inSize) { delete [] mBuffer ; // Line to insert mBuffer = new CANMessage [inSize] ;

Il will add this line in the future 1.1.1 release.

Best regards,

Pierre

Le 16 janv. 2019 à 10:58, qwec01 notifications@github.com a écrit :

In some caces, I have to change the filters and masks of one of my MCP2515s (yes I have 2, and they have to work together), after that, I have to recall the "begin" method. In the LoopBackDemo, when I tried to call begin again with "settings.mReceiveBufferSize = 31;" (Just for testing), the Arduino hangs. Then, I tried setting "settings.mReceiveBufferSize = 8;", and discovered that I can call begin twice, it hangs at the 3rd call. So I think when begin is called, this driver allocates the recieve buffer to a new space of RAM, not using the old space, and this filled the RAM up. Maybe I'm wrong, I'm not familiar with C++. Any solutions? Or I just missed something?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2515/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/ASys1F_4FlDHujlTM_i0d4sWyxf26wJLks5vDvfegaJpZM4aCs4v.