Hi Nordic,
In case of multiple slaves on the same spi bus, what is the best way to initialize 'spi_config' for spi_transceive() when Write device drivers using devicetree APIs by Option 1: create devices using instance numbers ?
Does SPI_CONFIG_DT_INST(inst, operation_, delay_) can be used for multiple slaves on the same spi bus? and how to select or active the specific slave when call spi_transceive()?
two slave on same spi bus:
&spi2 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <4>;
mosi-pin = <5>;
miso-pin = <6>;
cs-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>, <&gpio0 8 GPIO_ACTIVE_LOW>;
ads129xr0: ads129xr@0 {
compatible = "ti,ads129xr";
label = "ADS129xR";
reg = <0>;
status = "okay";
spi-max-frequency = <4000000>;
pwdn-gpios = <&gpio0 10 GPIO_ACTIVE_LOW>;
reset-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
drdy-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
start-gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
};
ads129xr1: ads129xr@1 {
compatible = "ti,ads129xr";
label = "ADS129xR";
reg = <1>;
status = "okay";
spi-max-frequency = <4000000>;
pwdn-gpios = <&gpio0 14 GPIO_ACTIVE_LOW>;
reset-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
drdy-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
start-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
};
};
Device instantiation macro as below:
#define ADS129XR_INST(inst) \
static struct ads129xr_data ads129xr_data_##inst = { \
/* initialize RAM values as needed, e.g.: */ \
.freq = DT_INST_PROP(inst, spi_max_frequency), \
}; \
const struct ads129xr_config ads129xr_cfg_##inst = { \
/* initialize ROM values as needed. */ \
.start_gpio_spec = GPIO_DT_SPEC_INST_GET(inst, start_gpios), \
.ready_gpio_spec = GPIO_DT_SPEC_INST_GET(inst, drdy_gpios), \
.reset_gpio_spec = GPIO_DT_SPEC_INST_GET(inst, reset_gpios), \
.pwdwn_gpio_spec = GPIO_DT_SPEC_INST_GET(inst, pwdn_gpios), \
.ledpw_gpio_spec = GPIO_DT_SPEC_INST_GET(inst, ledpw_gpios), \
.spi_cfg = SPI_CONFIG_DT_INST(inst, \
ADS129XR_SPI_OPERATION, \
0), \
}; \
DEVICE_DT_INST_DEFINE(inst, \
ads129xr_init, \
NULL, \
&ads129xr_data_##inst, \
&ads129xr_cfg_##inst, \
POST_KERNEL, \
CONFIG_SENSOR_INIT_PRIORITY, \
&ads129xr_driver_api);
/* Call the device creation macro for each instance: */
DT_INST_FOREACH_STATUS_OKAY(ADS129XR_INST);
