Sharing GPIOs between two devices

Hello,

I'm making low power device that features (mainly) a camera (OV2640 which needs 14 GPIOs to operate) and SD card. The problem is, the number of GPIOs is very limited. I don't need to use SD card and camera at the same time, so I thought I can share the SD SPI GPIOs with the camera GPIOs using analog multiplexer. This is my general idea:

  1. Power ON the camera using N-Channel MOSFET and initialize it
  2. Take a photo and save it to RAM
  3. Deinitialize and Power OFF camera using MOSFET
  4. Use 4 channel analog multiplexer (like SN74HCT257N) to redirect the GPIOs to SD card (so now MCU will be connected to SD card and part of the camera pins will be disconnected)
  5. Power ON the SD card using N-Channel MOSFET and initialize it
  6. Save the image from RAM
  7. Deinitialize and Power OFF SD card using MOSFET

My questions:

  1. Will such multiplexer provide correct isolation between the devices?
  2. How can I avoid powering the SD card via SPI pins after I cut the power with MOSFET? As I'm using N-Channel MOSFET I assume I need to set the SPI pins to output HIGH level, becasue the 3.3V will be present at the SD card (ground will be disconnected via mosfet as this is n-channel one)
  3. Wouldn't it be better to set those unused pins after SD card power off to input with pull-ups? Would it make any difference for example in term of the circuit security?
  4. Is it OK to left the second device pins floating after I switch the multiplexer channel? (The device with floating pins will be powered off at that time, however the 3.3V will be still present due to the nature of the mosfet)
  5. Are there any flaws in my concept?

Thanks for answers.

If you are switching the camera low-side, then you probably need to switch the signal lines to the
camera only after powering it up, and switch back to the SDcard before powering the camera
down. You may need some pull-ups or pull-downs on the camera lines after the multiplexer to
stop them floating after switching away from the camera.

Similarly you'll probably need some pullups or pulldowns on th SDcard after the multiplexer
to keep them from floating too.

The problem is that after point 7 on my list, both devices (camera and sd card) will be powered off, so I assume I need to set the pins to correct state, however I'm not sure if simply setting those GPIOs to low state will work (because there will be 3.3V present on the power line and I don't want to power it on via data pins by accident). I think it would be more proper to set those GPIOs high (or maybe to input mode with pull-ups?), but then I'm not sure if it's safe to keep pins in high state on powered off device.

Also do I need to stop those pins floating after switching away from the camera? Is there a problem with keeping it float even when the device is powered off?

Hi,
What model Arduino are you using?

Thanks.. Tom,... :slight_smile:

Hi,

not sure if that matters that's why I posted it in general electronics section, but I'm using ESP32 (anyway the camera and sd card works fine on separate pins for now, however as I need those pins for other devices I need to share them somehow)

Hi,
Google arduino port expander

Tom... :slight_smile:

Hi,

I'm already using port expander (SX1509) for keypad. However this is not sufficient. The camera pins need to be attached directly to esp32 as they need to communicate on really high speed using DMA

Seems a complicated way of going about 'shareing' pins.

What are these 'other devices' you need to attach ?

Its possible there is another solution.

I need to use:
I2C controlled GPIO expander (for keypad and to control other GPIOs, to turn on/off mosfets etc) - 2 pins, but those can be shared with the camera as it also uses I2C interface
4 line SPI LCD screen - 4 pins
SPI controlled SD card - 4 pins, but those can't be shared with LCD as the software implementation in esp-idf has a lot of issues when sharing the sd controller with other devices, also it would give really poor performance to lcd while the sd card is operating.
OV2640 camera - 14 pins

In the ESP32 WROVER I got no more than 20 usable pins (that aren't shared with onboard PSRAM, FLASH etc). 14+4+4 is 22.

Using all the GPIO pins is not low power. Get a 2nd ESP32 to handle some of the other stuff and have the 2 ESP32's pass their info back and forth, serial, ESPNOW, SPI, I2C, fly by night wiring scheme of your choice. I'm sure you'll use the extra pins of the 2nd ESP32.

My Hexapod uses 3 ESP32's; 1 for imaging, one to handle the servo motors, and the brain. The ESP32's communicate with the Brain that makes decisions on which direction to walk in or did it just detect a human?

I have managed on a single ESP32CAM;

OV2640 Camera
MicroSD card
GPS
LoRa device (SPI)
I2C FRAM
PCF8574 IO expander
BME280 Sensor
Battery Voltage read
ILI9341 SPI TFT display

The key to getting it all working was to offload as much as possible onto I2C, even the TFT display was driven over I2C with a Pro Mini acting as a backpack for the display in text only mode.

1 Like

Idahowalker:
Using all the GPIO pins is not low power.

What do you mean it's not low power? It's not like all the GPIOs will be used all the time, most of the time those devices will be powered off.

I thought about choosing second microcontroller, but also thought that the multiplexer thing could work

ElectronicNoob:
What do you mean it's not low power? It's not like all the GPIOs will be used all the time, most of the time those devices will be powered off.

I thought about choosing second microcontroller, but also thought that the multiplexer thing could work

Perhaps our bar of the meaning of low power differs. I'm OK with that.

Power used by a GPIO into a logic load goes with f C V^2, where f is the frequency, C is the load
capacitance, V is the supply voltage. For 100kHz and 30pF stray capacitance at 3.3V, that's 33µW,
which is tiny, and even at 4MHz its only just over 1mW.

If there's a 10k pullup that's being pulled down, that's about 1mW too.

All of this is nothing compared to the power pulled by the camera or SDcard when active, note.

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