MCP_CAN_lib icon indicating copy to clipboard operation
MCP_CAN_lib copied to clipboard

Make TIMEOUTVALUE macro configurable via compiler flags

Open zharovdv opened this issue 9 months ago • 0 comments

The TIMEOUTVALUE macro currently has a hardcoded value of 2500 (microseconds), which limits the ability to use the library at lower CAN bus speeds (e.g. 10 kbps). At such speeds, a single CAN frame can take longer than 2.5 ms to transmit, causing sendMsgBufBlocking() to timeout even under normal conditions.

This commit wraps the TIMEOUTVALUE definition in a conditional #ifndef, allowing users to override it via compiler flags (-DTIMEOUTVALUE=20000) or a preceding #define TIMEOUTVALUE in their own project code before including <mcp_can.h>.

This change maintains full backward compatibility while enabling more flexible usage across diverse CAN configurations.

Example override in PlatformIO:

build_flags = -DTIMEOUTVALUE=20000

Recommended for projects using slow CAN speeds, high bus load, or long arbitration delays.

zharovdv avatar May 14 '25 08:05 zharovdv