Skip to content

Commit

Permalink
Resolve issue with Teensy not sending CAN msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed Dec 21, 2023
1 parent 5d6440f commit 7d817e3
Show file tree
Hide file tree
Showing 7 changed files with 402 additions and 366 deletions.
4 changes: 4 additions & 0 deletions speeduino/board_teensy35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
#include "timers.h"
#include "comms_secondary.h"

/*
//These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
#if defined(__MK64FX512__) // use for Teensy 3.5 only
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
#elif defined(__MK66FX1M0__) // use for Teensy 3.6 only
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
#endif
*/

void initBoard()
{
Expand All @@ -22,6 +25,7 @@ void initBoard()
* General
*/
pSecondarySerial = &Serial2;
//Can0.setBaudRate(500000);

/*
***********************************************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions speeduino/board_teensy35.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@
#define SECONDARY_SERIAL_T HardwareSerial

#include <FlexCAN_T4.h>
/*
//These are declared locally in comms_CAN now due to this issue: https://github.com/tonton81/FlexCAN_T4/issues/67
#if defined(__MK64FX512__) // use for Teensy 3.5 only
extern FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
#elif defined(__MK66FX1M0__) // use for Teensy 3.6 only
extern FlexCAN_T4<CAN0, RX_SIZE_256, TX_SIZE_16> Can0;
extern FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> Can1;
#endif
*/
#define NATIVE_CAN_AVAILABLE
#endif //CORE_TEENSY
#endif //TEENSY35_H
735 changes: 385 additions & 350 deletions speeduino/comms_CAN.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions speeduino/comms_CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#define TS_CAN_OFFSET 0x100

void initCAN();
int CAN_read();
void CAN_write();
void sendBMWCluster();
void sendVAGCluster();
void DashMessages(uint16_t DashMessageID);
Expand Down
2 changes: 1 addition & 1 deletion speeduino/comms_secondary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint
outMsg.buf[5] = 0x70;
outMsg.buf[6] = 0x9E;
outMsg.buf[7] = 0x4D;
Can0.write(outMsg);
CAN_write();
#endif
break;

Expand Down
18 changes: 4 additions & 14 deletions speeduino/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "speeduino.h"
#include "timers.h"
#include "comms_secondary.h"
#include "comms_CAN.h"
#include "utilities.h"
#include "scheduledIO.h"
#include "scheduler.h"
Expand Down Expand Up @@ -291,15 +292,7 @@ void initialiseAll(void)
//Setup the calibration tables
loadCalibration();

#if defined (NATIVE_CAN_AVAILABLE)
configPage9.intcan_available = 1; // device has internal canbus
//Teensy uses the Flexcan_T4 library to use the internal canbus
//enable local can interface
//setup can interface to 500k
Can0.begin();
Can0.setBaudRate(500000);
Can0.enableFIFO();
#endif


//Set the pin mappings
if((configPage2.pinMapping == 255) || (configPage2.pinMapping == 0)) //255 = EEPROM value in a blank AVR; 0 = EEPROM value in new FRAM
Expand All @@ -310,11 +303,8 @@ void initialiseAll(void)
}
else { setPinMapping(configPage2.pinMapping); }

/* Note: This must come after the call to setPinMapping() or else pins 29 and 30 will become unusable as outputs.
* Workaround for: https://github.com/tonton81/FlexCAN_T4/issues/14 */
#if defined(CORE_TEENSY35)
Can0.setRX(DEF);
Can0.setTX(DEF);
#if defined(NATIVE_CAN_AVAILABLE)
initCAN();
#endif

//Must come after setPinMapping() as secondary serial can be changed on a per board basis
Expand Down
2 changes: 1 addition & 1 deletion speeduino/speeduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void loop(void)
{
//check local can module
// if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available())
while (Can0.read(inMsg) )
while (CAN_read())
{
can_Command();
readAuxCanBus();
Expand Down

0 comments on commit 7d817e3

Please sign in to comment.