I'm unable to get SPI to work on my nRF5340DK board. I can see activity on MOSI and SCK pins, but not on CS. The pin is not even initialized and is floating.
My overlay file
&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
cs-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
sck-pin = <6>;
mosi-pin = <5>;
miso-pin = <4>;
spi-device@0 {
status = "okay";
reg = <0>;
spi-max-frequency = <12000000>;
label = "test";
};
};
And my source code:
#define SPIDEV DT_NODELABEL(spi1)
void main(void)
{
const struct device *spi = device_get_binding(DT_LABEL(SPIDEV));
if (!spi) {
printf("Failed to open spi\n");
return;
} else {
if (!device_is_ready(spi)) {
printf("SPI not read\n");
return;
}
printf("SPI ready\n");
}
uint8_t tx_buffer[4] = { 0x55, 0x55, 0x55, 0x55 };
uint8_t rx_buffer[4] = { 0 };
const struct spi_buf tx_buf = { .buf = tx_buffer, .len = sizeof(tx_buffer) };
const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 };
const struct spi_buf rx_buf = { .buf = rx_buffer, .len = sizeof(rx_buffer) };
const struct spi_buf_set rx = { .buffers = &rx_buf, .count = 1 };
struct spi_config spi_cfg = { 0 };
spi_cfg.operation = SPI_WORD_SET(8);
spi_cfg.frequency = 500 * 1000;
spi_cfg.slave = 0;
spi_cfg.cs = NULL;
while (!spi_transceive(spi, &spi_cfg, &tx, &rx)) {
k_msleep(50);
}
printf("SPI failed\n");
}