Author Topic: Wannabe CAN bus implementation  (Read 886 times)

0 Members and 1 Guest are viewing this topic.

Offline aheidTopic starter

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Wannabe CAN bus implementation
« on: July 16, 2020, 02:06:45 am »
My STM32G031 does not have a CAN peripheral. However I'm not that interested in the CAN protocol itself, but the CAN physical layer suits my project nicely.

So I was thinking, its USART does have a synchronous mode where it samples RX when it sends data on TX, ala SPI.

Could this be used along with a CAN transceiver like this[1] to implement a CAN-ish bus between my own devices, or am I missing something?

The idea being that when transmitting, to use the synchronous mode to read back from the transceiver what is on the CAN lines and then compare with what was sent. If different, do some collision handling ala Ethernet or something. In my project each sender would have a unique ID/address which could be transmitted to ensure no two nodes starts transmissions the same way.

To receive data, I imagine regular async UART mode could be used.

Is my late night idea dumb or not?

[1]: https://www.microchip.com/wwwproducts/en/ATA6561
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22436
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Wannabe CAN bus implementation
« Reply #1 on: July 16, 2020, 05:43:33 am »
No need for synchronous mode, if you have full duplex just wire RXD to TXD via the interface and detect differences there. :)

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: aheid

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4209
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Wannabe CAN bus implementation
« Reply #2 on: July 16, 2020, 06:08:14 am »
RS-485 is electrically very similar.
 

Offline aheidTopic starter

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Wannabe CAN bus implementation
« Reply #3 on: July 16, 2020, 11:59:20 am »
No need for synchronous mode, if you have full duplex just wire RXD to TXD via the interface and detect differences there. :)

 :palm:  :-DD

Ok, so rest of scheme sounds ok then?
 

Offline aheidTopic starter

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Wannabe CAN bus implementation
« Reply #4 on: July 16, 2020, 12:05:02 pm »
RS-485 is electrically very similar.
I considered this, but from what I could see, the RS-485 drivers were not nearly as robust against transients, common mode voltage etc. And the CAN bus drivers were cheaper as well, at least for lowish numbers on DigiKey.
 

Offline T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 22436
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Wannabe CAN bus implementation
« Reply #5 on: July 16, 2020, 12:37:53 pm »
Yeah, scheme sounds roughly okay. Difficulties are, you'll need to keep a buffer of the previous sent byte(s) to compare, the comparison is bitwise-logical (so there's not much data to obtain from it either -- not that there's much purpose besides "hey, this is wrong"), and... well, all the other protocol overhead that CAN involves, really.

Supposedly, CAN was developed using RS-485 drivers and support components, so their similarities are no accident.

I'm not entirely convinced CAN drivers are much or any more robust than RS-485, but it depends which ones you're looking at.  A few CAN drivers are rated to survive huge overload conditions, like 70V (with transmitter off).  CAN specifies a wider CM range, but I think it's also not required to necessarily receive or drive valid bits under that condition?  So the +12/-7V range of RS-485 really isn't too big a deal.

If you need high CM range or rejection, you'll be much better off with a different standard, anyway.  Trying to force-fit something, it can be made to work, but really just isn't suitable for it, you'll end up spending a lot of time making it work.  Consider adding galvanic isolation (optos, transformer coupling), or even using fiber optics.

Note that RS-485 can be isolated fairly easily, using Ethernet transformers, a fairly high baud rate (say 1-10MHz), and Manchester encoding either by XORing with the bit clock (synchronous) or by formatting bytes into pairs of encoded nibbles (asynchronous -- you may not be able to suppress the USART's start/stop bits in the middle of those two nibbles, so adjust accordingly).  Some kind of DC-balanced line coding is necessary to use coupling transformers; Manchester happens to be the simplest way to ensure that.

Tim
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: 2N3055, aheid

Offline Elasia

  • Frequent Contributor
  • **
  • Posts: 726
  • Country: us
Re: Wannabe CAN bus implementation
« Reply #6 on: July 16, 2020, 12:41:21 pm »
Can confirm this scheme works... just take the rx and tx lines and connect them straight to the can chip.. have 10s of thousands of product in the field this works just fine on

Also fun tid bit... I actually have both a uart and a can module inside a pic electrically connected to the same tx lines and rx lines and can do auto detect of what its hooked up to.. weather it be uart protocol or can 2.0
« Last Edit: July 16, 2020, 12:42:53 pm by Elasia »
 
The following users thanked this post: 2N3055, aheid

Offline aheidTopic starter

  • Regular Contributor
  • *
  • Posts: 245
  • Country: no
Re: Wannabe CAN bus implementation
« Reply #7 on: July 16, 2020, 12:53:28 pm »
Awesome, thanks a lot for help!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf