SPI
SPI
command set allows to operate the Serial Peripheral Interface SPI interface of the HadCon(2)'s microcontroller, (currently "only") as a master.
It sends data in atomic chunks of bytes via the MOSI
pin to slave devices and receives via the MISO
pin the responses.
This happens in a buffered mode, so that multiple bytes can be send and received at once.
SPI write dc 7f 8f8fb4 0123456789abcdef be
SPI dc 7f 8f8fb4 0123456789abcdef be
write
command includes the following steps: dc 7f 8f 8f b4 01 23 45 67 89 ab cd ef be
SPI read
SPI show_read_buffer 3 1
SPI show_read_buffer 6
SPI show_read_buffer
TheSPI purge_read_buffer
// optionally
SPI purge_write_buffer// optionally
SPI add dc 7f SPI add 8f8fb4// repeat until write buffer is full
SPI add 0123456789abcdef//
SPI add be//
SPI show_write_buffer// optionally
SPI write_buffer SPI write_buffer// e.g. repeat it, if auto_purge is OFF
SPI write_buffer 02// only activate second chip select pin, by masking it with 0x02
write_buffer
command includes all remaining necessary steps: Reading: see Basic OperationSPI write dc 7f 8f8fb4 0123456789abcdef be SPI write_buffer
// e.g. repeat it, if auto_purge is OFF
... SPI write_buffer SPI write_buffer 02// only activate 2nd chip select pin, by masking it with 0x02
SPI write_buffer 01// only activate 1st chip select pin
SPI write_buffer fc// only activate the other chip select pins
Reading: see Basic OperationSPI purge_read_buffer
// optionally
SPI purge_write_buffer// optionally
SPI add dc 7f 8f8fb4 0123456789abcdef be SPI cs// get status of defined chip select pins
SPI cs_bar// same as above but with "active low" logic
SPI cs_set// set all available chip select pins to "active"
SPI transmit SPI cs_release// set all available chip select pins to "passive"
SPI cs_set 01// only activate 1st chip select pin to "active"
SPI transmit SPI cs_release// set all available chip select pins to "passive"
SPI cs_set fe// only activate the other chip select pins to "active"
SPI transmit SPI cs_release ee// set masked chip select pins to "passive", keep 5th "active"
SPI cs_release 10// set masked chip select pins to "passive", keep 5th "active"
SPI write <list of data bytes|words|dwords|qwords>
SPI w <list of data bytes|words|dwords|qwords>
DEBG
> 0 RECV SPI write OK
SPI write_buffer [ <Chip Select Mask> ]
SPI wb [ <Chip Select Mask> ]
RECV SPI write_buffer
SPI cs_set [ <Chip Select Mask> ]
SPI css [ <Chip Select Mask> ]
RECV SPI cs 1:1 2:- 3:- 4:- 5:- 6:- 7:- 8:-
cs
is called to show the current status SPI cs_release [ <Chip Select Mask> ]
SPI csr [ <Chip Select Mask> ]
RECV SPI cs 1:1 2:- 3:- 4:- 5:- 6:- 7:- 8:-
SPI read
SPI r
RECV SPI read <value>
<value>
SPI show_read_buffer [<Number of Bytes> [<Reverse Flag>]]
SPI sr [<Number of Bytes> [<Reverse Flag>]]
SPI sr
RECV SPI show_read_buffer elements: 0x5 (5)
RECV SPI show_read_buffer 10 00 10 21 42
SPI sr
RECV SPI show_read_buffer elements: 0x14 (20)
RECV SPI show_read_buffer (#1) 10 00 10 21 42 51 25 01 ...
RECV SPI show_read_buffer (#2) 10 10 10 00 10 21 42 51 ...
RECV SPI show_read_buffer (#3) 25 01 10 10
<Number of Bytes>
set, <Number of Bytes>
≠0, SPI sr 3
RECV SPI show_read_buffer --
<Number of Bytes>
set, e.g. 4, SPI sr 4
RECV SPI show_read_buffer 10 00 10 21
<Number of Bytes>
set, e.g. 0xA, SPI sr a
RECV SPI show_read_buffer (#1) 10 00 10 21 42 51 25 01 ...
RECV SPI show_read_buffer (#2) 10 10
<Number of Bytes>
set, e.g. 2, <Reverse Flag>
flag set ( TRUE,HIGH,ON,1
) SPI sr 2 TRUE
RECV SPI show_read_buffer 10 10
<Number of Bytes>
set, e.g. 9, <Reverse Flag>
flag set ( TRUE,HIGH,ON,1
) SPI sr 9 1
RECV SPI show_read_buffer (#1) 00 10 21 42 51 25 01 10 ...
RECV SPI show_read_buffer (#2) 10
8
(#i)
, starting from 1, is added in front
<Number of Bytes>
0
: all available
<Number of Bytes>
elements from beginning (1) to maximum <Number of Bytes>
<Reverse Flag>
0,FALSE,OFF,LOW
: show <Number of Bytes>
elements from beginning (1) to maximum <Number of Bytes>
<Number of Bytes>
elements from <number of elements> - <Number of Bytes>
until last added element
SPI purge_read_buffer
SPI pr
DEBG
> 0 RECV SPI purge_read_buffer OK
SPI cs [<Chip Select Mask>]
SPI cs
RECV SPI cs 1:0 2:- 3:- 4:- 5:- 6:- 7:- 8:-
0b01100001 = 0x71
SPI cs 71
RECV SPI cs 1:0 6:- 7:-
[<Chip Select Mask>]
<Pin States>
<Pin States>
: <Index>:<State>
<Index>
: 1 ... 8
<State>
: 1
: HIGH
0
: LOW
-
: undefined, channel not connected
SPI cs_bar [<Chip Select Mask>]
SPI csb [<Chip Select Mask>]
SPI csb
RECV SPI cs_bar 1:1 2:- 3:- 4:- 5:- 6:- 7:- 8:-
0b01100001 = 0x71
SPI csb 71
RECV SPI cs_bar 1:1 6:- 7:-
<Chip Select Mask>
<Pin States>
<Pin States>
: <Index>:<State>
<Index>
: 1 ... 8
<State>
: 1
: LOW
0
: HIGH
-
: undefined, channel not connected
SPI cs_pins [<CS Channel Index>]
SPI cs_pins
RECV SPI cs_pins <List of active <Index>:<PORTx>,<Pin> CS Configurations>
RECV SPI cs_pins 1:PORTB,0 2:PORTA,4 3:PORTG,4 7:PORTF,5
<CS Channel Index>
SPI cs_pins <CS Channel Index>
RECV SPI cs_pins <Index><PORTx>,<Pin>,<Status>
SPI cs_pins 1
RECV SPI cs_pins 1:PORTB,0,ON
<CS Channel Index>
1 ... 8
<List of active <Index>:<PORTx>,<Pin> CS Configurations>
<<Index>:<PORTx>,<Pin>,<Status> CS Configuration>
<Index>
1 ... 8
<PORTx>
PORTx
x
: A ... G
<Pin>
PORTx
0 ... 7
<Status>
ON
: active
OFF
: deactivated
SPI cs_add_pin <Symbolic Output Port Address> <Output Port Pin> [<Channel Select Index/Slot>]
SPI csap <Symbolic Output Port Address> <Output Port Pin> [<Channel Select Index/Slot>]
RECV SPI cs_pins <List of active <Index>:<PORTx>,<Pin> CS Configurations>
PORTX:Pin
combinations to act as channel select channels. Provided the chosen slots aren't used yet or the address set is already defined (see SPI cs_pins, SPI cs_remove_pin).<Channel Select Index/Slot>
: <Channel Select Index/Slot>
: <Symbolic Output Port Address>
PORTx
x
: A ... G
<Output Port Pin>
PORTx
0 ... 7
<Channel Select Index/Slot>
1 ... 8
SPI cs_remove_pin <Channel Select Index/Slot>
SPI csrp <Channel Select Index/Slot>
RECV SPI cs_pins <List of active <Index>:<PORTx>,<Pin> CS Configurations>
<Channel Select Index/Slot>
1 ... 8
SPI control_bits [<Extended SPI Control Register>]
SPI c [<Extended SPI Control Register>]
RECV SPI control_bits 50
RECV SPI spi_enable TRUE
RECV SPI data_order 0
RECV SPI master TRUE
RECV SPI clock_polarity 0
RECV SPI clock_phase 0
RECV SPI speed 0
RECV SPI double_speed TRUE
RECV SPI speed_divider 4 (2500000Hz @ 10000000Hz)
SPCR
and the SPI Status Register SPSR
en bloc. Therefore those two registers are combinded into one 16bit data word with SPCR
as LSB and SPSR
as MSB. Since SPSR
, despite its name, does have one control bit. <Extended SPI Control Register>
: <Extended SPI Control Register>
: <Extended SPI Control Register>
0 ... 1FF
SPI enable state: SPE
SPI spi_enable [<value>]
RECV SPI spi_enable ==SPI enable state: SPE==
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI Data Order: DORD
SPI data_order [<value>]
RECV SPI data_order
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI Master/Slave Select: MSTR
SPI master [<value>]
RECV SPI master
<value>
(0,) 1, ≠0, ON, (OFF), TRUE, (FALSE)
SPI Clock Polarity: CPOL
SPI clock_polarity [<value>]
RECV SPI clock_polarity
CPOL | Leading Edge | Trailing Edge |
---|---|---|
0 | Rising | Falling |
1 | Falling | Rising |
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI Clock Phase: CPHA
SPI clock_phase [<value>]
RECV SPI clock_phase
CPHA | Leading Edge | Trailing Edge |
---|---|---|
0 | Sample | Setup |
1 | Setup | Sample |
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI Clock Rate Select 1/0: SPR1/0
SPI speed [<value>]
RECV SPI speed
<value>
0 ... 3
speed | double speed | clock rate: SCK frequency |
---|---|---|
0 | OFF | fclkIO/4 |
1 | OFF | fclkIO/16 |
2 | OFF | fclkIO/64 |
3 | OFF | fclkIO/128 |
0 | ON | fclkIO/2 |
1 | ON | fclkIO/8 |
2 | ON | fclkIO/32 |
3 | ON | fclkIO/64 |
SPI Double Speed Bit:
SPI2X
SPI double_speed [<value>]
RECV SPI double_speed
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI transmit_byte_order [<value>]
RECV SPI transmit_byte_order
<value>
0, 1
<value> | transmit byte order |
---|---|
0 | MSB, big endian, FIFO |
1 | LSB, little endian, LIFO |
SPI transmit_report [<value>]
RECV SPI transmit_report
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI auto_purge_write_buffer [<value>]
RECV SPI auto_purge_write_buffer
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE
SPI auto_purge_read_buffer [<value>]
RECV SPI auto_purge_read_buffer
<value>
0, 1, ≠0, ON, OFF, TRUE, FALSE