打开STM8A的用户手册,找到SPI寄存器描述那一页,对着看SPI_CR1和SPI_CR2各个bit位的含义。
SPI_CR1 address 0x00 5200 赋值
BIT 7 0(最高位先传输)
BIT 6 1(SPI使能)
BIT [5:3] 000(fmaster二分频)
BIT 2 1(主器件)
BIT 1 0(SCK从0电平开始)
BIT 0 0(第一个CLOCK开始第一个数据捕捉)
BDM: Bi-directional data mode enable
0: 2-line uni-directional data mode selected
1: 1-line bi-directional data mode selected
BDOE: Output enable in bi-directional mode
This bit combined with BDM bit selects the direction of transfer in bidirectional
mode
0: Output disabled (receive-only mode)
1: Output enabled (transmit-only mode)
In master mode, the MOSI pin is used and in slave mode, the MISO pin is
used.
RXONLY: Receive only
0: Full duplex (Transmit and receive)
1: Output disabled (Receive only mode)
This bit combined with BDM bit selects the direction of transfer in 2 line unidirectional
mode
This bit is also useful in a multi-slave system in which this particular slave is
not accessed, the output from the accessed slave is not corrupted.
如果设置BDM=0,且RXONLY=0,就是STM8A 的SPI的常规用法,即全双工。
而如果BDM=1,即一个数据线同时负责收发,bidirectional?就可以通过BDOE为0或者为1来切换收和发的方向,即如果要发送数据必须先将BDOE置一,而要收数据得先给BDOE置零?
而如果BDM=0,且RXONLY=1(1: Output disabled (Receive only mode)),则意味着什么?
RXONLY: Receive only
0: Full duplex (Transmit and receive)
1: Output disabled (Receive only mode)
This bit combined with BDM bit selects the direction of transfer in 2 line unidirectional
mode
This bit is also useful in a multi-slave system in which this particular slave is
not accessed, the output from the accessed slave is not corrupted.