I'm currently struggling interfacing an SPI device using just 3 pins (CLK, DATA, NSS).

Wiring up? Connecting MOSI/MISO together?

How do i read since it's half duplex?

In ESP32 there are flags which can be set (SPI_TRANS_USE_RXDATA, SPI_TRANS_USE_TXDATA). How can i accomplish this in the Arduino environment? i didn't see a such option and the API seems a little bit limited.

Thanks for any advice.

1 Answer 1


All you need is a single resistor.


simulate this circuit – Schematic created using CircuitLab

When DATA is an input the data from MOSI passes through the resistor to both DATA and MISO. When DATA is an output the data from DATA goes to MISO and voltage is dropped safely across R1 to the sink or source of MOSI depending on what state it is in.

In other words, when DATA is input it receives from MOSI. When DATA is output MOSI is ignored.

Code wise, it's no different to any other transfer. You just never have any valid data to transfer while receiving. So just transfer anything (0xFF is a common choice).

For example, if you need to send 0x38 first then receive two bytes, you would:

uint8_t byte1 = SPI.transfer(0xFF);
uint8_t byte2 = SPI.transfer(0xFF);
  • Thanks, worked great! +1
    – elebb
    Commented Jun 6, 2019 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.