The bus and the settings
An Arduino Uno R3 reads a BME280 sensor over SPI. The Uno is the controller: it makes the clock. Four wires: SCK, the clock (pin 13); MOSI, data out (11); MISO, data in (12); and chip select, CS (10).
SPISettings names three things: the top speed (1 MHz), the bit order (most significant bit first) and the mode (SPI_MODE0). beginTransaction() loads them into the Uno's SPI hardware. The BME280 datasheet allows up to 10 MHz.
One transaction
digitalWrite(CS, LOW) selects the sensor. Chip select is active low: a chip listens while its CS is LOW and ignores the bus while it is HIGH. SPI picks a chip this way, with a wire, instead of an address.
SPI.transfer(0xD0) clocks 8 bits out on MOSI, most significant first: 1101 0000. Bit 7 = 1 means read; the other 7 bits pick the register. So the byte asks for register 0xD0, the chip ID.
The sensor can only answer while the clock runs, so the Uno sends a dummy 0x00. On those same 8 clocks the sensor shifts 0110 0000 out on MISO: 0x60. Every transfer sends one byte and receives one.
digitalWrite(CS, HIGH) ends the frame; endTransaction() frees the bus for other code. id holds 0x60, the chip ID the datasheet promises, so the driver works. The clocking took 16 clocks: 16 µs at 1 MHz.
Modes
The mode says when a bit is read. CPOL is the clock's resting level; CPHA picks the edge. Mode 0: the clock rests low, bits are read on the rising edge and changed on the falling edge. The BME280 accepts modes 0 and 3.
Type SPI_MODE1 by mistake and the Uno reads on the falling edge: the instant the sensor changes the bit. Old bit or new one? It depends on nanoseconds. The analyser shows the read marks on the edges. Fix: use a mode the datasheet allows.
Chip select with two chips
Add an SD card. It shares SCK, MOSI and MISO but gets its own chip select, pin 9. setup() makes both CS pins outputs and drives them HIGH. Then only the chip whose CS is LOW drives MISO.
Forget digitalWrite(CS, HIGH) and the sensor stays selected when the SD card is called. Both chips drive MISO at once, and the bytes are garbage. On the analyser the giveaway is two CS lines LOW at the same time.
What happens
;; step 1/10 · bus controller Arduino Uno R3 (ATmega328P) peripheral BME280 breakout SCK pin 13 clock, made by the Uno MOSI pin 11 controller out, peripheral in (COPI) MISO pin 12 controller in, peripheral out (CIPO) CS pin 10 chip select, LOW = "talk to me"
The analyser view draws the two bytes back to back. On a real Uno the CPU needs a few instructions between bytes, so a short gap appears between them. 16 clocks at 1 MHz is 16 µs of clocking. MISO is drawn at half height where the sensor sends no data (nobody drives the line); a real analyser shows it floating or pulled to one level.