i2c_send/i2c_recv/spi
The SaarCPU has hardware support for serial communication via I²C and SPI.
i2c_send
sends the accumulator bit by bit, starting with the most significant bit.
i2c_recv
receives a byte (again starting with the most significant bit), storing it in the accumulator.
spi
sends and receives one byte at the same time, starting with the least significant bit.
Source and destination are the accumulator.
Instruction | Encoding | Semantics | Cycles |
---|---|---|---|
i2c_send | 10 001 001 | see below | 12 |
i2c_recv | 10 010 010 | see below | 12 |
spi | 10 011 011 | see below | 10 |
i2c_send
The following steps are executed in the specified order with the I²C/SPI clock as well as SPI_SEND
enabled:
- send (start bit)
- send
- send
- send
- send
- send
- send
- send
- send
- receive acknowledge (should be but is not checked)
- send (stop bit)
The 12th micro instruction in our implementation is used for the instruction fetch.
i2c_recv
The following steps are executed in the specified order with the I²C/SPI clock enabled and SPI_SEND
disabled:
- receive the start bit (should be but is not checked)
- receive
- receive
- receive
- receive
- receive
- receive
- receive
- receive
- send (acknowledge)
- ignore stop bit (should be but is not checked)
The 12th micro instruction in our implementation is used for the instruction fetch.
spi
The following steps are executed in the specified order with the I²C/SPI clock enabled and SPI_SEND
disabled:
- send and receive
- send and receive
- send and receive
- send and receive
- send and receive
- send and receive
- send and receive
- send and receive
Our implementation needs 10 cycles because it needs to transfer the to the ALU latch before step 1 and perform the instruction fetch after step 8.