diff --git a/include/fw_spi.h b/include/fw_spi.h index a4dee18..3491df1 100644 --- a/include/fw_spi.h +++ b/include/fw_spi.h @@ -43,9 +43,10 @@ typedef enum SPI_ClockPreScaler_32or2 = 0x03, } SPI_ClockPreScaler_t; -#define SPI_RxTxFinished() (SPSTAT & (0x01 << 7)) -#define SPI_ClearInterrupt() SFR_RESET(SPSTAT, 7) -#define SPI_ClearWriteConflictInterrupt() SFR_RESET(SPSTAT, 6) +#define SPI_RxTxFinished() (SPSTAT & 0x80) +#define SPI_ClearInterrupt() SFR_SET(SPSTAT, 7) +#define SPI_ClearWriteConflictInterrupt() SFR_SET(SPSTAT, 6) +#define SPI_ClearInterrupts() (SPSTAT |= 0xC0) #define SPI_IgnoreSlaveSelect(__STATE__) SFR_ASSIGN(SPCTL, 7, __STATE__) #define SPI_SetEnableState(__STATE__) SFR_ASSIGN(SPCTL, 6, __STATE__) @@ -64,4 +65,6 @@ typedef enum */ #define SPI_SwitchPort(__ALTER_PORT__) (P_SW1 = P_SW1 & ~(0x03 << 2) | ((__ALTER_PORT__) << 2)) +uint8_t SPI_TxRx(uint8_t dat); + #endif diff --git a/src/fw_spi.c b/src/fw_spi.c new file mode 100644 index 0000000..88ab700 --- /dev/null +++ b/src/fw_spi.c @@ -0,0 +1,27 @@ +// Copyright 2021 IOsetting +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "fw_spi.h" +#include "fw_tim.h" +#include "fw_sys.h" + + +uint8_t SPI_TxRx(uint8_t dat) +{ + SPI_ClearInterrupts(); + SPDAT = dat; + while (!SPI_RxTxFinished()); + SPI_ClearInterrupts(); + return SPDAT; +}