iCE40 I2C and SPI Hardened IP Usage Guide
iCE40 I2C and SPI Hardened IP Usage Guide
iCE40 I2C and SPI Hardened IP Usage Guide
Introduction
This reference guide provides guidance for the advanced usage of iCE40LM, iCE40 Ultra™, iCE40 UltraLite™ and
iCE40 UltraPlus™ I2C and SPI IP. It is used as a supplement to TN1274, iCE40 I2C and SPI Hardened IP Usage
Guide. Note that the module generator - GUI flow is the recommended flow for initializing the Hard IP blocks as in
TN1274. In this document you will find:
The block diagram in Figure 4 shows the supported System Bus signals between the FPGA core and the Hard-
ened IP. Table 2 provides a detailed definition of the supported signals.
Figure 1. System Bus Interface Between the FPGA Core and the IP
iCE40LM/iCE40 Ultra
System Bus Master (User Logic)
SBCLKI
SBSTBI
IP Register Map
SBRWI
SBADRI[31:0] Hardened IP
User Logic
SBDATI[31:0]
SBDATO[31:0]
SBACKO
© 2015 Lattice Semiconductor Corp. All Lattice trademarks, registered trademarks, patents, and disclaimers are as listed at www.latticesemi.com/legal. All other brand
or product names are trademarks or registered trademarks of their respective holders. The specifications and information herein are subject to change without notice.
www.latticesemi.com 1 TN1276_1.4
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
To interface with the IP, you must create a System Bus Master controller in the User Logic. In a multiple-Master
configuration, the System Bus Master outputs are multiplexed through a user-defined arbiter. If two Masters
request the bus in the same cycle, only the outputs of the arbitration winner reach the Slave interface.
System Bus Write Cycle
Figure 5 shows the waveform of a Write cycle from the perspective of the System Bus Slave interface. During a sin-
gle Write cycle, only one byte of data is written to the IP block from the System Bus Master. A Write operation
requires a minimum three clock cycles.
On clock Edge 0, the Master updates the address, data and asserts control signals. During this cycle:
On clock Edge 1, the System Bus Slave decodes the input signals presented by the master. During this cycle:
• The Slave decodes the address presented on the SBADRI[7:0] address lines
• The Slave prepares to latch the data presented on the SBDATI[7:0] data lines
• The Master waits for an active-high level on the SBACKO line and prepares to terminate the cycle on the next
clock edge, if an active-high level is detected on the SBACKO line
• The IP may insert wait states before asserting SBACKO, thereby allowing it to throttle the cycle speed. Any num-
ber of wait states may be added
• The Slave asserts SBACKO signal
• The Slave latches the data presented on the SBDATI[7:0] data lines
• The Master de-asserts the strobe signal, SBSTBI, and the write enable signal, SBRWI
• The Slave de-asserts the acknowledge signal, SBACKO, in response to the Master de-assertion of the strobe
signal
2
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
SBCLKI
SBSTBI
SBCSI
SBRWI
VALID ADDRESS
SBADRI[3:0]
VALID DATA
SBDATI[9:0]
SBDATO[9:0]
SBACKO
On clock Edge 0, the Master updates the address, data and asserts control signals. The following occurs during
this cycle:
On clock Edge 1, the System Bus slave decodes the input signals presented by the master. The following occurs
during this cycle:
• The Slave decodes the address presented on the SBADRI[7:0] address lines
• The Master prepares to latch the data presented on SBDATO[7:0] data lines from the System Bus slave on the
following clock edge
• The Master waits for an active-high level on the SBACKO line and prepares to terminate the cycle on the next
clock edge, if an active-high level is detected on the SBACKO line
• The IP may insert wait states before asserting SBACKO, thereby allowing it to throttle the cycle speed. Any num-
ber of wait states may be added.
• The Slave presents valid data on the SBDATO[7:0] data lines
• The Slave asserts SBACKO signal in response to the strobe, SBSTBI signal
3
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
• The Master latches the data presented on the SBDATO[7:0] data lines
• The Master de-asserts the strobe signal SBSTBI
• The Slave de-asserts the acknowledge signal, SBACKO, in response to the master de-assertion of the strobe
signal
SBCLKI
SBSTBI
SBCSI
SBRWI
VALID ADDRESS
SBADRI[7:0]
SBDATI[7:0]
VALID DATA
SBDATO[7:0]
SBACKO
4
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
The block diagram in Figure 4 shows the supported System Bus signals between the FPGA core and the Hard-
ened IP. Table 2 provides a detailed definition of the supported signals.
Figure 4. System Bus Interface Between the FPGA Core and the IP
iCE40
IP Register Map
SBRWI
SBADRI[31:0] Hardened IP
User Logic
SBDATI[31:0]
SBDATO[31:0]
SBACKO
To interface with the IP, you must create a System Bus Master controller in the User Logic. In a multiple-Master
configuration, the System Bus Master outputs are multiplexed through a user-defined arbiter. If two Masters
request the bus in the same cycle, only the outputs of the arbitration winner reach the Slave interface.
5
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
On clock Edge 0, the Master updates the address, data and asserts control signals. During this cycle:
On clock Edge 1, the System Bus Slave decodes the input signals presented by the master. During this cycle:
• The Slave decodes the address presented on the SBADRI[9:0] address lines
• The Slave prepares to latch the data presented on the SBDATI[9:0] data lines
• The Master waits for an active-high level on the SBACKO line and prepares to terminate the cycle on the next
clock edge, if an active-high level is detected on the SBACKO line
• The IP may insert wait states before asserting SBACKO, thereby allowing it to throttle the cycle speed. Any num-
ber of wait states may be added
• The Slave asserts SBACKO signal
• The Slave latches the data presented on the SBDATI[9:0] data lines
• The Master de-asserts the strobe signal, SBSTBI, and the write enable signal, SBRWI
• The Slave de-asserts the acknowledge signal, SBACKO, in response to the Master de-assertion of the strobe
signal
SBCLKI
SBSTBI
SBCSI
SBRWI
VALID ADDRESS
SBADRI[3:0]
VALID DATA
SBDATI[9:0]
SBDATO[9:0]
SBACKO
6
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
On clock Edge 0, the Master updates the address, data and asserts control signals. The following occurs during
this cycle:
On clock Edge 1, the System Bus slave decodes the input signals presented by the master. The following occurs
during this cycle:
• The Slave decodes the address presented on the SBADRI[3:0] address lines
• The Master prepares to latch the data presented on SBDATO[9:0] data lines from the System Bus slave on the
following clock edge
• The Master waits for an active-high level on the SBACKO line and prepares to terminate the cycle on the next
clock edge, if an active-high level is detected on the SBACKO line
• The IP may insert wait states before asserting SBACKO, thereby allowing it to throttle the cycle speed. Any num-
ber of wait states may be added.
• The Slave presents valid data on the SBDATO[9:0] data lines
• The Slave asserts SBACKO signal in response to the strobe, SBSTBI signal
• The Master latches the data presented on the SBDATO[9:0] data lines
• The Master de-asserts the strobe signal SBSTBI
• The Slave de-asserts the acknowledge signal, SBACKO, in response to the master de-assertion of the strobe
signal
7
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
SBCLKI
SBSTBI
SBCSI
SBRWI
VALID ADDRESS
SBADRI[7:0]
SBDATI[7:0]
VALID DATA
SBDATO[7:0]
SBACKO
8
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2CEN I2C System Enable Bit – This bit enables the I2C core functions. If I2CEN is cleared,
the 2C core is disabled and forced into idle state.
GCEN Enable bit for General Call Response – Enables the general call response in slave
mode.
0: Disable
1: Enable
The General Call address is defined as 0000000 and works with either 7-bit or 10-bit
addressing
WKUPEN Wake-up from Standby/Sleep(by Slave Address matching) Enable Bit – When this bit
is enabled the, I2C core can send a wake-up signal to wake the device up from
standby/sleep. The wake-up function is activated when the Slave Address is matched
during standby/sleep mode.
0: Send ACK
1: Send NACK
9
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
CKSDIS Clock Stretching Disable – Disables the clock stretching if desired by the user for both
master and slave mode. Then overflow error flag must be monitored.0:Send ACK
RBUFDIS Read Command with Buffer Disable – Read from Slave in master mode with the dou-
ble buffering disabled for easier control over single byte data communication scenario.
I2C_PRESCALE[9:0]
I2C Clock Pre-scale value. A write operation to I2CBRMSB[1:0] will cause an I2C core reset. The System Bus
clock frequency is divided by (I2C_PRESCALE*4) to produce the Master I2C clock frequency supported by the I2C
bus (50KHz, 100KHz, 400KHz).
TIP Transmitting In Progress - This bit indicates that current data byte is being transferred
for both master and slave mode. Note that the TIP flag will suffer half SCL cycle
latency right after the start condition because of the signal synchronization. Note also
that this bit could be high after configuration wake-up and before the first valid I2C
transfer start (when BUSY is low), and it is not indicating byte in transfer, but an invalid
indicator.
10
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
BUSY Bus Busy – This bit indicates the bus is involved in transaction. This will be set at start
condition and cleared at stop. Therefore, only when this bit is high, should all other
status bits be treated as valid indicators for a valid transfer.
RARC Received Acknowledge – This flag represents acknowledge response from the
addressed slave during master write or from receiving master during master read.
0: No acknowledge received
1: Acknowledge received
SRW Slave RW
ARBL Arbitration Lost – This bit will go high if master has lost its arbitration in Master mode,
It will cause an interrupt to System Bus Host if SCI set up allowed.
0: Normal
1: Arbitration Lost
TRRDY Transmitter or Receiver Ready Bit – This flag indicate that a Transmit Register ready
to receive data or Receiver Register if ready for read depend on the mode (master or
slave) and SRW bit. It will cause an interrupt to System Bus Host if SCI set up allowed.
TROE Transmitter/Receiver Overrun or NACK Received Bit – This flag indicate that a Trans-
mit or Receive Overrun Errors happened depend on the mode (master or slave) and
SRW bit, or a no-acknowledges response is received after transmitting a byte. If
RARC bit is high, it is a NACK bit, otherwise, it is overrun bit. It will cause an interrupt
to System Bus Host if SCI set up allowed.
HGC Hardware General Call Received – This flag indicate that a hardware general call is
received from the slave port. It will cause an interrupt to System Bus Host if SCI set up
allowed.
I2C_ Transmit_Data[7:0] I2C Transmit Data – This register holds the byte that will be transmitted on the I2C bus
during the Write Data phase. Bit 0 is the LSB and will be transmitted last. When trans-
mitting the slave address, Bit 0 represents the Read/Write bit.
11
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2C_ Receive _Data[7:0] I2C Receive Data – This register holds the byte captured from the I2C bus during the
Read Data phase. Bit 0 is LSB and was received last.
I2C_ GC _Data[7:0] I2C General Call Data – This register holds the second (command) byte of the Gen-
eral Call transaction on the I2C bus.
IRQINTCLREN Auto Interrupt Clear Enable – Enable the interrupt flag auto clear when the I2CIRQ
has been read.
IRQINTFRC Force Interrupt Request On – Force the Interrupt Flag set to improve testability
12
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
13
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2CEN I2C System Enable Bit – This bit enables the I2C core functions. If I2CEN is cleared,
the 2C core is disabled and forced into idle state.
GCEN Enable bit for General Call Response – Enables the general call response in slave
mode.
0: Disable
1: Enable
The General Call address is defined as 0000000 and works with either 7-bit or 10-bit
addressing
14
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
WKUPEN Wake-up from Standby/Sleep(by Slave Address matching) Enable Bit – When this bit
is enabled the, I2C core can send a wake-up signal to wake the device up from
standby/sleep. The wake-up function is activated when the Slave Address is matched
during standby/sleep mode.
00: 300 ns
Disable the clock stretching if desired by user for both master and slave mode. Then
overflow error flag must be monitored.
0: Send ACK
1: Send NACK
CKSDIS Clock Stretching Disable – Disables the clock stretching if desired by the user for both
master and slave mode. Then overflow error flag must be monitored.0:Send ACK
RBUFDIS Read Command with Buffer Disable – Read from Slave in master mode with the dou-
ble buffering disabled for easier control over single byte data communication scenario.
15
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2C_PRESCALE[9:0]
I2C Clock Pre-scale value. A write operation to I2CBRMSB[1:0] will cause an I2C core reset. The System Bus
clock frequency is divided by (I2C_PRESCALE*4) to produce the Master I2C clock frequency supported by the I2C
bus (50 kHz, 100 kHz, 400 kHz).
TIP Transmitting In Progress - This bit indicates that current data byte is being transferred
for both master and slave mode. Note that the TIP flag will suffer half SCL cycle
latency right after the start condition because of the signal synchronization. Note also
that this bit could be high after configuration wake-up and before the first valid I2C
transfer start (when BUSY is low), and it is not indicating byte in transfer, but an invalid
indicator.
BUSY Bus Busy – This bit indicates the bus is involved in transaction. This will be set at start
condition and cleared at stop. Therefore, only when this bit is high, should all other
status bits be treated as valid indicators for a valid transfer.
RARC Received Acknowledge – This flag represents acknowledge response from the
addressed slave during master write or from receiving master during master read.
0: No acknowledge received
1: Acknowledge received
SRW Slave RW
16
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
ARBL Arbitration Lost – This bit will go high if master has lost its arbitration in Master mode,
It will cause an interrupt to System Bus Host if SCI set up allowed.
0: Normal
1: Arbitration Lost
TRRDY Transmitter or Receiver Ready Bit – This flag indicate that a Transmit Register ready
to receive data or Receiver Register if ready for read depend on the mode (master or
slave) and SRW bit. It will cause an interrupt to System Bus Host if SCI set up allowed.
TROE Transmitter/Receiver Overrun or NACK Received Bit – This flag indicate that a Trans-
mit or Receive Overrun Errors happened depend on the mode (master or slave) and
SRW bit, or a no-acknowledges response is received after transmitting a byte. If
RARC bit is high, it is a NACK bit, otherwise, it is overrun bit. It will cause an interrupt
to System Bus Host if SCI set up allowed.
HGC Hardware General Call Received – This flag indicate that a hardware general call is
received from the slave port. It will cause an interrupt to System Bus Host if SCI set up
allowed.
HGC Hardware General Call Received – This flag indicate that a hardware general call is
received from the slave port. It will cause an interrupt to System Bus Host if SCI set up
allowed.
RNACK Received NACK – This flag represents acknowledge response from the addressed
slave during master write.
0: Acknowledge received
1: No acknowledge (NACK) is received, FIFO state machine issues a
STOP and go to idle state.
17
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
MRDCMPL Master Read Complete – This is only valid for Master Read mode.
ARBL Arbitration Lost – This bit will go high if the master has lost its arbitration in Master
mode.
0: Normal
1: Arbitration Lost, FIFO state machine goes to idle state.
TXSERR TX FIFO synchronization error. This happens when there are back-to-back commands
in the FIFO.
0: No synchronization error
1: Synchronization error, the previous command is overwritten, then continues
with the next data entry in the FIFO.
TXUNDERF TX FIFO underflow – This indicates an error condition, mutually exclusive with clock
stretching function.
0: No underflow
1: FIFO underflow, data is not valid
RXOVERF RX FIFO overflow – This indicates an error condition, mutually exclusive with clock
stretching function.
0: No overflow
1: FIFO overflow, data is not valid
I2C_ Transmit_Data[7:0] I2C Transmit Data – This register holds the byte that will be transmitted on the I2C bus
during the Write Data phase. Bit 0 is the LSB and will be transmitted last. When trans-
mitting the slave address, Bit 0 represents the Read/Write bit.
18
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
CMD, RSTAEN 10: Bits [4:0] of this byte is the number of bytes to be received (in Master
mode). Following data transaction should be sent using a STOP then a
START.
11: Bits [4:0] of this byte is the number of bytes to be received (in Master mode).
Following data transaction should be sent using a START/ReSTART. The 1st
data byte should always has RSTAEN bit set to 1.
CMD, LTXBYTE 00: Bits [7:0] of this byte are data bits. If this is the last data byte in the TXFIFO,
then depending on the CKSDIS bit, Master Write will either go into clock
stretching (CKSDIS=0), or TXFIFO will underflow (CKSDIS=1).
01: Bit [7:0] of this byte are data bytes. If this is the last data byte in TXFIFO, this
indicates the last byte to be transferred and a STOP will be issued. If this is
not the last byte in TXFIFO, then this bit is ignored.
RXBYTE[7:5] Not used when CMD =1; data byte when CMD =0
I2C_ Receive _Data[7:0] I2C Receive Data – This register holds the byte captured from the I2C bus during the
Read Data phase. Bit 0 is LSB and was received last.
0: Normal data
1: First byte received after a Start or a ReStart is detected
19
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2C_ GC _Data[7:0] I2C General Call Data – This register holds the second (command) byte of the Gen-
eral Call transaction on the I2C bus.
IRQINTCLREN Auto Interrupt Clear Enable – Enable the interrupt flag auto clear when the I2CIRQ
has been read.
IRQINTFRC Force Interrupt Request On – Force the Interrupt Flag set to improve testability
20
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Default 0 0 0 0 0 0 0 0 0 0
0 to Disable YES YES YES YES YES YES YES YES YES YES
Access R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W
IRQCLREN Auto Interrupt Clear Enable – Enable the interrupt flag auto clear when the I2CINTSR
been read
IRQFRC Force Interrupt Request On – Force the Interrupt Flag set to improve testability
0: Normal operation
1: Force the Interrupt Request
HGCEN Force Interrupt Request On — Force the Interrupt Flag set to improve testability
0: Normal operation
1: Force the Interrupt Request
21
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Default - - - - - - - - - -
Access R/W R/W R/W R/W R/W R/W R/W R/W R/W R/W
IRQHGC General Call Interrupt Request Flag. Write a "1" to this bit clear the interrupt
0: No interrupt request
1: Interrupt request pending
IRQRNACK NACK Interrupt Request Flag. Write a "1" to this bit clear the interrupt
0: No interrupt request
1: Interrupt request pending
IRQMRDCMPL Master Read Completion Interrupt Request Flag. Write a "1" to this bit clear the inter-
rupt
0: No interrupt request
1: Interrupt request pending
IRQARBL Arbitration Lost Interrupt Request Flag. Write a "1" to this bit clear the interrupt
0: No interrupt request
1: Interrupt request pending
22
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
IRQTXSERR TXFIFO Synchronization Error Interrupt Request Flag. Write a "1" to this bit clear the
interrupt
0: No interrupt request
1: Interrupt request pending
IRQTXUNDERF TXFIFO Underflow Interrupt Request Flag. Write a "1" to this bit clear the interrupt
0: No interrupt request
1: Interrupt request pending
IRQRXOVERF RXFIFO Overflow Interrupt Request Flag. Write a "1" to this bit clear the interrupt
0: No interrupt request
1: Interrupt request pending
23
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Start
TXDR <= I2C addr + ‘W’ TXDR <= I2C addr + ‘R’
CMDR <= 0x94 (STA+WR) CMDR <= 0x94 (STA+WR)
N
Write more data? CMDR <= 0x24 (RD)
Y
Read data? Wait for TRRDY
Wait *
Figure 8 shows a flow diagram for reading and writing from an I2C Slave device via the System Bus interface.
24
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Start
N
wait for not BUSY Write reply data?
N
wait for TRRDY Write more data?
Y
* Required only for IRQ
driven algorithms
25
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
I2C Framing
Each command string sent to the I2C port must be correctly “framed” using the protocol defined for each interface.
In the case of I2C, the protocol is well known and defined by the industry as shown below.
SDA A6 A5 A4 A3 A2 0 0 W 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
SCL ...
(continued)
SDA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
(continued)
ACK By ACK By
iCE40LM iCE40LM
SCL ...
(continued)
SDA A6 A5 A4 A3 A2 0 0 R 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 ...
(continued)
Restart ACK By ACK By ACK By
By Master iCE40LM Master Master
Frame 6 I2C Slave Address Byte Frame 7 Read ID Byte 1 Frame 8 Read ID Byte 2
SCL
(continued)
SDA ID ID ID ID 0 0 0 0 0 1 0 0 0 0 1 1
(continued)
ACK By NACK By Stop By
Master Master Master
Frame 9 Read ID Byte 3 Frame 10 Read ID Byte 4
26
Figure 10. Master – I2C Write
I2C Functional Waveforms
1 9 1 9 1 9 Master Stop
SCL
Idle
Master Start
SDA AD6 AD5 AD4 AD3 AD2 AD1 AD0 Write D7 D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
I2C_1_SR[BUSY]
27
I2C_1_SR[SRW]
I2C_1_SR[RARC]
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Figure 11. Master – I2C Read
1 9 1 9 1 9
SCL
Master Start/ Ack from Ack from Nack from Stop from
Restart Slave Master Master Master
I2C_1_TXDR AD[(6:0),W]
28
I2C_1_SR[BUSY]
I2C_1_SR[SRW]
1 9 1 9 1 9
SCL
Start from Ack from Ack from Ack from Stop from
Master Slave Slave Slave Master
I2C_1_TXDR
29
I2C_1_SR[BUSY]
I2C_1_SR[SRW]
1 9 1 9 1 9
SCL
Start from Ack from Ack from No Ack from Stop from
Master Slave Master Master Master
I2C_1_RXDR
30
I2C_1_SR[BUSY]
I2C_1_SR[SRW]
I2C_1_SR[RARC]
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
SCL
SDA
The SPI core communicates with the System Bus interface through a set of control, command, status and data reg-
isters. Table 3 shows the register names and their functions.
SPI Registers
Table 34. SPI Registers Summary
Simulation Model
SPI Register Name Address[3:0] Register Function Access
Register Name
SPICR0 SPICR0 1000 SPI Control Register 0 Read/Write
SPICR1 SPICR1 1001 SPI Control Register 1 Read/Write
SPICR2 SPICR2 1010 SPI Control Register 2 Read/Write
SPIBR SPIBR 1011 SPI Baud Rate Register Read/Write
SPITXDR SPITXDR 1101 SPI Transmit Data Register Read/Write
SPIRXDR SPIRXDR 1110 SPI Receive Data Register Read
SPICSR SPICSR 1111 SPI Chip Select Mask Read/Write
For Master Mode
SPISR SPISR 1100 SPI Status Register Read
SPIIRQ SPIINTSR 0110 SPI Interrupt Status Register Read/Write1
SPIIRQEN SPIINTCR 0111 SPI Interrupt Control Register Read/Write
1. SPIIRQ is Read Only. Write operation upon this register will not change the content of this register, but will clear corresponding interrupt flag
caused by the flags inside SPIIRQ.
31
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
TIdle_XCNT[1:0]Idle Delay Count – Specifies the minimum interval prior to the Master Chip Select low assertion (Master Mode
only), in SCK periods.
00:½
01:1
10:1.5
11:2
TTrail_XCNT[2:0]Trail Delay Count – Specifies the minimum interval between the last edge of SCK and the high deassertion of
Master Chip Select (Master Mode only), in SCK periods.
000:½
001:1
010:1.5
…
111:4
TLead_XCNT[2:0]Lead Delay Count – Specifies the minimum interval between the Master Chip Select low assertion and the
first edge of SCK (Master Mode only), in SCK periods.
000:½
001:1
010:1.5
…
111:4
SPEThis bit enables the SPI core functions. If SPE is cleared, SPI is disabled and forced into idle state.
0:SPI disabled
1:SPI enabled, port pins are dedicated to SPI functions.
WKUPEN_USERWake-up Enable via User – Enables the SPI core to send a wake-up signal to the on-chip Power Controller to
wake the part from Standby mode when the User slave SPI chip select (spi_scsn) is driven low.
0:Wakeup disabled
1:Wakeup enabled.
WKUPEN_CFGWake-up Enable Configuration – Enables the SPI core to send a wake-up signal to the on-chip power controller
to wake the part from standby mode when the Configuration slave SPI chip select (ufm_sn) is driven low.
0:Wakeup disabled
1:Wakeup enabled.
TXEDGEData Transmitting selection bit – This bit gives user capability to select which clock edge to transmit data for fast SPI
applications. Note that this bit should not be set when CPHA or MCSH of SPICR2 is set.
32
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
0:Transmit data on the different clock edge of data receiving (receiving on rising / transmit on falling)
1:Transmit data on the same clock edge of data receiving (receiving on rising /transmit on rising)
MSTRSPI Master/Slave Mode – Selects the Master/Slave operation mode of the SPI core. Changing this bit forces the SPI sys-
tem into idle state.
0:SPI is in Slave mode
1:SPI is in Master mode
MCSHSPI Master CSSPIN Hold – Holds the Master chip select active when the host is busy, to halt the data transmission with-
out de-asserting chip select.
Note: This mode must be used only when the System Bus clock has been divided by a value greater than three (3).
0:Master running as normal
1:Master holds chip select low even if there is no data to be transmitted
SDBRESlave Dummy Byte Response Enable – Enables Lattice proprietary extension to the SPI protocol. For use when the
internal support circuit (e.g. System host) cannot respond with initial data within the time required, and to make the slave read
out data predictably available at high SPI clock rates.
When enabled, dummy 0xFF bytes will be transmitted in response to a SPI slave read (while SPISR[TRDY]=1) until an initial
write to SPITXDR. Once a byte is written into SPITXDR by the System host, a single byte of 0x00 will be transmitted then fol-
lowed immediately by the data in SPITXDR. In this mode, the external SPI master should scan for the initial 0x00 byte when
reading the SPI slave to indicate the begin-ning of actual data. Refer to Figure 18
Note: This mechanism only applies for the initial data delay period. Once the initial data is available, subsequent data must be
supplied to SPITXDR at the required SPI bus data rate.
CPOLSPI Clock Polarity – Selects an inverted or non-inverted SPI clock. To transmit data between SPI modules, the SPI mod-
ules must have identical SPICR2[CPOL] values. In master mode, a change of this bit will abort a transmission in progress and
force the SPI system into idle state. Refer to Figure 19 through Figure 21.
0:Active-high clocks selected. In idle state SCK is low.
1:Active-low clocks selected. In idle state SCK is high.
CPHASPI Clock Phase – Selects the SPI clock format. In master mode, a change of this bit will abort a transmission in progress
and force the SPI system into idle state. Refer to Refer to Figure 19 through Figure 21.
0:Data is captured on a leading (first) clock edge, and propagated on the opposite clock edge.
1:Data is captured on a trailing (second) clock edge, and propagated on the opposite clock edge*.
Note: When CPHA=1, the user must explicitly place a pull-up or pull-down on SCK pad corresponding to the value of CPOL
(e.g. when CPHA=1 and CPOL=0 place a pull-down on SCK). When CPHA=0, the pull direction may be set arbitrarily.
Slave SPI Configuration mode supports default setting only for CPOL, CPHA.
LSBFLSB-First – LSB appears first on the SPI interface. In master mode, a change of this bit will abort a transmission in prog-
ress and force the SPI system into idle state. Refer to Figure 19 through Figure 21.
Note: This bit does not affect the position of the MSB and LSB in the data register. Reads and writes of the data register always
have the MSB in bit 7.
33
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
DIVIDER[5:0]SPI Clock Prescale value – The System clock frequency is divided by (DIVIDER[5:0] + 1) to produce the desired
SPI clock frequency. A write operation to this register will cause a SPI core reset. DIVIDER must be >= 1.
Note: The digital value is calculated by Module Generator when the SPI core is configured in the SPI tab of the Module Genera-
tor GUI. The calculation is based on the System Bus Clock Frequency and the SPI Frequency, both entered by the user. The
digital value of the divider is loaded in the iCE40LM and iCE40 Ultra devices using Soft IP into the SPIBR register.
Register SPIBR has Read/Write access from the System Bus interface. Designers can update the clock pre-scale register
dynamically during device operation.
CSN_[7:0]SPI Master Chip Selects – Used in master mode for asserting a specific Master Chip Select (MCSN) line. The regis-
ter has four bits, enabling the SPI core to control up to four external SPI slave devices. Each bit represents one master chip
select line (Active-Low). Bits [3:1] may be connected to any I/O pin via the FPGA fabric. Bit 0 has a pre-assigned pin location.
The register has Read/Write access from the System Bus interface. A write operation on this register will cause the SPI core to
reset.
TIPSPI Transmitting In Progress – Indicates the SPI port is actively transmitting/receiving data.
0:SPI Transmitting complete
1:SPI Transmitting in progress*
BUSYSPI Busy Flag – This bit indicate that the SPI port in the middle of data transmitting / receiving (CSN is low)
0:SPI Transmitting complete
1:SPI Transmitting in progress*
TRDYSPI Transmit Ready – Indicates the SPI transmit data register (SPITXDR) is empty. This bit is cleared by a write to
SPITXDR. This bit is capable of generating an interrupt.
0:SPITXDR is not empty
1:SPITXDR is empty
34
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
RRDYSPI Receive Ready – Indicates the receive data register (SPIRXDR) contains valid receive data. This bit is cleared by a
read access to SPIRXDR. This bit is capable of generating an interrupt.
0:SPIRXDR does not contain data
1:SPIRXDR contains valid receive data
TOEReceive Overrun Error – This bit indicates that the SPIRXDR received new data before the previous data was read. The
previous data will be lost if occurs. It will cause an interrupt to System Host if SCI set up allowed.
0:Normal
1:Transmit Overrun detected
ROEReceive Overrun Error – Indicates SPIRXDR received new data before the previous data was read. The previous data is
lost. This bit is capable of generating an interrupt.
0:Normal
1:Receiver Overrun detected
MDFMode Fault – Indicates the Slave SPI chip select (spi_scsn) was driven low while SPICR2[MSTR]=1. This bit is cleared by
any write to SPICR0, SPICR1 or SPICR2. This bit is capable of generating an interrupt.
0:Normal
1:Mode Fault detected
SPI_Receive_Data[7:0]SPI Transmit Data – This register holds the byte that will be transmitted on the SPI bus. Bit 0 in this reg-
ister is LSB, and will be transmitted last when SPICR2[LSBF]=0 or first when SPICR2[LSBF]=1.
Note: When operating as a Slave, SPITXDR must be written when SPISR[TRDY] is '1' and at least 0.5 CCLKs before the first bit
is to appear on SO. For example, when CPOL = CPHA = TXEDGE = LSBF = 0, SPITXDR must be written prior to the CCLK ris-
ing edge used to sample the LSB (bit 0) of the previous byte. See Figure 17-25. This timing requires at least one protocol
dummy byte be included for all slave SPI read operations.
SPI_Receive_Data[7:0]SPI Receive Data This register holds the byte captured from the SPI bus. Bit 0 in this register is LSB and
was received last when LSBF=0 or first when LSBF=1.
35
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
36
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Start
Y
Read data?
N N
Done? Last Read?
Y Y
Done
Note: Assumes CR2 register, MSCH = '1'. The algorithm when MSCH = '0' is application dependent and not pro-
vided. See Figure 17 for guidance.
37
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
SPI Framing
Each command string sent to the SPI port must be correctly ‘framed’ using the protocol defined for each interface.
In the case of SSPI the protocol is well known and defined by the industry as shown below:
SPI_SCK ...
MOSI 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
MISO ...
SCSN ...
(continued)
SPI_SCK ...
(continued)
MOSI 0 0 0 0 0 0 0 0 ...
(continued)
MISO 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 ...
(continued)
Op Byte 3 Read ID Byte 1 Read ID Byte 2
SCSN
(continued)
SPI_SCK
(continued)
MOSI
(continued)
MISO ID ID ID ID 0 0 0 0 0 1 0 0 0 0 1 1
(continued)
38
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
SPISR[RRDY]
SPIRXDR R1 R2 R3 R4 R5 R6 R7 R8
SPISR[TIP]
MOSI R1 R2 R3 R4 R5 R6 R7 R8
MISO T1 T2 T3 T4 T5 T6 T7 T8
MCSN or SCSN
SPITXDR T1 T2 T3 T4 T5 T6 T7 T8
SPISR[TRDY]
T1 written to T1 from
SPITXDR via SPITXDR to SO
WISHBONE (auto)
(user)
Figure 18. Minimally Specified SPI Transaction Example (iCE40LM and iCE40 Ultra as SPI Slave)
CMD read from Addr read from
SPIRXDR via SPIRXDR via Flush SPIRXDR
WISHBONE WISHBONE via WISHBONE
(user) (user) (user)
Quit reading SPIRXDR (data is “don’t care”)
SPISR[TRDY]
SPISR[TRDY]
SPISR[TIP]
MOSI
0x08 addr dum
Command Reply to Command
MISO
old FF* dum2 D1 D2 D3 D4 D5
SCSN
SPISR[TRDY]
39
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
sample instants
SPI_SCK
(CPOL=0)
SPI_SCK
(CPOL=1)
MOSI
MISO
MSCN/SCSN/SN
tL tT tI tL
MSB first (LSBF=0): MSB bit6 bit5 bit4 bit3 bit2 bit1 LSB
LSB first (LSBF=1): LSB bit1 bit2 bit3 bit4 bit5 bit6 MSB
tL = TLead_XCNT
tT = TTrail_XCNT *Note: iCE40LM supports only
tL = Tidle_XCNT CPHA = CPOL = LSBF = TXEDGE = 0
sample instants
SPI_SCK
(CPOL=0)
SPI_SCK
(CPOL=1)
MOSI
MISO
MSCN or SCSN
tL tT tI tL
MSB first (LSBF=0): MSB bit6 bit5 bit4 bit3 bit2 bit1 LSB
LSB first (LSBF=1): LSB bit1 bit2 bit3 bit4 bit5 bit6 MSB
tL = TLead_XCNT
tT = TTrail_XCNT
tL = Tidle_XCNT
40
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
sample instants
SPI_SCK
(CPOL=0)
SPI_SCK
(CPOL=1)
MOSI
MISO
MCSN or SCSN
tL tT tI tL
MSB first (LSBF=0): MSB bit6 bit5 bit4 bit3 bit2 bit1 LSB
LSB first (LSBF=1): LSB bit1 bit2 bit3 bit4 bit5 bit6 MSB
tL = TLead_XCNT
tT = TTrail_XCNT
tL = Tidle_XCNT
41
Advanced iCE40 I2C and SPI
Hardened IP Usage Guide
Revision History
Date Version Change Summary
October 2015 1.4 Added support for iCE40 UltraPlus.
Updated I2C Registers for iCE40LM and iCE40 Ultra section. Revised
SDA_DEL_SEL[1:0] description.
Updated Technical Support Assistance section.
Fixed link to TN1274 on page 1.
January 2015 1.3 Added support for iCE40 UltraLite.
June 2014 1.2 Changed document title to Advanced iCE40 I2C and SPI Hardened IP
Usage Guide.
Added support for iCE40 Ultra.
November 2013 01.1 Changed the interface signal names of hardened IP module.
Updated I2C Registers Summary table.
October 2013 01.0 Initial release.
42