Using SPI Port Question - Fanstel BT840
I wonder if this is the correct place to seek help with a problem I am seeing. I am trying to use the SPI port on a Fanstel BT840, and was hoping to use the spi_read() and spi_write() functions that are found in the header file spi.h in the directory zephyr/include/drivers/. These functions would be used to pass data between the Bluetooth and SPI ports on the Fanstel BT840. The Fanstel part has the Nordic nRF82540 as its core processor.
In my project’s main.c, I include <drivers/spi.h>. I am then able to add ‘status = spi_read(spiDev, &spiConfig, &spi_rx);’, but run into exception errors when I try to step over this function. A Nordic FAE suggested that I might be taking a wrong approach, and should instead seek out examples that make use of the SPI port. Looking through the adxl372 example he suggested, it is not obvious how to read and write from the SPI port.
Zephyr is a new and very broad field to me, so I would appreciate any pointers to get going in the right direction.
Utility Relay Company.
I am not an expert on Zephyr, in fact I am roughly in the same position as you. But I have recently solved this problem so I thought I should share. I apologise in advance if some of this is obvious to you already.
The ADXL372 example will not be useful to you, because Zephyr already has a driver for that specific device. This abstracts away the direct bus access.
The first thing you need to do is ensure that the SPI peripheral is mapped to the correct pins. You can do this in the dts file for the board, or using a dts overlay. Something like this is what I would normally use for the nrf52840:
compatible = "nordic,nrf-spi";
status = "okay";
sck-pin = <14>;
mosi-pin = <13>;
miso-pin = <15>;
cs-gpios = <&gpio0 26 GPIO_ACTIVE_LOW>;
clock-frequency = <1000000>;
Next, take a look at this example code: https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/drivers/spi_fujitsu_fram/src/main.c
There is no driver for this FRAM device, so the example does indeed use the bare API to control the SPI bus.
The main use of the raw SPI API is in the function mb85rs64v_access. Note that the Zephyr APIs use a structure-in-structure approach, where you pass a spi_buf_set which contains one or more spi_buf. If you cross-reference that code with the documentation here: https://docs.zephyrproject.org/latest/reference/peripherals/spi.html it should make more sense.
Hope this helps.