I need to design sensors card in altium for sensors connected I2C and SPI. When I searched modules on internet, while some used mosfet to handle high and low side others did not use mosfets. I could not understand clearly for which purpose they used mosfet. Could you help me, should I use mosfet connections for my card? To explain my question well, I added two diffirent photos for the same sensor type.
The circuit shown is a common level shifting circuit for I2C. It is used because it can translate bi-directional open-drain signals as used in I2C.
I wouldn't recommend this circuit for use with SPI, because
- SPI doesn't require bi-directional translation.
- This circuit is slow (but it's difficult or at least tedious to predict how slow). That's okay for early generation I2C that runs at 100 or 400 kHz. But it's not adequate for SPI busses that might be expected to run at 1 - 10 MHz.
For SPI I'd recommend an off-the-shelf level translator IC to get predictable output levels and propagation delays.
Even for I2C if your application can accept a few $0.10's of extra cost I'd recommend paying for an off-the-shelf I2C translator IC to get predictable performance. Some of the available chips will also give a speed boost and/or allow you to power down one side of the bus without blocking communication on the other side.
They are using the MOSFETs as level shifters. If your devices do not all use the same voltage signalling levels, you may need to use them if your signals are bi-directional.
STM32 series microcontrollers can work directly with 5V peripherals just fine, without any MOSFET or other kind of level shifter.
Check the pinout table in the datasheet for your controller. Most pins are marked as FT, meaning Five-Volt Tolerant. These pins can safely take 5V input voltage when used as inputs (e.g. as the MISO line) or as open-drain outputs (SDA and SCL lines). Although they will output only 3.3 Volts when used as push-pull outputs, most 5V parts (check the datasheet of yours) would interpret a voltage above 2 Volts as a logical high level.