ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_spi.h File Reference
#include "fw_conf.h"
#include "fw_types.h"

Go to the source code of this file.

Macros

#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_SetEnabled(__STATE__)   SFR_ASSIGN(SPCTL, 6, __STATE__)
 
#define SPI_SetDataOrder(__ORDER__)   SFR_ASSIGN(SPCTL, 5, __ORDER__)
 
#define SPI_SetMasterMode(__STATE__)   SFR_ASSIGN(SPCTL, 4, __STATE__)
 
#define SPI_SetClockPolarity(__STATE__)   SFR_ASSIGN(SPCTL, 3, __STATE__)
 
#define SPI_SetClockPhase(__PHASE__)   SFR_ASSIGN(SPCTL, 2, __PHASE__)
 
#define SPI_SetClockPrescaler(__PRE_SCALER__)   (SPCTL = SPCTL & ~0x03 | ((__PRE_SCALER__) << 0))
 
#define SPI_SetPort(__ALTER_PORT__)   (P_SW1 = P_SW1 & ~(0x03 << 2) | ((__ALTER_PORT__) << 2))
 

Enumerations

enum  SPI_AlterPort_t {
  SPI_AlterPort_P12P54_P13_P14_P15 = 0x00 , SPI_AlterPort_P22_P23_P24_P25 = 0x01 , SPI_AlterPort_P54_P40_P41_P43 = 0x02 , SPI_AlterPort_P35_P34_P33_P32 = 0x03 ,
  SPI_AlterPort_8G1K08_8Pin = 0x00
}
 
enum  SPI_ClockPreScaler_t { SPI_ClockPreScaler_4 = 0x00 , SPI_ClockPreScaler_8 = 0x01 , SPI_ClockPreScaler_16 = 0x02 , SPI_ClockPreScaler_32or2 = 0x03 }
 
enum  SPI_ClockPhase_t { SPI_ClockPhase_LeadingEdge = 0x00 , SPI_ClockPhase_TrailingEdge = 0x01 }
 
enum  SPI_DataOrder_t { SPI_DataOrder_MSB = 0x00 , SPI_DataOrder_LSB = 0x01 }
 

Functions

uint8_t SPI_TxRx (uint8_t dat)
 
void SPI_TxRxBytes (uint8_t *pBuf, uint8_t len)
 

Macro Definition Documentation

◆ SPI_ClearInterrupt

#define SPI_ClearInterrupt ( )    SFR_SET(SPSTAT, 7)

Definition at line 64 of file fw_spi.h.

◆ SPI_ClearInterrupts

#define SPI_ClearInterrupts ( )    (SPSTAT |= 0xC0)

Definition at line 66 of file fw_spi.h.

◆ SPI_ClearWriteConflictInterrupt

#define SPI_ClearWriteConflictInterrupt ( )    SFR_SET(SPSTAT, 6)

Definition at line 65 of file fw_spi.h.

◆ SPI_IgnoreSlaveSelect

#define SPI_IgnoreSlaveSelect (   __STATE__)    SFR_ASSIGN(SPCTL, 7, __STATE__)

Definition at line 68 of file fw_spi.h.

◆ SPI_RxTxFinished

#define SPI_RxTxFinished ( )    (SPSTAT & 0x80)

Definition at line 63 of file fw_spi.h.

◆ SPI_SetClockPhase

#define SPI_SetClockPhase (   __PHASE__)    SFR_ASSIGN(SPCTL, 2, __PHASE__)

Clock Phase (CPHA) 0: bits are sampled on the leading clock edge 1: bits are sampled on the trailing clock edge

Definition at line 84 of file fw_spi.h.

◆ SPI_SetClockPolarity

#define SPI_SetClockPolarity (   __STATE__)    SFR_ASSIGN(SPCTL, 3, __STATE__)

Clock Polarity, CPOL 0: clock line idles low 1: clock line idles high

Definition at line 78 of file fw_spi.h.

◆ SPI_SetClockPrescaler

#define SPI_SetClockPrescaler (   __PRE_SCALER__)    (SPCTL = SPCTL & ~0x03 | ((__PRE_SCALER__) << 0))

SPI Clock

Definition at line 88 of file fw_spi.h.

◆ SPI_SetDataOrder

#define SPI_SetDataOrder (   __ORDER__)    SFR_ASSIGN(SPCTL, 5, __ORDER__)

Definition at line 70 of file fw_spi.h.

◆ SPI_SetEnabled

#define SPI_SetEnabled (   __STATE__)    SFR_ASSIGN(SPCTL, 6, __STATE__)

Definition at line 69 of file fw_spi.h.

◆ SPI_SetMasterMode

