/*-----------------------------------------------------------------------*/ /* Select the card and wait for ready */ /*-----------------------------------------------------------------------*/ static int select() /* 1:OK, 0:Timeout */ { /* Set CS# low */ chipSelectPin.Write(GpioPinValue.Low); Spi.RcvSpi(); /* Dummy clock (force DO enabled) */ if (wait_ready() > 0) { return(1); /* Wait for card ready */ } deselect(); return(0); /* Failed */ }
/*-----------------------------------------------------------------------*/ /* Receive bytes from the card */ /*-----------------------------------------------------------------------*/ static void rcvr_mmc( ref byte[] buff, /* Pointer to read buffer */ uint bc /* Number of bytes to receive */ ) { int rxIndex = 0; do { buff[rxIndex++] = Spi.RcvSpi(); /* Store a received byte */ }while (--bc > 0); }
/*-----------------------------------------------------------------------*/ /* Deselect the card and release SPI bus */ /*-----------------------------------------------------------------------*/ static void deselect() { chipSelectPin.Write(GpioPinValue.High); Spi.RcvSpi(); /* Dummy clock (force DO hi-z for multiple slave SPI) */ }