📄 pucspi.h
字号:
/*Programed by zhoudb 2002-6-21*/
#ifndef __GENERAL_PORT_SPI_H
#define __GENERAL_PORT_SPI_H
/*物料层的相关定义*/
#define BitMask 0x80
#define SS_EN 0
#define SS_DIS 1
#define HALFPERIOD 1 /*用于调整SCK的半周期*/
#define SCK(val) SET_PB_BIT(30,val)
#define MOSI(val) SET_PB_BIT(29,val)
#define MISO GET_PB_BIT(28)
#define SS1(val) SET_PB_BIT(31,val)
#define SS2(val) SET_PB_BIT(27,val)
/*数据链路层的相关定义*/
#define YYES 1
#define NNO 0
#define COMMANDWRITE 0x61
#define COMMANDREAD 0x60
#define IDMASK 0xf1
#define SOFTWARETIMEOUT 1000
#define MAXTIMEOUTNUM 6
#define RESETTIME 3
/*BCM5328的SPI相关寄存器地址*/
#define SPI_DATA0 0xf0
#define SPI_DATA1 0xf1
#define SPI_DATA2 0xf2
#define SPI_DATA3 0xf3
#define SPI_DATA4 0xf4
#define SPI_DATA5 0xf5
#define SPI_DATA6 0xf6
#define SPI_DATA7 0xf7
#define SPI_STS 0xfe
#define SPI_PAGE 0xff
/*BCM5328的SPI状态寄存器的比特屏蔽字节*/
#define MASK_STS_SPIF 0x80
#define MASK_STS_RACK 0x20
#define MASK_STS_TXRDY 0x02
#define MASK_STS_RXRDY 0x01
typedef struct
{
unsigned char RegPageAddr;
unsigned char RegAddr;
unsigned char DataLength;
unsigned char DataBuf[8]; /*DataBuf[]是次高位的BYTE,DataBuf[0]是最高位的BYTE*/
unsigned char BcmID;
}BcmRegStruct;
typedef enum
{
BCM_OK=0, /*操作成功*/
BCM_INVALID_ID=1, /*无效的ID号*/
BCM_TIME_OUT=2, /*软件超时*/
BCM_INVLAID_DATA_LENGTH=3,/*无效的数据长度,为了简化协议,这儿的最大长度为8*/
}BCM_STATUS;
/*供应用层软件调用的的接口函数*/
void Bcm5328SpiInit(void);
void Bcm5328CLK(void);
BCM_STATUS Bcm5328RegWrite(BcmRegStruct *RegStruct);
BCM_STATUS Bcm5328RegRead(BcmRegStruct *RegStruct);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -