-
Notifications
You must be signed in to change notification settings - Fork 55
Using SPI
SPI MASTER <port>, <mode>, LSB|MSB <speed in MHz>
SPI TRANSFER <pin> <array variable>
SPI (Serial Peripheral Interface - wikipedia entry) is a defacto standard for connecting the CC254X to peripheral devices. BlueBasic supports the use of a single SPI interface in Master mode (no Slave support at this time), chosen from the 4 available on the device. SPI is configured as follows:
SPI MASTER 0, 0, MSB 1
This configures the SPI interface to use port 0, SPI mode 0, most significant bit first, and running at 1Mhz. Other options are:
port | USART |
---|---|
0 | USART 0 |
1 | USART 0, alternate |
2 | USART 1 |
3 | USART 1, alternate |
See pinout reference for more information.
mode | CPOL | CPHA |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
2 | 1 | 0 |
3 | 1 | 1 |
Endian | |
---|---|
LSB | bit 0 read/written first |
MSB | bit 7 read/written first |
speed
Speed | Bus speed |
---|---|
1 | 1 MHz |
2 | 2 MHz |
4 | 4 Mhz |
Once the SPI interface is initiated, data can be transfered to and from device as follows:
SPI TRANSFER P0(0) D
Before the transfer begin the pin P0(0) is set to 0 to select the device connected to this pin. The data in array "D" is then transferred to the selected device, and the contents of the array replaced by the data read from the device during the transfer. Once the transfer is completed, pin P0(0) is set to 1.
Specifying the pin to use to select the device allows the SPI interface to be used with many different devices, each selected by different pins. Also note that the pin must have been previous set as an output and value set to 1.
PINMODE P0(0) OUTPUT
P0(0) = 1