Can bus v TWI/I2c

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys,

 

Just a sanity check.  I have some 16 encoders connected to an Atmega324PB with PCint's active.  Works great.  However, with TWI the master device (PI) needs to poll using TWI for any changes.  I'm thinking if I use Can Bus, the Atmega can broadcast any changes so polling is not required.  

 

Any flaws in my logic?

 

regards

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, CAN bus is a broadcast network (or possibly multicast, if you consider that nodes can implement message reception filters).

 

Clearly it needs more outboard hardware (CAN controller + CAN transceiver) but the wiring is more amenable to longer bus lengths, interference, etc.

 

You may have to rate-limit your message traffic so that nodes don't get overwhelmed. A few hundred messages/sec should be ok for 8-bit devices.

 

Edited ...

 

You could have an interrupt signal from this device to the master, prompting it to poll over I2C for changes. Much less hardware.

Last Edited: Tue. Dec 1, 2020 - 06:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be nice if someone would share a working multi-master I2C implementation, my efforts have fallen short so far, but I have certainly learned.

 

In theory, if each could master the bus, then one could set the others to return their events (sort of like a callback). What I have been trying to get working is to have a manager pass its address and command register (e.g., the first value after address, think of it as a reply port) to the device that will send events. After the event generating device knows where to send them, then bang, no more polling. Also, bus usage would be efficient.

Last Edited: Tue. Dec 1, 2020 - 07:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nikm wrote:
with TWI the master device (PI) needs to poll using TWI for any changes

Many slaves can provide some sort of interrupt signal to indicate when they have something to say...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...