#define SPI_SetMasterMode (   __STATE__)    SFR_ASSIGN(SPCTL, 4, __STATE__)

Definition at line 71 of file fw_spi.h.

◆ SPI_SetPort

#define SPI_SetPort (   __ALTER_PORT__)    (P_SW1 = P_SW1 & ~(0x03 << 2) | ((__ALTER_PORT__) << 2))

Alternative ports

Definition at line 92 of file fw_spi.h.

Enumeration Type Documentation

◆ SPI_AlterPort_t

STC8H1K08(TSSOP20) STC8H3K32S2(TSSOP20) #1 #4 #1 #3 #4 SPI SS -> 1 16 19 7 16(P35) SPI MOSI -> 2 15 15(P34) SPI MISO -> 3 14 14(P33) SPI CLK -> 4 13 13(P32)

The ports for STC8G1K08-8Pin, STC8G1K08A are different: SS MO MI SCLK 00 - P5.5 P5.4 P3.3 P3.2, 01/10/11 - n/a

Enumerator
SPI_AlterPort_P12P54_P13_P14_P15 
SPI_AlterPort_P22_P23_P24_P25 
SPI_AlterPort_P54_P40_P41_P43 
SPI_AlterPort_P35_P34_P33_P32 
SPI_AlterPort_8G1K08_8Pin 

Definition at line 33 of file fw_spi.h.

34{
35 // SS MOSI MISO SCLK
SPI_AlterPort_t
Definition: fw_spi.h:34
@ SPI_AlterPort_P22_P23_P24_P25
Definition: fw_spi.h:37
@ SPI_AlterPort_P35_P34_P33_P32
Definition: fw_spi.h:39
@ SPI_AlterPort_8G1K08_8Pin
Definition: fw_spi.h:40
@ SPI_AlterPort_P54_P40_P41_P43
Definition: fw_spi.h:38
@ SPI_AlterPort_P12P54_P13_P14_P15
Definition: fw_spi.h:36

◆ SPI_ClockPhase_t

Enumerator
SPI_ClockPhase_LeadingEdge 
SPI_ClockPhase_TrailingEdge 

Definition at line 51 of file fw_spi.h.

52{
53 SPI_ClockPhase_LeadingEdge = 0x00, // Bits are sampled on the leading edge of SCLK
54 SPI_ClockPhase_TrailingEdge = 0x01, // Bits are sampled on the trailing edge of SCLK
SPI_ClockPhase_t
Definition: fw_spi.h:52
@ SPI_ClockPhase_TrailingEdge
Definition: fw_spi.h:54
@ SPI_ClockPhase_LeadingEdge
Definition: fw_spi.h:53

◆ SPI_ClockPreScaler_t

Enumerator
SPI_ClockPreScaler_4 
SPI_ClockPreScaler_8 
SPI_ClockPreScaler_16 
SPI_ClockPreScaler_32or2 

Definition at line 43 of file fw_spi.h.

44{
SPI_ClockPreScaler_t
Definition: fw_spi.h:44
@ SPI_ClockPreScaler_4
Definition: fw_spi.h:45
@ SPI_ClockPreScaler_8
Definition: fw_spi.h:46
@ SPI_ClockPreScaler_32or2
Definition: fw_spi.h:48
@ SPI_ClockPreScaler_16
Definition: fw_spi.h:47

◆ SPI_DataOrder_t

Enumerator
SPI_DataOrder_MSB 
SPI_DataOrder_LSB 

Definition at line 57 of file fw_spi.h.

58{
59 SPI_DataOrder_MSB = 0x00, // High bits first
60 SPI_DataOrder_LSB = 0x01, // Low bits first
SPI_DataOrder_t
Definition: fw_spi.h:58
@ SPI_DataOrder_LSB
Definition: fw_spi.h:60
@ SPI_DataOrder_MSB
Definition: fw_spi.h:59

Function Documentation

◆ SPI_TxRx()

uint8_t SPI_TxRx ( uint8_t  dat)

Definition at line 20 of file fw_spi.c.

21{
22 SPDAT = dat;
23 while (!SPI_RxTxFinished());
25 return SPDAT;
26}
__CODE int8_t dat[20]
#define SPI_ClearInterrupts()
Definition: fw_spi.h:66
#define SPI_RxTxFinished()
Definition: fw_spi.h:63

◆ SPI_TxRxBytes()

void SPI_TxRxBytes ( uint8_t pBuf,
uint8_t  len 
)

Definition at line 28 of file fw_spi.c.

29{
30 while(len--)
31 {
32 *pBuf++ = SPI_TxRx(*pBuf);
33 }
34}
uint8_t SPI_TxRx(uint8_t dat)
Definition: fw_spi.c:20