Mixing sdcard and spi2.send fails

Posted on
  • I'm working on a function to draw bmp-files to ILI9341 display.
    Idea is to read bmp file from local drive and send to display.

        for(var i = 0; i < img.height; i++){
          bmp = E.toArrayBuffer(file.read(img.width + img.width));
          spi.send(bmp.buffer);
        }
    
    

    Data sent to SPI is somehow corrupted.
    Checked sending color red and its corrupted.
    Uncommented file.read and its working fine.

    Is there a problem using sdCard and SPI2 at the same time ?

  • Well, the SD card itself is on SPI2 - so if you can use another SPI port (or software SPI) it's probably better.

    Having said that I'd have thought it would work. Does the act of reading the file (without the SPI.send) corrupt the LCD? If so you might have left CS asserted on the LCD?

  • Good point,
    I added cs off / cs on during reading from sdCard
    With a constant color this works now, but ...

    • if color is red, it works fine
    • if color is green I get "Error: Invalid Pin!"

      var c = 0x07e0; //Error: Invalid Pin!
      var c = 0xf800; // works fine
      for(var i = 0; i < img.height; i++){
        ce.write(1);
        bmp = E.toArrayBuffer(file.read(img.width + img.width));
        ce.write(0);
        for(var j = 0; j < 32; j++){spi.send(c>>8,c);}
      }
      
      
  • Try spi.send([c>>8,c]); :)

    If a second argument is given to SPI.send, it's assumed to be a chip select pin. 0xf800 & 255 = 0 = A0 so it'll be turning A0 on and off when you're sending via SPI :)

    Note that you could use it to your advantage:

        for(var i = 0; i < img.height; i++){
          bmp = E.toArrayBuffer(file.read(img.width + img.width));
          for(var j = 0; j < 32; j++){spi.send([c>>8,c],ce);}
        }
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Mixing sdcard and spi2.send fails

Posted by Avatar for JumJum @JumJum

Actions