SPI addr + data transaction

#1

Hi,
I need to control an SPI chip which requires a first byte written indicating address and read/write operation, followed by the data to be written in case of a write operation, and the chip will send the data read after this first byte for a read operation.

I understand I can handle the read operation with a half-duplex transaction (write the address, read the data: hd.tx_len = 1, hd.rx_len=data length).

Regarding the write operation, address and data are on separate spaces and CS must be kept low for the entire frame (address + data). I imagine these possibilities:

  1. Manually handle CS, perform a 1-byte write and then write the rest of the data
  2. Combine address and data together and run a single full-duplex transaction with fd.tx_len = data length + 1 and fd.rx_data=NULL

Anything simpler ? Something I’m missing ?
Regards

PS: by “separate spaces” I mean this is a low-level driver for a high-level driver and the function receives address and data as separate arguments. I can’t (shouldn’t) modify the high-level driver.

#2

Looks like similar to the way BME280 works.
Have a look here.

#3

Thx!, that example copies address and data to a temporary buffer for the write operation; looks like I’ll have to evaluate what is worse: copying 256 bytes (max data length) or manually handling CS. I guess toying with CS can be more of a problem in a system like this.
Since most operations would likely be writing to one register, I think I’ll go with this scheme. Thanks again.