Another fork of FlexCAN

I was trying to figure out the version of TD after I had installed it and hunting around I found this file that kinda looked like it might be:

/Applications/Arduino-1.8.2.app/Contents/Java/hardware/teensy/avr/platform.txt

# http://www.pjrc.com/teensy/teensyduino.html
name=Teensyduino
version=1.6.7
rewriting=disabled​

I guess that's just one of the many Arduino version numbers - can you tell me how to determine the version of TD after it has been installed?

I think my next step is to try it on the T3.6 and get to a "known good" milestone and then work backwards until the T3.1 works again.

I'm sure there will be a simple explanation - just need to find it... ;)

Regards

Alex Shepherd
 
platform.txt is not the right place (the version number there is junk).

The build output has the version (IDE Preferences / 'Show verbose output during compilation'):
...
Compiling library "FlexCAN"
".../arduino-1.8.2-TD1.36/hardware.teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=136 -DARDUINO=10802 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I.../arduino-1.8.2-TD1.36/hardware/teensy/avr/cores/teensy3" "-I.../arduino-1.8.2-TD1.36/hardware/teensy/avr/libraries/FlexCAN" ".../arduino-1.8.2-TD1.36/hardware/teensy/avr/libraries/FlexCAN/FlexCAN.cpp" -o "/tmp/arduino_build_986471/libraries/FlexCAN/FlexCAN.cpp.o"

and can tell if FlexCAN is picked up from the right location (or possibly from somewhere else).
 
platform.txt is not the right place (the version number there is junk).

The build output has the version (IDE Preferences / 'Show verbose output during compilation'):
...
Compiling library "FlexCAN"
".../arduino-1.8.2-TD1.36/hardware.teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -fsingle-precision-constant -D__MK20DX256__ -DTEENSYDUINO=136 -DARDUINO=10802 -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-I.../arduino-1.8.2-TD1.36/hardware/teensy/avr/cores/teensy3" "-I.../arduino-1.8.2-TD1.36/hardware/teensy/avr/libraries/FlexCAN" ".../arduino-1.8.2-TD1.36/hardware/teensy/avr/libraries/FlexCAN/FlexCAN.cpp" -o "/tmp/arduino_build_986471/libraries/FlexCAN/FlexCAN.cpp.o"

and can tell if FlexCAN is picked up from the right location (or possibly from somewhere else).

Ok, got-it! I can confirm: -DTEENSYDUINO=136 so that part is ok then.

I'll confirm the behaviour on the T3.6 next.

Thanks for your help

Alex
 
So i have started to play with this again and i have set up a successful bus using and Arduino with a CAN shield, and a Kvaser Leaf. Im attempting to connect the Teensy and i get ZERO out of it. Can someone confirm that this basic sketch SHOULD send a single message per second at 500K:

#include <FlexCAN.h>

static CAN_message_t rxmsg, txmsg;

void setup() {
Can0.begin(500000);
Serial.begin(115200);
delay(1000);
Serial.println("Hello Teensy 3.6 CAN Test.");
txmsg.id = 0xa5;
txmsg.ext = 0;
txmsg.len = 2;
txmsg.timeout = 0;
txmsg.buf[0] = 0x01;
txmsg.buf[1] = 0x02;
txmsg.buf[2] = 0x03;
txmsg.buf[3] = 0x04;
txmsg.buf[4] = 0x05;
txmsg.buf[5] = 0x06;
txmsg.buf[6] = 0x07;
txmsg.buf[7] = 0x08;
}
void loop() {
Can0.write(txmsg);
delay(1000);
}



And that this one SHOULD receive a message sent at 500K:

#include <FlexCAN.h>

static CAN_message_t rxmsg, txmsg;

void setup() {
Can0.begin(500000);
Serial.begin(115200);
delay(1000);
Serial.println("Hello Teensy 3.6 CAN Test.");
}
void loop() {
if (Can0.available()) {
Can0.read(rxmsg);
Serial.print("ID ");
Serial.print(rxmsg.id, HEX);
Serial.print(" Data ");
Serial.print(rxmsg.buf[0], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[1], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[2], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[3], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[4], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[5], HEX);
Serial.print(" , ");
Serial.print(rxmsg.buf[6], HEX);
Serial.print(" , ");
Serial.println(rxmsg.buf[7], HEX);
}
}
 
@TurboStreetCar:
The code from #105 works here (FlexCAN from TD 1.36).

