How to use Arduino in SPI 3-wire ?

When SPI were used in 4-wire mode, one should write dummy bytes in MOSI as it receiving bytes in MISO, how about 3-wire mode?

That depends on the configuration and which end of the bus the device is. Check this link, it should explain what you need to know.
Introduction to SPI Interface | Analog Devices Then there is this one: Interfacing a DS1868 3-Wire Device to a SPI Bus | Analog Devices

Please, mention the types of Arduino and slave device.

Arduino UNO + ADXL345

I read these 2, they didn't give code details.

1. Are you using raw sensor (Fig-1) or a breakout board (Fig-2). If using breakout board, please post the picture as there are varieties of breakout boards.

ADXL345RawChip
Figure-1:

image
Figure-2:

2. Why do you want to use 3-Wire SPI Port when there are enough pins for the UNO to handle 4-WIre SPI?

Can you please answer to my Question-1 of post #6. It is importaant for me to guide you.

I used a breakout board:


It's circuit diagram:

1 Like

1. The schematic does not agree with the signal signatures of your board. Please, show your connection like this:

ADXL345      UNO
5V           5V
3V3          where?
GND          GND
VS           where?
CS           where?
IN1          where?
IN2          where?
SDO          where?
SDA          where?

2. Are you using a Library for the operation of ADXL345? If yes, mention the name of the Library.

3. Please, post the codes/sketch that you have tried.

Surprise you never mentioned you wanted code which you will find in examples under the IDE files menu.

1 Like

Notice that OP is not responding to post #10. I am in doubt if he has the gadgets or he is just simulating.

You two didn't understand my question, I want to know the difference in code reading and writing between spi 4-wire mode and 3-wire mode.

Do you have breakout board and UNO? If yes, I will provide you now to do the functional check of the sensor/breakout board using I2C Bus. After that it will be your task to operate the board:
1. Using 4-Wire SPI Port
2. Usin 3-Wire SPI Port.

The board has both IIC and SPI interface, I have used IIC mode, now I want to use SPI, and its default mode is SPI 3-wire. I want you guide me in writing code for reading and writing in SPI 3-wire mode.

Let me know the I2C Slave address of your sensor and the x, y, z components of g that you have got. Is the breakout board a 3.3V device or 5V device?

@MianQi
You can't do the ADXL345 3 wire SPI on an Uno using hardware SPI.

No it's 4 wire

Why not?

The data sheets clearly says that storing HIGH (1) into bit-6 of DATA_FORMAT register puts the sensor into 3-Wire SPI Mode. Now, the user has to wrie codes to chnage the directions of SDIO Line (SDA on Breakout Board) as input/output when necessary.
ADXL345.pdf (481.8 KB)

The sensor supports 4-WIre SPI, 3-Wire SPI, and I2C. There is no default mode as the value of SPI-bit in the DATA_FORMAT Register is unspecified. The concern is the Breakout Board to see how have they configured the sensor pins (Figure of post #9).

I would say that the default mode is I2C. You just connect the SDA/SCL pins of the breakout board with SDA/A4 and SCL/A5 lines of UNO. The board just works on Wire.h based sketch of IDE Example.
sensortest-1.ino (4.4 KB)

1 Like