Skip to content

MAX3421E: reduce default SPI freq to 20 MHz to accomodate granularity on ESP32#11078

Closed
dhalbert wants to merge 2 commits into
adafruit:mainfrom
dhalbert:MAX3421E-frequency
Closed

MAX3421E: reduce default SPI freq to 20 MHz to accomodate granularity on ESP32#11078
dhalbert wants to merge 2 commits into
adafruit:mainfrom
dhalbert:MAX3421E-frequency

Conversation

@dhalbert

Copy link
Copy Markdown
Collaborator

The problem here is that the default SPI frequency for the MAX3421E is 24 MHz. However, the SPI frequency ("baudrate") has different granularity on different Espressif chips. On ESP32-C6, 24 MHz is actually 20 MHz. On ESP32, 24 MHz is actually ~26.67 MHz (26.666...). On ESP32-S2, it's also 26.67 MHz.

The max spec of the MAX3421E is 26 MHz, so it's at the hairy edge. On S2 it works some of the time, but not ESP32; I'm not sure why. but in any case, it's too high.

20 MHz is OK on all, so I've changed the default from 24 MHz to 20 MHz, and documented this. I re-tested on ESP32 and other chips.

Also fixed a tiny typo in espressif/mpconfigport.mk.

Claude Code was helpful on this. It started out on incorrect theories, but was good at instrumenting whether the MAX3421E setup was working or not. It suggested lower baudrates as a test at one point, and that set me on a quest of which baud rates actually worked. I then discovered the different quantization of the baudrates.

This raises a long-term issue of whether SPI clock rates (and similar) should round down or not. I'll open an issue about that.

@dhalbert dhalbert requested a review from tannewt June 29, 2026 16:41
@deshipu

deshipu commented Jun 29, 2026

Copy link
Copy Markdown

If I remember correctly, the actual baudrate set should be the highest possible that is lower than the requested baudrate, so that you can always request the maxium badurate supported by the device you are trying to communicate with. This seems to be a bug in the baudrate setting code, not in the driver.

@dhalbert

Copy link
Copy Markdown
Collaborator Author

@deshipu says:

If I remember correctly, the actual baudrate set should be the highest possible that is lower than the requested baudrate, so that you can always request the maxium badurate supported by the device you are trying to communicate with. This seems to be a bug in the baudrate setting code, not in the driver.

We discussed this internally and agree the baudrate should be a ceiling. The current documentation (from 2018) says:

  • baudrate (int) – the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the frequency attribute for the actual clock rate.

As you correctly point out, this is a bad idea. We'll fix this. On some boards, like nRF528xx, it is already a ceiling.

@dhalbert

Copy link
Copy Markdown
Collaborator Author

So I will make this a draft since the better fix to fix the SPI baudrate semantics.

@dhalbert dhalbert marked this pull request as draft June 29, 2026 18:12
@mikeysklar

mikeysklar commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

SPI @ 20 MHz definitely helps the Feather V2 <-> MAX3241E. That was a key finding you worked out.

I am experiencing two other issues that are causing instability with the MAX3241E.

  • OSCOK timeout (TinyUSB hcd_init() )
  • SPI dead lock - switch to single thread polling

I can submit a separate patch for these two. Still testing...

@dhalbert

Copy link
Copy Markdown
Collaborator Author

This is going to be superseded by #11081, assuming that is merged.

@dhalbert

dhalbert commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #11081, which is a more general solution.

@dhalbert dhalbert closed this Jul 1, 2026
@dhalbert dhalbert deleted the MAX3421E-frequency branch July 1, 2026 02:36
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

Successfully merging this pull request may close these issues.

Feather ESP32-V2 and MAX3421 Featherwing

3 participants