@kiwi64ajs:
Can you post the compiled .elf and .hex? It's in the sketch build directory. The forum allows attachments, if you go to the advanced post view. You need to put the .hex and .elf into a .zip file, the forum doesn't allow raw .hex / .elf files.
 
@TurboStreetCar:
The code from #105 works here (FlexCAN from TD 1.36).

@kiwi64ajs:
Can you post the compiled .elf and .hex? It's in the sketch build directory. The forum allows attachments, if you go to the advanced post view. You need to put the .hex and .elf into a .zip file, the forum doesn't allow raw .hex / .elf files.

Ok I
- copied the build output into a file "Build-Output.txt" in the sketch folder
- copied the whole build folder into the sketch folder
- ZIPped the Sketch folder including the build folders - so you have everything

Thanks for looking into this

Alex
 

Attachments

  • CANtest-with-V1-using-FlexCAN.zip
    669.6 KB · Views: 681
@kiwi64ajs:
Your attachment from #109 works here (Teensy 3.2).

Hmmm... well that is wierd.

Well the 3.1 and 3.2 have the same chips and I've proven that my hardware works ok with the other library - it must be something else.

So I'm now guessing that the CAN bus timing must be different in terms of where the bit sampling and the other configurable CAN bit-timing settings are concerned.

I'll have to take a look in the morning and try and find that. The other nodes on my CAN Bus are AVR AT90CAN128 based as well as a MCP2515 so maybe they have some incompatible bit-timings.

Alex
 
Thanks! What exactly is TD 1.36? I assume thats the version of the FlexCan library? How do i know what version i have?

Verified im using 1.36.

I have managed to get the code to receive and print a message from the bus to the serial monitor.

The issue im still having is it will not transmit or ACK a message put into the bus. So I need to have a minimum of three devices on the bus including the Teensy, or else there will be no ACK and I get error frames. The other two devices create a successful transmission and ACK keeping the bus error free and the Teensy can listen in and grab the messages.

Is the ACK something handled in the code and library by the Teensy? Or should the TI transceiver handle that on its own with no input needed from the teensy?
 
So, I had been using the previous version of ColinK's Flexcan very successfully. There was a push done 4 days ago which I just grabbed, assuming that nothing major would break.

I was wrong.

Code:
[B]#include "FlexCAN_Latest\FlexCAN_Library\FlexCAN.h"[/B]
...
What are you doing? Your sketch is using the latest header, but from the link error messages it's clear that you have an old FlexCAN version around that gets compiled.
 
I don't believe I did. I've pretty much stick to just the read, write, and available commands. Is this something that is set once and continues for future use?
 
I don't believe I did. I've pretty much stick to just the read, write, and available commands. Is this something that is set once and continues for future use?
It is configured at runtime and not persistent. The FlexCAN default is to not use listen only mode and acknowledge (it works for me).

It sounds like the transmitter of your CAN transceiver isn't working (or you didn't connect the Teensy TX pin properly).
 
What are you doing? Your sketch is using the latest header, but from the link error messages it's clear that you have an old FlexCAN version around that gets compiled.

You are probably right. The project is so large, Rather than changing every header include directive, I should probably update my test server, QA the changes, then push into my prod server.

Terribly sorry about that post. It was late, I was frustrated, and I probably didn't perform due diligence.

Thanks for pointing that out. I'll go back and make the necessary changes.
 
It is configured at runtime and not persistent. The FlexCAN default is to not use listen only mode and acknowledge (it works for me).

It sounds like the transmitter of your CAN transceiver isn't working (or you didn't connect the Teensy TX pin properly).

Yes it sounds very possible, just strange that BOTH of the transceivers i have, don't work.
 
TNI: Think you could double check my receive code from post #105 and see if it properly sends an ACK?
I did. Testing ACKs happens automatically. If the receiver can't send an ACK (it monitors the bus for it's own transmission), the receiver will discard the message.

If I disconnect the receiver TX, the receiver won't receive anything and the sender keeps retrying sending the message indefinitely.
 
I did. Testing ACKs happens automatically. If the receiver can't send an ACK (it monitors the bus for it's own transmission), the receiver will discard the message.

If I disconnect the receiver TX, the receiver won't receive anything and the sender keeps retrying sending the message indefinitely.

Well, the new transceivers came in, and it now successfully communicates both ways! Super pumped, thanks for all the help!
 
