Hi nRF support team,
By using the nRF Connect SDK, I am trying to implement an SPI communication with the display module from my nRF52840 dev kit and nRF52840 as a master.
I have tried below test code. But I m not receiving invalid data on MOSI pin and also not receiving a proper clock signal.
Can you please share the working sample code of SPI as a master of nRFconnect SDK?
This is my .overlay configuration:
&spi3 {
status = "okay";
cs-gpios = <&gpio0 12 0>;
stxxxx@0 {
compatible = "sitronix,stxxxx";
label = "STxxxx";
spi-max-frequency = <2000000>;
reg = <0>;
};
};
nRFsdk Pin configuration:
CS <-> P0.12
CLK <-> P1.15
MISO <-> P1.14
MOSI <-> P1.13
Test Code:
struct device *spi_dev;
struct spi_cs_control spi_cs;
const struct spi_config spi_cfg = {
.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
SPI_MODE_CPOL | SPI_MODE_CPHA,
.frequency = 2000000,
//.slave = 0,
};
static void spi_init(void)
{
spi_cs.gpio_dev = device_get_binding("STxxxx");
spi_cs.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
spi_cs.delay = 0;
spi_cs.gpio_dt_flags = GPIO_ACTIVE_LOW;
//spi_cfg.cs = &spi_cs;
printk("SPI Initiating...");
spi_dev = device_get_binding("STxxxx");
if (spi_dev == NULL) {
printk("\n******* Display device not found. Aborting test. *******\n");
return;
}
}
void spi_send(struct device *spi_dev)
{
int err;
static uint8_t tx_buffer[1];
static uint8_t rx_buffer[1];
const struct spi_buf tx_buf = {
.buf = tx_buffer,
.len = sizeof(tx_buffer)
};
const struct spi_buf_set tx = {
.buffers = &tx_buf,
.count = 1
};
struct spi_buf rx_buf = {
.buf = rx_buffer,
.len = sizeof(rx_buffer),
};
const struct spi_buf_set rx = {
.buffers = &rx_buf,
.count = 1
};
err = spi_transceive(spi_dev, &spi_cfg, &tx, &rx);
if (err) {
printk("SPI write error: %d\n", err);
} else {
/* Connect MISO to MOSI for loopback */
printk("MISO TX sent: %x\n", tx_buffer[0]);
printk("MOSI RX recv: %x\n", rx_buffer[0]);
}
}
void main(void)
{
printk("\n**** main() start... ****\n");
//Initlize the SPI module
spi_init();
while (1)
{
spi_send(spi_dev);
k_sleep(K_SECONDS(2));
}
}
Thanks in advance.
Regards,
Kalyan