SPI write function

Hello, I’m using SPI interface between ESP32-S3 and DWM1000, which is a UWB module. What I want to do is to write a value into the register of DWM1000. DWM1000 is SPI slave. Here’s my code.

id(spi_dwm1000).enable();
uint8_t MTXFRS[4] = {0x80, 0x00, 0x00, 0x00};
id(spi_dwm1000).write_byte(0x8E);
id(spi_dwm1000).write_array(MTXFRS, 4);

id(spi_dwm1000).write_byte(0x0E);
id(spi_dwm1000).read_array(MTXFRS, 4);
ESP_LOGD(“SPI”, “CHAN_CTRL: 0x%02X%02X%02X%02X”, MTXFRS[3], MTXFRS[2], MTXFRS[1], MTXFRS[0]);

I checked the register value but it wasn’t what I wrote.
I’m writing a value into the register 0x0E. In order to write to DWM1000, MSB is needed to be 1 so I wrote 0x8E.
Anyone knows about this problem, please help me.

Always a good idea to read the datasheet. An SPI transaction starts with /CS being asserted and ends with it being deasserted. Your code above calls enable() but never calls disable() so the chip treats your read attempt as being a continuation of the write. The extra bytes might be ignored, or they might overwrite other registers. You need to call disable() after the write, and surround the read with enable()/disable()

There may be other issues, but that’s one.