Skip to main content

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.

InstructionEncodingSemanticsCycles
i2c_send10 001 001see below12
i2c_recv10 010 010see below12
spi10 011 011see below10

i2c_send

The following steps are executed in the specified order with the I²C/SPI clock as well as SPI_SEND enabled:

  1. send 00 (start bit)
  2. send acc[7]\mathit{acc}[7]
  3. send acc[6]\mathit{acc}[6]
  4. send acc[5]\mathit{acc}[5]
  5. send acc[4]\mathit{acc}[4]
  6. send acc[3]\mathit{acc}[3]
  7. send acc[2]\mathit{acc}[2]
  8. send acc[1]\mathit{acc}[1]
  9. send acc[0]\mathit{acc}[0]
  10. receive acknowledge (should be 00 but is not checked)
  11. send 00 (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:

  1. receive the start bit (should be 00 but is not checked)
  2. receive acc[7]\mathit{acc}[7]
  3. receive acc[6]\mathit{acc}[6]
  4. receive acc[5]\mathit{acc}[5]
  5. receive acc[4]\mathit{acc}[4]
  6. receive acc[3]\mathit{acc}[3]
  7. receive acc[2]\mathit{acc}[2]
  8. receive acc[1]\mathit{acc}[1]
  9. receive acc[0]\mathit{acc}[0]
  10. send 00 (acknowledge)
  11. ignore stop bit (should be 00 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:

  1. send and receive acc[0]\mathit{acc}[0]
  2. send and receive acc[1]\mathit{acc}[1]
  3. send and receive acc[2]\mathit{acc}[2]
  4. send and receive acc[3]\mathit{acc}[3]
  5. send and receive acc[4]\mathit{acc}[4]
  6. send and receive acc[5]\mathit{acc}[5]
  7. send and receive acc[6]\mathit{acc}[6]
  8. send and receive acc[7]\mathit{acc}[7]

Our implementation needs 10 cycles because it needs to transfer the acc\mathit{acc} to the ALU latch before step 1 and perform the instruction fetch after step 8.