diff --git a/speeduino/cancomms.ino b/speeduino/cancomms.ino index 8a412df6..55fe4ad7 100644 --- a/speeduino/cancomms.ino +++ b/speeduino/cancomms.ino @@ -291,6 +291,17 @@ void sendCancommand(uint8_t cmdtype, uint16_t canaddress, uint8_t candata1, uint case 3: //send to truecan send routine //canaddress == speeduino canid, candata1 == canin channel dest, paramgroup == can address to request from + outMsg.id = (canaddress); + outMsg.len = 8; + outMsg.buf[0] = 0x0B ; //11; + outMsg.buf[1] = 0x145; + outMsg.buf[2] = candata1; + outMsg.buf[3] = 0x24; + outMsg.buf[4] = 0x7F; + outMsg.buf[5] = 0x70; + outMsg.buf[6] = 0x9E; + outMsg.buf[7] = 0x4D; + Can0.write(outMsg); break; default: diff --git a/speeduino/init.ino b/speeduino/init.ino index 675c4c8b..83e4284d 100644 --- a/speeduino/init.ino +++ b/speeduino/init.ino @@ -48,14 +48,21 @@ void initialiseAll() Serial.begin(115200); if (configPage9.enable_secondarySerial == 1) { CANSerial.begin(115200); } - #if defined(CORE_STM32) || defined(CORE_TEENSY) + #if defined(CORE_STM32) configPage9.intcan_available = 1; // device has internal canbus - //Teensy onboard CAN not used currently + //STM32 can not currently enabled + #endif + + #if defined(CORE_TEENSY) + 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 250k - //FlexCAN CANbus0(2500000, 0); - //static CAN_message_t txmsg,rxmsg; - //CANbus0.begin(); + //setup can interface to 500k + //volatile CAN_message_t outMsg; + //volatile CAN_message_t inMsg; + Can0.begin(); + Can0.setBaudRate(500000); + Can0.enableFIFO(); #endif //Repoint the 2D table structs to the config pages that were just loaded diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 6365eedb..bd07894d 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -36,6 +36,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "crankMaths.h" #include "init.h" #include BOARD_H //Note that this is not a real file, it is defined in globals.h. +#if defined(CORE_TEENSY) + #include + FlexCAN_T4 Can0; + + static CAN_message_t outMsg; + static CAN_message_t inMsg; +#endif #ifndef UNIT_TEST // Scope guard for unit testing void setup() @@ -69,17 +76,27 @@ void loop() if (CANSerial.available() > 0) { canCommand(); } } } - #if defined(CORE_TEENSY) || defined(CORE_STM32) - else if (configPage9.enable_secondarySerial == 2) // can module enabled + #if defined(CORE_TEENSY) + //currentStatus.canin[12] = configPage9.enable_intcan; + if (configPage9.enable_intcan == 1) // use internal can module { //check local can module // if ( BIT_CHECK(LOOP_TIMER, BIT_TIMER_15HZ) or (CANbus0.available()) - // { - // CANbus0.read(rx_msg); - // } + while (Can0.read(inMsg) ) + { + Can0.read(inMsg); + //currentStatus.canin[12] = inMsg.buf[5]; + } } #endif - + + #if defined(CORE_STM32) + else if (configPage9.enable_intcan == 1) // can module enabled + { + //check local can module + } + #endif + //Displays currently disabled // if (configPage2.displayType && (mainLoopCount & 255) == 1) { updateDisplay();} @@ -140,6 +157,13 @@ void loop() { BIT_CLEAR(TIMER_mask, BIT_TIMER_15HZ); readTPS(); //TPS reading to be performed every 32 loops (any faster and it can upset the TPSdot sampling time) + #if defined(CORE_TEENSY) + if (configPage9.enable_intcan == 1) // use internal can module + { + // this is just to test the interface is sending + sendCancommand(3,(configPage9.realtime_base_address+ 0x100),currentStatus.TPS,0,0x200); + } + #endif //Check for launching/flat shift (clutch) can be done around here too previousClutchTrigger = clutchTrigger;