embedded-hal icon indicating copy to clipboard operation
embedded-hal copied to clipboard

How to read incoming data from SPI MOSI Lane? (not MISO)

Open Syphixs opened this issue 6 months ago • 1 comments

I am working on a specific epd which requires to read data from the MOSI line after sending a command but switching the CS pin between each byte. It's unclear to me if this is even achievable with the SPI Bus implementation. If so some guidance would be appreciated. Some relevant parts from the documentation: appnote1

Here it also states that a CS pulse is necessary between each read.
appnote2

I thought something like this would be working:

    pub fn read_otp(&mut self, buffer: &mut [u8]) -> Result<(), E> {
        self.bus.lock(|bus| {
            let mut bus = bus.borrow_mut();

            self.cs.set_low().ok();
            // Command mode
            self.dc.set_low().ok();

            // Send read command
            bus.write(&[0xA2])?;

            self.dc.set_high().ok(); // Data mode

            // Read data
            for byte in buffer.iter_mut() {
                self.cs.set_high().ok();
                self.cs.set_low().ok();

                // Send dummy byte and read the result
                let mut read_buf = [0u8];
                bus.transfer(&mut read_buf, &[0x00])?;
                *byte = read_buf[0];
            }

            self.cs.set_high().ok();
            Ok(())
        })
    }

but then i found out that the transfer also wants to read on the MISO line.

Syphixs avatar Aug 17 '24 07:08 Syphixs