Author Topic: Looking for wifi module with i2c slave port, connect to my i2c host *bare metal*  (Read 4418 times)

0 Members and 1 Guest are viewing this topic.

Offline wb0gazTopic starter

  • Frequent Contributor
  • **
  • Posts: 354
I wish to add wifi capability to a microcontroller project via i2c port (my microcontroller project has 2 pins configured as i2c master; it would connect to the wifi module's i2c slave pins.)

The catch (?) is that my project is not based on Arduino, so I don't believe I can use ESP-IDF (espressif "stack" for the ESP32-C6 module?)

Any suggestions as to how I can proceed or at least get a general direction (other than embedding my project in the Arduino ecosystem, as the project is too far along to make that effort practical) would be much appreciated.

Happy to provide any requested clarifying information.

Thanks!
 

Offline xvr

  • Frequent Contributor
  • **
  • Posts: 941
  • Country: ie
    • LinkedIn
Quote
The catch (?) is that my project is not based on Arduino, so I don't believe I can use ESP-IDF (espressif "stack" for the ESP32-C6 module?)
ESP-IDF is not based on Arduino; rather, the Arduino framework for ESP is built upon the IDF. Consequently, you can create projects using the pure IDF alone, without any involvement from Arduino.
Espressif provides plugins for working with the IDF in VS Code and Eclipse; however, the IDF can also be used without them—all you need is a compiler and the CMake build system.

The IDF also provides many examples, so you can use one of them as a base for creating your own project.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 2001
  • Country: 00
You could program any ESP with anything you'd like (such as Arduino), that handles WiFi stuff and accepts commands over I2c.
It will be slow but perhaps doable for tiny MQTT packets and such. Then the I2c master can be programmed completely independently too.

Actually I had this architecture from a 5 year old project that I picked up not too long ago. I've a RGB lamp that I wanted to control through home assistant, based on a PIC32MX250 because that was easy to program. I added a ESP32-C3 in there on I2c bus. The bus is quite busy so I'd rather keep the I2c master on the PIC32MX.

A few months ago I looked at the firmware, and just wanted to pop in here that there are two I2c slave drivers present within ESP-IDF. The old one is really back-to-front kind of thinking.. it sets up a slave but it requires blocking send/receive functions iirc. This kind of mitigates the whole point of using a slave because you're not in control when communications will start.

The newer version does include callbacks, but I think I had some problems with buffers not synchronizing properly (occasionally all bytes in the packet handlers would shift). So unfortunately in typical ESP-IDF fashion, you'll have to write more software on top of other half-working software. But I'm sure that with a bit of care it can be made to work..
 

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ua
The catch (?) is that my project is not based on Arduino, so I don't believe I can use ESP-IDF (espressif "stack" for the ESP32-C6 module?)

Confused here.
Is you MCU esp32c6, or you just considering esp32c6 as a WiFI module?

If former, you don't need i2c at all, plus it can't be baremetal since Espressif's wifi blob is linked against FreeRTOS.
If latter, then you'd need to turn esp32c6 into an AT-modem over I2C, so the esp32c6's firmware is separate from your baremetal project.

Which is which ?
Mongoose - a full-stack embedded network library for STM32, NXP and other - https://mongoose.ws
TCP/IP stack + drivers + TLS1.3 + HTTP/WebSocket/MQTT + OTA in a single file
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3590
  • Country: ca
I2C is slow and therefore is a bad choice for WiFi modules, so it'll be hard to find one. You certainly can use ESP32 to create your own module which will use I2C.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 2001
  • Country: 00
True in my project I also didn't use it to transfer complete ethernet frames, but instead, I had a MQTT client running on the ESP32 and just sent binary data on certain MQTT topics back and forth.
Though its just a matter of implementing a register space to emulate some kind of ethernet mac/phy over I2c. But 400kbit/s I2C is only 40-44kB/s so quite slow indeed..
 

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ua
True in my project I also didn't use it to transfer complete ethernet frames, but instead, I had a MQTT client running on the ESP32 and just sent binary data on certain MQTT topics back and forth.
Though its just a matter of implementing a register space to emulate some kind of ethernet mac/phy over I2c. But 400kbit/s I2C is only 40-44kB/s so quite slow indeed..

As far as I know, ESP32 does not document WiFi registers, and also does not provide low level (ethernet) access to its WiFi radio.
So it is impossible to operate on WiFi Ethernet level using their SDK.
What's possible is to use socket or higher level API (e.g. http, mqtt) and expose it via a serial link - that's what you did, apparently.
Mongoose - a full-stack embedded network library for STM32, NXP and other - https://mongoose.ws
TCP/IP stack + drivers + TLS1.3 + HTTP/WebSocket/MQTT + OTA in a single file
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 2001
  • Country: 00
I'm sorry I abused the word "register". I meant creating a memory space on I2c for controlling WiFi modes (AP, Client, etc.), controlling buffers for packets, status etc.
It doesn't have to map to real hardware to look like a register set. I'm sure that many I2c sensors or e.g. GPIO expanders chips look like having hardware registers but actually run a small ROM micro that implements a complex sequence of instructions.

In theory it is possible that the ESP32 runs an I2c slave program at a MAC level (raw ethernet frames) up to a fixed set MQTT topics like I described. The latter strips away all the MAC, IPv4/IPv6 headers, and UDP or TCP headers (along with other protocols needed, like DHCP, ARP, ICMP, etc.). Ultimately this decreases the traffic volume significantly on the I2c bus.

It may make more sense to run everything on a single ESP32 instead, but sometimes it is useful to build small projects in a modular way. In software we'd say its separation of concerns so some parts of a project is just a black box that is known to work.
 

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ua
It may make more sense to run everything on a single ESP32 instead, but sometimes it is useful to build small projects in a modular way. In software we'd say its separation of concerns so some parts of a project is just a black box that is known to work.

Agreed!

The separation makes things more testable and replaceable.
For example, one can define a simple serial interface for mqtt/pubsub: connect, publish, subscribe, with a callback: on connect, on message, on disconnect.

Then it would be very easy to test the whole functionality by plugging a test stub on the other side of the serial, instead of a real modem.
And also it would be easy to replace the modem - e.g. go from esp32 to nxp rw612. the "business logic" of a firmware won't change a bit, and is kept tested.
Mongoose - a full-stack embedded network library for STM32, NXP and other - https://mongoose.ws
TCP/IP stack + drivers + TLS1.3 + HTTP/WebSocket/MQTT + OTA in a single file
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17858
  • Country: fr
I've seen many projects actually using a ESP32 SoC as some kind of slave device for WiFi access. When you don't need to optimize for cost to the last dollar, it often makes sense especially if the team has no previous experience with the ESP32 line. They can implement the core of the device around some other MCU and just use the ESP32 for network access.

Physically separating network access from the rest is also a plus in terms of security. Additionally, developing everything on ESP32 pretty much means using the RTOS they use, which may or may not fit your use case. When people are forced to use a RTOS for no other reason than because the network stack requires it, it can be painful. So if you're switching your whole design to the ESP32, just consider exactly what it is you're getting into.


 
The following users thanked this post: tellurium

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ua
Another thing that can be done is to wire ESP32 to SWD pins (or whatever ISP pins the target MCU uses) and turn ESP32 into a remote programmer.
Suddenly you can reflash the target MCU or even debug it live.
Mongoose - a full-stack embedded network library for STM32, NXP and other - https://mongoose.ws
TCP/IP stack + drivers + TLS1.3 + HTTP/WebSocket/MQTT + OTA in a single file
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 3938
  • Country: gb
« Last Edit: November 01, 2026, 09:50:06 am by voltsandjolts »
 

Offline wb0gazTopic starter

  • Frequent Contributor
  • **
  • Posts: 354
Sorry long delay from my original post to respond...

I think the core useful comment here is that I2C is slow which reduces the potential demand for I2C->Wifi bridge peripheral, making such a thing uncommon or the product of some after-the-fact engineering (I'd want plug-and-play, while I realize ESP32 is common for it's integrated wireless peripherals, I believe it also uses bit-emulated I2C and lacks I2C slave capability...)

Although the throughput constraint of I2C would not be a concern for my application, the point is well taken.

Therefore, I am re-routing this search towards a Wifi peripheral I can connect via 2-wire async (STM32 USART) port (particularly something whose usage instruction does not begin with "recompile the kernel...!")

Thanks for the discussion, helpful!

Dave
 

Offline Kilrah

  • Supporter
  • ****
  • Posts: 2049
  • Country: ch
ESP8266s and ESP32s have been used as serial "modem" wifi adapters since they came out, was probably one of the most common uses for the original 8266. Nothing's preventing you from using I2C instead if you want.

The key is that there is no "standard" way to "make an I2C wifi adapter" so you may have to define a protocol for both to communicate. Serial typically uses the AT commands of old since well, that's what they were meant for, you could use the same just transported over I2C.
Or you could run the whole MQTT code in the ESP and just tell it what to do from the other, or you could replace the whole existing MCU with just the ESP since it can probably do all of it unless you have fancy requirements...

while I realize ESP32 is common for it's integrated wireless peripherals, I believe it also uses bit-emulated I2C and lacks I2C slave capability...)
Not at all. Varies by model but they all have hardware I2C.

These days if using an ESP as wifi modem/adapter I'd use an ESP32-C5 since that supports both 2.4 and 5GHz WiFi.
« Last Edit: November 27, 2026, 10:20:26 pm by Kilrah »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->