Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN-BUS #87

Open
dufi2profor opened this issue Jul 11, 2020 · 10 comments
Open

CAN-BUS #87

dufi2profor opened this issue Jul 11, 2020 · 10 comments

Comments

@dufi2profor
Copy link

Hello,

i plan to use Teensy 4.0 as an gateway between two devices in my car.
I would like to ask, if You plan to implement CAN bus RX pin as an wake pin, or should i use digital pin driver?

Thank You

@david-res
Copy link

Try to use digital.pinMode(23, INPUT, RISING); on your Rx pin (I use CAN1 on the T4)
This will work only in hibernate mode. Otherwise, you will need to reinitialise your CAN library upon wakeup from sleep or deepsleep mode.

Give that a try and report back.

@dufi2profor
Copy link
Author

david, thanks. I am waking Teensy by ERR output from TJA1055. That pin indicates start of frame on bus.
My sketch is based on bi directional forward example of FlexCAN library for T4.
Whenever valid message is received on "car" side, i preload one variable, that decrements every millisecond. Then, when car goes to sleep, the variable gets to zero, but before it does, i put all three TJA1055 to sleep and then, i call Snooze.deepSleep(config_teensy40).
config_teensy40 has digital and usb loaded.
When "car side" TJA1055 indicates begin of transmission by pulling its ERR pin down, Teensy wakes up, enables all three TJA1055 and starts forwarding.
But sometimes Teensy gets frozen, in various times after wake up. It never freezes when You power it up. But only after wake.
The same happens sporadically when i configure additional pin and put button to it. Teensy wakes up and then freezes. Only way to get it run is to unplug power and plug it back again.
Need to say that even when Teensy runs as it should, means does not freeze, when i press the button, it freezes at that moment.

I have used MsTimer2, which is ISR based to flash LED to see, if, when Teensy freezes, my program is not stuck somewhere. Both MsTimer2 stops.

By the way, when i tried hibernate sketch hibernate_all_wakeups, i am not able to wake the Teensy. So that is why i did not try hibernate, but deepSleep.

PSA_GW_NAC_08A.txt

@duff2013
Copy link
Owner

I'm a bit behind in these issues as of late, (kids school things). I'm hoping to get back to Snooze soon and I'll be taking a look at this.

@dufi2profor
Copy link
Author

Many thanks. Maybe if i call detachInterrupt on those two pins, it might help. Then reattach it before entering sleep.

@dufi2profor
Copy link
Author

I am using Arduino 1.8.9 and Teensyduino 1.5.3

@dufi2profor
Copy link
Author

dufi2profor commented Jul 20, 2020

Seems like this approach helped:

digital.pinMode(TJA_MASTER_ERR, INPUT, FALLING);
digital.pinMode(IN_DEBUG, INPUT_PULLUP, FALLING);
Snooze.deepSleep(config_teensy40);
detachInterrupt(digitalPinToInterrupt(TJA_MASTER_ERR));
detachInterrupt(digitalPinToInterrupt(IN_DEBUG));

@david-res
Copy link

@dufi2profor I'm using the TI SN65HVD230, but I just had a look at the TJA1005 and it looks interesting - do you mind sharing a schematic of how you have it connected to the T4 with the wakeup and sleep functions?

@dufi2profor
Copy link
Author

Sure, i will draw the schema in KiCad and share then.
I have been using in past MCP2551, but that one, as part of high speed can group, has different recessive and dominant states.
As a result i found the output on RX pin inverted. Looked strange to me and then i looked in my radio (Peugeot 3008) and found this TJA1055. Low speed, fault tolerant. But different idle and dominant states.

I would not use control of sleep functions on those transcievers if i did not want the lowest current as possible and when all three TJAs are "sleeping", it makes current drop by at least 3 mA in total,

So my current setup, when using deepSleep draws 5 mA, which is okay in car i think.

@david-res
Copy link

Actually, I just saw the 1055 limited to 125Kb/s baud rate, I'll stick with the SN65HVD230 in this case as I need 500Kb/s.
I put the 230 into sleep mode by default and pull the mode pin low when the Teensy is awake to bring it to life. I haven't measured consumption, but I'm hoping for 3-1mA if not less in Hibernate mode.

@dufi2profor
Copy link
Author

Yes, that is the only drawback of TJA, but i need it for my infotainment project in my Peugeot. Had been using that MCP2551, but only as listen only mode on my Peugeot "body" can which is running at 500 Kb/s.

Here is schematic diagram of what i have on breadboard now.

SCH_CAN_ISOL_T4.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants