SPI MOSI is high during spi_read()

Hello,

I am using an Adafruit Feather with NRF52840 IC to interface with a BNO085 IMU over SPI. I am coding using the NRF Connect Zephyr environment in VS Code. I have gotten communication between the two devices almost working, but a high MOSI pin during read is messing up my transfer.

The BNO works by first having an initialization stage, and then a timed output stage. Anytime I perform an spi_read command, I have found that my MOSI pin is going high. This is fine during the init stage, but screws up the output stage. I have found that unplugging the MOSI after init leads to a working output reading, otherwise the program freezes after a single read. Is there a way I can configure the MOSI not to go high?

Logic Analyzer showing the high MOSI during a read:

SPI main.c configuration:

#define SPI1_NODE	DT_NODELABEL(spi1)
static const struct device *spi1_dev = DEVICE_DT_GET(SPI1_NODE);

static struct spi_config spi_cfg ={
        .frequency = 1000000, //125000U
        .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER | SPI_MODE_CPOL | SPI_MODE_CPHA, //SPI_MODE_CPHA
		.slave = 0,
    };

SPI read command:

    gpio_pin_set(gpio1_dev, CS_PIN, 0);

	struct spi_buf rx_buf2 = {
		.buf = pBuffer,
		.len = packet_size,
	};
	const struct spi_buf_set rx2 = {
		.buffers = &rx_buf2,
		.count = 1
	};

	if (spi_read(spi1_dev, &spi_cfg, &rx2)) {
		printk("SPI Read Failed\r\n");
		return 0;
	}

	gpio_pin_set(gpio1_dev, CS_PIN, 1);

Full prj.conf:

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
CONFIG_USB_DEVICE_PID=0x0004
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y

CONFIG_SPI=y
CONFIG_GPIO=y

CONFIG_SPI_NRFX=y

CONFIG_NRFX_SPIM3=y
CONFIG_CBPRINTF_FP_SUPPORT=y

Board File:

&pinctrl {
        spi1_default: spi1_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 13)>;
            };
        };
    
        spi1_sleep: spi1_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 14)>,
                        <NRF_PSEL(SPIM_MISO, 0, 15)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 13)>;
                low-power-enable;
            };
        };
    
    };

&spi1 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        //cs-gpios = <&gpio0 8 GPIO_ACTIVE_HIGH>;

        pinctrl-0 = <&spi1_default>;
        pinctrl-1 = <&spi1_sleep>;
        pinctrl-names = "default", "sleep";

};

Thank you for the help

Parents
  • You can use the ORC register to define whether the output is high or low, set to 0x00 for always low after the command bytes:

    6.25.6.25 ORC Address offset: 0x5C0
    Byte transmitted after TXD.MAXCNT bytes have been transmitted in the case when RXD.MAXCNT is greater than TXD.MAXCNT
    When the maximum number of bytes in receive buffer is larger than the number of bytes in the transmit buffer, the contents of register ORC on page 388 will be transmitted after the last byte in the transmit buffer has been transmitted.

    Simple in SDK, not sure what this is called in Connect; maybe just search for "ORC" it should be part of the spi_config in spiinit

Reply
  • You can use the ORC register to define whether the output is high or low, set to 0x00 for always low after the command bytes:

    6.25.6.25 ORC Address offset: 0x5C0
    Byte transmitted after TXD.MAXCNT bytes have been transmitted in the case when RXD.MAXCNT is greater than TXD.MAXCNT
    When the maximum number of bytes in receive buffer is larger than the number of bytes in the transmit buffer, the contents of register ORC on page 388 will be transmitted after the last byte in the transmit buffer has been transmitted.

    Simple in SDK, not sure what this is called in Connect; maybe just search for "ORC" it should be part of the spi_config in spiinit

Children
Related