You are reading a single comment by @Ruprect99 and its replies. Click here to read the full conversation.
  • Hi,

    I've been looking at this code to try and convert to run an e-ink display (M5Paper) (https://github.com/gnzzz/IT8951/blob/89d505b26f130539644117522a0fdc128ffe44c1/lib/it8951.ts)

    I'm pretty new to SPI so have been trying to figure it out.

    looking through the forums I've managed to piece together 3 methods for reading, writing and sending commands

    var read = function(reg,len) { // read
      return SPI1.send([reg|SPI_PREAMBLE.READ,new Uint8Array(len)], cs).slice(1);
    };
    
    var write = function(reg,data) { // write
        return SPI1.write(reg, data, cs);
    };
    
    var command = function(c,d) {
        SPI1.write(c, cs);
        if (d!==undefined) {
          dc.set();
          SPI1.write(d, cs);
        }
      }
    

    But it doesn't work. So for example in the code I'm looking at, this gets called

     this.setRegister(SYS_REG.I80CPCR, 0x0001);
     this.spi.writeWords(
                Uint16Array.from([SPI_PREAMBLE.CMD, USDEF_I80_CMD.GET_DEV_INFO])
     );
     const data = this.spi.readWords(20);
    

    I've converted this to:

    write(SPI_PREAMBLE.WRITE|SYS_REG.I80CPCR, 0x0001);
    let info = read(SPI_PREAMBLE.CMD|USDEF_I80_CMD.GET_DEV_INFO,20)
    

    but info is just full of zeros.

    I'm not sure if I'm totally on the wrong track or just missing some key bit of information.

    Thanks,

    Rob Smart

  • Just a guess, in this code

     var command = function(c,d) {
     
     SPI1.write(c, cs);
     if (d!==undefined) {
       dc.set();
       SPI1.write(d, cs);
     }
     }
    

    you are not sending command+data as one block with cs low, not sure what device protocol there is but typically cs should be low for whole piece that belongs together. When cs goes high the device state machine typically goes to beginning (even to sleep) so forgets its state. But that's just a guess, don't know this device.

    EDIT:
    also don't see dc.clear(); before sending the command

About

Avatar for Ruprect99 @Ruprect99 started