Wannabe CAN bus implementation - Page 1
Forum section: electronics / projects

author: aheid
author_rank: Regular Contributor
timestamp: July 16, 2020, 02:06:45 am
content: 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 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?:https://www.microchip.com/wwwproducts/en/ATA6561

author: T3sl4co1l
author_rank: Super Contributor
timestamp: July 16, 2020, 05:43:33 am
content: No need for synchronous mode, if you have full duplex just wire RXD to TXD via the interface and detect differences there.Tim

author: Jeroen3
author_rank: Super Contributor
timestamp: July 16, 2020, 06:08:14 am
content: RS-485 is electrically very similar.

author: aheid
author_rank: Regular Contributor
timestamp: July 16, 2020, 11:59:20 am
content: Quote from: T3sl4co1l on July 16, 2020, 05:43:33 amOk, so rest of scheme sounds ok then?

author: aheid
author_rank: Regular Contributor
timestamp: July 16, 2020, 12:05:02 pm
content: Quote from: Jeroen3 on July 16, 2020, 06:08:14 amI 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.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: July 16, 2020, 12:37:53 pm
content: 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

author: Elasia
author_rank: Frequent Contributor
timestamp: July 16, 2020, 12:41:21 pm
content: 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 onAlso 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

author: aheid
author_rank: Regular Contributor
timestamp: July 16, 2020, 12:53:28 pm
content: Awesome, thanks a lot for help!