Hi guys, I've been having some trouble setting a filter. I'm sure it's something simple, but I feel like I have tried everything that I can think of and don't really know what else to try.

I am trying to listen for a single address, take bytes [4] and [5], and output that value on teensy's DAC. My problem is that no matter what I try, the filter doesn't take, and I am receiving addresses that should be filtered out.

I can get it to work if I manually include an if (frame.id == 0x70) inside frameHandler, but that kinda defeats the purpose.

Here is my setup:

Teensy 3.2 with MCP2561 transceiver
IntrepidCS ValueCAN3 set up to output the following messages:

Every 5ms:

ID: 0x70 ***this is the one I would like to filter for***
bytes[0][1]: incrementing counter
bytes[2][3]: 0xDEAD
bytes[4][5]: uint16_t sine wave of ~2.5Hz ***the value of interest***
bytes[6][7]: 0xBEEF

Every 50ms:

ID: 0x110
byte[0]: incrementing counter
byte[1]: 20
byte[2]: 30
byte[3]: 40
bytes[4][5][6][7]: 0xDEADBEEF

Software:

Ubuntu 16.04.2
Arduino 1.8.2
Teensyduino 1.36
FlexCAN library from CollinK's github (also tried the version that came with TD 1.36 but that didn't make a difference)

Code:
#include <FlexCAN.h>

uint16_t raw;

class ExampleClass : public CANListener 
{
public:
   bool frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller); //overrides the parent version so we can actually do something
   //void gotFrame(CAN_message_t &frame, int mailbox); //overrides the parent version so we can actually do something
};

//void ExampleClass::gotFrame(CAN_message_t &frame, int mailbox)
bool ExampleClass::frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller)
{
  
    raw = 0;
    raw |= frame.buf[5] << 8;
    raw |= frame.buf[4];
    analogWrite(A14,raw);
  
  return true;
}

ExampleClass exampleClass;

// -------------------------------------------------------------
void setup(void)
{
  delay(1000);
  Serial.println(F("CAN variable to Analog Out"));
  
  //turn LED on
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  analogWriteResolution(16);

  CAN_filter_t filter;
  filter.id = 0x70;
  filter.flags.extended = 0;
  filter.flags.remote = 0;
  
  Can0.begin(1000000);
  //Can0.begin(1000000,filter);
  
  Can0.attachObj(&exampleClass);

  for (uint8_t filterNum=0; filterNum<16; filterNum++)
  {
    Can0.setFilter(filter,filterNum);
  }

  for (uint8_t filterNum=0; filterNum<16; filterNum++)
  {
    exampleClass.attachMBHandler(filterNum);
  }

  //exampleClass.attachGeneralHandler();
  //exampleClass.detachGeneralHandler();
}


// -------------------------------------------------------------
void loop(void)
{
  /*  
  float eval = (raw - 32768) * 0.0001274;
  Serial.print("Value: ");
  Serial.print(eval);
  Serial.write('\r');
  Serial.write('\n');
  delay(100);
  */
}

In the attached scope screenshot, you can see that bytes[4][5] from 0x110 are being read when they shouldn't be. Help?
 

Attachments

  • NewFile1.png
    NewFile1.png
    48.1 KB · Views: 173
Some additional info...I added the following to the end of setup() to make sure the mailboxes were successfully getting a filter set.

Code:
CAN_filter_t setfilter;

for(uint8_t num=0; num<16; num++)
{
  if(Can0.getFilter(setfilter,num))
  {
    Serial.print("MB ");
    Serial.print(num);
    Serial.print(": ID: ");
    Serial.print(setfilter.id,HEX);
    Serial.write('\r');
    Serial.write('\n');
  }
}

The resulting serial window output:
Code:
CAN variable to Analog Out
MB 0: ID: 70
MB 1: ID: 70
MB 2: ID: 70
MB 3: ID: 70
MB 4: ID: 70
MB 5: ID: 70
MB 6: ID: 70
MB 7: ID: 70
MB 8: ID: 70
MB 9: ID: 70
MB 10: ID: 70
MB 11: ID: 70
MB 12: ID: 70
MB 13: ID: 70

So it looks as if mailboxes 0 through 13 are correctly getting filters set but not 14 and 15. This seems to be proper behavior since 14 and 15 are reserved for TX only, but it is still reading data from 0x110.
 
Back
Top