From 1605e7aa30e6a8db6d623413c42efa4339057653 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 23 Oct 2025 14:07:47 -0400 Subject: recalculate bittimings --- fw/can.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/fw/can.h b/fw/can.h index c9b3d4b..c7a6c18 100644 --- a/fw/can.h +++ b/fw/can.h @@ -18,15 +18,15 @@ #define CAN_CS LATAbits.LATA5 // Bit timings (CNF1, CNF2, CNF3) -#define CAN_TIMINGS_10K 0xDD, 0xAD, 0x06 // BRP=30, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 -#define CAN_TIMINGS_20K 0xCE, 0xAD, 0x06 // BRP=15, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 -#define CAN_TIMINGS_50K 0xC5, 0xAD, 0x06 // BRP=6, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 -#define CAN_TIMINGS_100K 0xC2, 0xAD, 0x06 // BRP=3, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 -#define CAN_TIMINGS_125K 0xC3, 0x9A, 0x03 // BRP=4, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 -#define CAN_TIMINGS_250K 0xC1, 0x9A, 0x03 // BRP=2, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 -#define CAN_TIMINGS_500K 0xC0, 0x9A, 0x03 // BRP=1, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 -#define CAN_TIMINGS_800K "800kbps unsupported" // not possible with 12MHz clock -#define CAN_TIMINGS_1M "1Mbps unsupported" // not possible with 12MHz clock +#define CAN_TIMING_10K 0xDD, 0xAD, 0x06 // BRP=30, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 +#define CAN_TIMING_20K 0xCE, 0xAD, 0x06 // BRP=15, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 +#define CAN_TIMING_50K 0xC5, 0xAD, 0x06 // BRP=6, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 +#define CAN_TIMING_100K 0xC2, 0xAD, 0x06 // BRP=3, PropSeg=6, PS1=6, PS2=7, SP=65%, SJW=4 +#define CAN_TIMING_125K 0xC3, 0x9A, 0x03 // BRP=4, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 +#define CAN_TIMING_250K 0xC1, 0x9A, 0x03 // BRP=2, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 +#define CAN_TIMING_500K 0xC0, 0x9A, 0x03 // BRP=1, PropSeg=3, PS1=4, PS2=4, SP=66.7%, SJW=4 +#define CAN_TIMING_800K "800kbps unsupported" // not possible with 12MHz clock +#define CAN_TIMING_1M "1Mbps unsupported" // not possible with 12MHz clock // MCP2515 modes of operation typedef enum { @@ -57,20 +57,29 @@ void canInit(void); void canSetMode(CanMode mode); // Set the bit timing parameters (bitrate, etc.). -// Pass one of the CAN_TIMINGS_x macros. +// Pass one of the CAN_TIMING_x macros. // The MCP2515 must be in Config mode. void canSetBitTiming(U8 cnf1, U8 cnf2, U8 cnf3); // Enable/disable interrupts on the MCP2515's INT pin. void canIE(bool enable); +// Read RX status with RX STATUS instruction. +U8 canRxStatus(void); + +// Read the DATA field of RXB0. +void canReadRxb0Data(U8 data[8u]); + +// Read the DATA field of RXB1. +void canReadRxb1Data(U8 data[8u]); + // Set the message acceptance mask of RXB0. // The MCP2515 must be in Config mode. void canSetMask0(const CanId *mask); // Set the message acceptance mask of RXB1. // The MCP2515 must be in Config mode. -void canSetMask0(const CanId *mask); +void canSetMask1(const CanId *mask); // Set message acceptance filter 0 (RXB0). // The MCP2515 must be in Config mode. -- cgit v1.2.3