_SD_PASM Block Diagram Equiv Cluso99 20151127 First command "M" to mount card flush spi by DataInPin & ClockPin as outputs 74 loops of readSPI 8 bits slow (phsa=0, frqa[i]=%0000_0001_0) goto idle state: timeout=1s DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|0, 00,00,00,00, 95 (command 0, parameter 0, crc 95) readSPI 8 bits slow up to 9x looking for <>$FF shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input send interface condition: DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|8, 00,00,01,AA, 87 (command 8, parameter 1_AA, crc 87) readSPI 8 bits slow up to 9x looking for <>$FF readSPI 32 bits slow (result) shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input result=$04? If no, try SD 1.x initialisation SD 2.0/3.0 initialisation: if (result & $1FF)<>$1AA then instruction error! Send Operating Condition: timeout=1s DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|55, 00,00,00,00, FF (command 55, parameter 0, crc FF) readSPI 8 bits slow up to 9x looking for <>$FF shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input if (result<>$04) then goto MMC initialisation! command 41: DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|41, 40,00,00,00, FF (command 55, parameter HCSBitMask, crc FF) readSPI 8 bits slow up to 9x looking for <>$FF shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input if timeout call timeoutSPI + jmp exitIdleStateLoop_SD It's an SD card! sectorPntrAddress=$00_43_44_53 Read cards OCR register DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|58, 00,00,00,00, FF (command 58, parameter 0, crc FF) readSPI 8 bits slow up to 9x looking for <>$FF readSPI 32 bits slow (result) shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input if (result<>$0) instruction error! check voltage supported: if responce<>$00FF0000 (checked for z & <<1 nc parity) then instruction error! if response<<2 =c then SDHC & SPIShift=0 else SDXC & SPIShift=9 read CSD register: DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|9, 00,00,00,00, FF (command 9, parameter 0, crc FF) readSPI 8 bits slow up to 9x looking for =$FE read CSD register (16 bytes) readSPI 8 bits 16x into CSDRegister readSPI 16 bits shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input read CID register: DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|10, 00,00,00,00, FF (command 10, parameter 0, crc FF) readSPI 8 bits slow up to 9x looking for =$FE read CID register (16 bytes) readSPI 8 bits 16x into CIDRegister readSPI 16 bits shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input set Block Length: DataInPin & ClockPin & ChipSelectPin as outputs (CS last) readSPI 8 bits slow writeSPI $ 40|16, 00,00,02,00, FF (command 16, parameter 512, crc FF) readSPI 8 bits slow up to 9x looking for =$FE shutdownSPI: readSPI, ChipSelectPin off/input, readSPI, DataInPin & ClockPin off/input set card variables: SPITiming neg #1 cardMounted neg #1 goto InstructionLoop ----------------------------------------------------------------------------------------------