Best suited MCU for I2C Slave operation

Hello,

Its been mentioned to me that the atmega328P perhaps has some shortcomings when acting as I2C slave, or at least that it won't win any awards for its I2C Slave performance

What is the very best / most forgiving / least finicky platform to use for I2C slave operation?

Appreciate any recommendations or anecdotes

Thanks!

Maybe this tester:

I2C Tester (testonica.com)

Seriously, such questions are out-of-context and are unanswerable IMO.

Where? Post a link to that information. I don't know why the mega328 would be worse than other, comparable, processors. Of course a 16MHz mega328 processor may not have the performance of a 80MHz ESP32.

"Best" is always a subjective measure. Define what would make a best and go from there. What distinguishes best from 2nd rate in this context?

1 Like

In this thread

So I figured I'd see what people had to say

Have a look at the available interrupts and flags in I2C slave mode. There is no reasonable support for reading multiple bytes in one transmission. Reading single byte by byte is only a poor workaround, not compatible with all masters.

Also a master can not count incoming bytes from a slave, that's a know problem with the I2C protocol. This makes it hard to meter or protect I2C connections.

I'm not familiar with other processor families and can not name a better controller. Does somebody have more insight and experience with other controllers?

Tell us what the shortcomings are? That is a subjective statement. I can say candy tastes good my neighbor can say it tastes bad for the same candy. Electronics is not a one case fits all, it is always a tradeoff of one parameter for another. It is very dependent on the application.

The application is emulating RTCs and EEPROMs. which are similar, in that neither of them process data, they just give it up.

So the MCU I'm using has to mirror the performance of an I2C EEPROM as closely as possible (I2C Slave Mode)

I think this means it can't be sloppy or slow.

The ATmega328P has the best I2C Slave implementation at the moment.
There were some timing issues in the past, but those were fixed, so the ATmega328P is a reliable I2C Slave since a few years. No other Arduino board can top that.

That does not mean that it is any "good". All the notes by DrDiettrich stand, and there is so much more that can go wrong.

What is the Master ? A Arduino board ?

When a processor is turned into Slave mode, it uses both hardware and software. To run the software, it keeps the SCL low, which pauses the Master. That is called "clock pulse stretching". If the Master is also a Arduino board, then it can deal with clock pulse stretching, other devices might not be able to handle that.

The ESP32 has a different design, but that has consequences, and I'm not sure if the newest changes make a reliable I2C Slave.

I have written a few notes on emulating a I2C Slave.
Some on this forum can make it work. Some have a Master which uses a software implementation for the I2C bus which is so bad, that it is not compatible at all with the Arduino as a I2C Slave. It is a weird world that you have entered. Can you do your project without a Arduino as a I2C Slave ?

A rather senseless statement to my mind; like, dude, you mean "emulate" EEPROM IN flash?

If the little AVR microcontrollers are not cutting it for your needs, then start testing alternatives uC's on your bench; no one here can mind read your specific requirements.

Personally, I would spend some time with a beer and Internet search on STM products and I2C issues, then expand that into other manufacturers. Like, there are scores of ARM-based uC in the universe, select a unit matching your SRAM/flash needs and then shake the Internet to see if I2C issues jump out of the bushes.

IMO, you are making this way too difficult; you are supposed to be working for an engineering degree; no better time than now to walk.

STM has a compatible Arduino core and literally bunches of Dev boards: STM32duino · GitHub

Support Forum:
Arduino for STM32 - Index page (stm32duino.com)

1 Like

These are features of ATmega328P MCU and not the flaws?

So I did not follow the beer suggestion, but I did get margarita. I have some Teensy 4.0 on order to try

The reason I need to emulate EEPROM is 2 fold

1.) be able to configure any slave I2C address. Most EEPROM have only a few addresses to choose from using address pins

2.) be able to change data on the fly, without in circuit or out of circuit EEPROM programming

I guess I ideally need something fast enough that I can entirely avoid clock stretching

I think this is possible, as I am only dealing with about 64 bytes of data at a time

I once tried to do an i2c sniffer using ESP8266 and it failed because it sometimes missed clock flanks. It is an 80MHz mcu and I disabled WiFi.

Project was an XYZ 3D printer that used nfc to make sure people used original expensive pla.

On my wish-list is a simple circuit that can act as a clock stretcher, then any slow mcu will do.

The bus master must obey the supported bus clock frequency. Typical limit is 400 kHz. A master running free above the given limit is crap.

If your master does not obey the given bus speed it also may ignore clock stretching.

At 400kHz, there is very little time to detect that clk is low in software, so it sometimes missed to do so. A hardware latch on clk would help by giving sw almost unlimited time to react.
Is this functionality built into mcu's with hardware i2c? Or is clock-stretching made in sw?

IMO a bad idea. If the code can determine the right time to pull SCL low, then it also had time to read or write the transmission registers and proceed without clock stretching. Once missed the time where it should pull SCL low means a broken transmission.

A slave can pull SCL low after all bits of a byte have been received, and release it again when the controller has read the receiver register. On a read request the SCL can be set low on the start condition, until the output register has been written.

I made a page about I2C Sniffers: https://github.com/Testato/SoftwareWire/wiki/I2C-Sniffers

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.