// // Copyright © 2003..2012 : Henk van Kampen // // This file is part of pBlazASM. // // pBlazASM is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // pBlazASM is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY// without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with pBlazASM. If not, see . // // ------------------------------------------------------------------------------- // SPI routines // data to move in s1, s1&s2, s1&s2&s3 // uses s0, sF // sE: bit in the command reg of the SPI_LE pin // sD: address of the command register // sC: address of the SPI control/status register // ------------------------------------------------------------------------------- .IF _SPI_ bMOSI .EQU 0b00000001 bMISO .EQU 0b10000000 bSCLK .EQU 0b00000010 ESPI24: MOVE sD, _PIGGY + _CMD // address of the command register, contains the CE signals MOVE sC, _PIGGY + _SPI // address of the SPI register, contains MOSI, MISO, SCLK signals SPI24: IN sF, sD // switch on the appropriate CE XOR sE, $FF AND sF, sE OUT sF, sD MOVE s0, s1 CALL _SPI8 MOVE s0, s2 CALL _SPI8 MOVE s0, s3 CALL _SPI8 IN sF, sD XOR sE, $FF OR sF, sE OUT sF, sD // switch off the CE RET ESPI16: MOVE sD, _PIGGY + _CMD // address of the command register, contains the CE signals MOVE sC, _PIGGY + _SPI // address of the SPI register, contains MOSI, MISO, SCLK signals SPI16: IN sF, sD // switch on the appropriate CE XOR sE, $FF AND sF, sE OUT sF, sD MOVE s0, s1 CALL _SPI8 MOVE s0, s2 CALL _SPI8 IN sF, sD XOR sE, $FF OR sF, sE OUT sF, sD // switch off the CE RET ESPI8: MOVE sD, _PIGGY + _CMD // address of the command register, contains the CE signals MOVE sC, _PIGGY + _SPI // address of the SPI register, contains MOSI, MISO, SCLK signals SPI8: IN sF, sD // switch on the appropriate CE XOR sE, $FF AND sF, sE OUT sF, sD MOVE s0, s1 CALL _SPI8 IN sF, sD XOR sE, $FF OR sF, sE OUT sF, sD // switch off the CE RET // ------------------------------------------------------------------------------- // raw SPI routines // byte to move in s0 // uses sF // ------------------------------------------------------------------------------- _SPI8: // shift 8 bits CALL _SPI4 _SPI4: // shift 4 bits CALL _SPI2 _SPI2: // shift 2 bits CALL _SPI1 // ------------------------------------------------------------------------------- // send one bit w/clock // ------------------------------------------------------------------------------- _SPI1: // shift 1 bit IN sF, sC AND sF, ~ bMOSI // clear MOSI bit SL0 s0 // check if upper bit set SKIP NC OR sF, bMOSI // set MOSI bit OUT sF, sC // update MOSI signal OR sF, bSCLK // set SCLK bit OUT sF, sC // update SCLK signal AND sF, ~ bSCLK // clear SCLK bit OUT sF, sC // update SCLK bit IN sF, sC TEST sF, bMISO // test MISO signal RET Z OR s0, 1 // reflect it in s0 RET .FI // -----------SPI Subroutines end-------------------------------------------------