TECHNICAL FIELD
[0001] This invention relates to communication using a Serial Peripheral Interface.
BACKGROUND
[0002] The Serial Peripheral Interface (SPI) is a serial data link that allows communication
between a master device and one or more slave devices.
[0003] The Serial Peripheral Interface comprises four lines: Serial Clock (SCLK), Master
Out Slave In (MOSI), Master In Slave Out (MISO) and Slave Select (SS). The lines SCLK,
MOSI and MISO are connected between the master device and all of the slave devices.
There is a dedicated SS line per slave device. The master uses the SS line to signal
to a slave that it is currently selected for communication.
[0004] A master device can individually poll slave devices to determine if they have data
to send. Another approach is to provide an additional line between a slave and the
master. This additional line can be used to signal an interrupt request from a slave
to the master. A disadvantage of this approach is that it requires additional lines,
and additional input/output processing at the master.
SUMMARY
[0005] An aspect of the invention provides a method of communicating between a slave device
and a master device using a Serial Peripheral Interface, the Serial Peripheral Interface
comprising a slave select line, the method comprising, at the slave device, signalling
an interrupt request to the master device by changing a state of the slave select
line from a first state indicative of an inactive state to a second state indicative
of an active state.
[0006] The signalling can further comprise returning the slave select line to the first
state.
[0007] The method can further comprise waiting for the master device to put the slave select
line to the second state; and sending data from the slave device over a data line
of the Serial Peripheral Interface.
[0008] The slave select line can be connected to an input/output stage of the slave device
which: allows the slave select line to remain in the first state if the master device
or the slave device does not change the state of the slave select line; allows the
slave select line to change to the second state if the master device or the slave
device wants to change the state of the slave select line.
[0009] The input/output stage can allow the slave select line to remain in the second state
if the master device or the slave device wants to maintain the state of the slave
select line in the second state.
[0010] Another aspect of the invention provides a method of communicating between a slave
device and a master device using a Serial Peripheral Interface, the Serial Peripheral
Interface comprising a slave select line per slave device, the method comprising,
at the master device, determining when the slave device has requested an interrupt
by detecting when the slave device changes the slave select line from a first state
indicative of an inactive state to a second state indicative of an active state.
[0011] The method can further comprise, in response to determining that the slave device
has requested an interrupt: selecting the slave device by putting the slave select
line into the second state; and retrieving data from the slave device over a data
line of the Serial Peripheral Interface.
[0012] There can be a plurality of slave devices, each connected to the master device by
a respective slave select line, and the method can comprise monitoring the slave select
lines of the plurality of slave devices.
[0013] The method can further comprise: receiving interrupt requests from a plurality of
the slave devices; and prioritising the interrupt requests.
[0014] The slave select line can be connected to an input/output stage of the slave device
which: allows the slave select line to remain in the first state if the master device
or the slave device does not change the state of the slave select line; allows the
slave select line to change to the second state if the master device or the slave
device wants to change the state of the slave select line.
[0015] The input/output stage can also allow the slave select line to remain in the second
state if the master device or the slave device want to maintain the state of the slave
select line in the second state.
[0016] The input/output stage can be a general purpose input output module.
[0017] The first state can be a high state and the second state can be a low state.
[0018] The Serial Peripheral Interface can further comprise a clock line, a Master Out Slave
In data line and a Master In Slave Out data line.
[0019] Another aspect of the invention provides apparatus at a slave device comprising:
a Serial Peripheral Interface to communicate with a master device, the Serial Peripheral
Interface comprising a slave select line, wherein the apparatus is configured to signal
an interrupt request to the master device by changing a state of the slave select
line from a first state indicative of an inactive state to a second state indicative
of an active state.
[0020] Another aspect of the invention provides apparatus at a master device comprising:
a Serial Peripheral Interface to communicate with a slave device, the Serial Peripheral
Interface comprising a slave select line per slave device, wherein the apparatus is
configured to determine when the slave device has requested an interrupt by detecting
when the slave device has caused the slave select line to change from a first state
indicative of an inactive state to a second state indicative of an active state.
[0021] The Serial Peripheral Interface at the slave device and the master device can comprise
an input/output stage which is configured to: allow the slave select line to remain
in the first state if the master device or the slave device does not change the state
of the slave select line; allow the slave select line to change to the second state
if the master device or the slave device wants to change the state of the slave select
line.
[0022] The input/output stage can comprise a general purpose input output module.
[0023] The input/output stage can comprise an open collector or open drain stage with a
pull-up resistor.
[0024] The functionality described here can be implemented in hardware, software executed
by a processing apparatus, or by a combination of hardware and software. The processing
apparatus can comprise a computer, a processor, a state machine, a logic array or
any other suitable processing apparatus. The processing apparatus can be a general-purpose
processor which executes software to cause the general-purpose processor to perform
the required tasks, or the processing apparatus can be dedicated to perform the required
functions. Another aspect of the invention provides machine-readable instructions
(software) which, when executed by a processor, perform any of the described or claimed
methods. The machine-readable instructions may be stored on an electronic memory device,
hard disk, optical disk or other machine-readable storage medium. The machine-readable
medium can be a non-transitory machine-readable medium. The term "non-transitory machine-readable
medium" comprises all machine-readable media except for a transitory, propagating
signal. The machine-readable instructions can be downloaded to the storage medium
via a network connection.
[0025] An advantage of at least one embodiment is that a slave device can signal an interrupt
request to a master device when it has something to communicate. This can avoid the
need to wait until the slave device is next polled in a normal manner and can therefore
reduce delays in communication between devices.
[0026] An advantage of at least one embodiment is that a slave device can signal an interrupt
request to a master device without the need for an additional line between a slave
device and a master device.
BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Embodiments of the invention will be described, by way of example only, with reference
to the accompanying drawings in which:
Figure 1 schematically shows a master device and a plurality of slave devices connected
by a SPI;
Figure 2 shows an example of signalling between a master device and a slave device
over the SPI;
Figure 3 shows an example of apparatus at a device.
DETAILED DESCRIPTION
[0028] Figure 1 schematically shows a system comprising a master device 10 and three slave
devices 1, 2, 3. The devices 1, 2, 3, 10 are connected by a Serial Peripheral Interface
(SPI) 20. The SPI 20 comprises an interface 28, 29 at each of the devices 1, 2, 3,
10 to support the interface and lines 21 between the devices to carry signals. The
lines 21 can be conductive tracks between the devices 1, 2, 3, 10. The SPI comprises:
a Serial Clock (SCLK) line 22, a Master Out Slave In (MOSI) line 23 and a Master In
Slave Out (MISO) line 24. The SCLK, MOSI and MISO lines are connected between the
master device 10 and all of the slave devices 1-3. The SPI also comprises a Slave
Select (SS) line per slave device. There is a first SS line 25 for slave device 1,
a second SS line 26 for slave device 2 and a third SS line 27 for slave device 3.
Another name for the Slave Select line is the Chip Select line. The interfaces 28,
29 at each device can comprise circuitry to physically connect to the lines 21 of
the SPI. The interfaces 28, 29 can comprise circuitry to drive the lines 21 of the
SPI. The interfaces 28, 29 can comprise circuitry to read one or more lines 21 of
the SPI. For clarity, in this description each line of the SPI is described according
to the signal that it carries. For example, the Serial Clock line 22 carries the Serial
Clock signal. The SPI can be used between integrated circuits (chips) on the same,
or different, circuit boards. Examples of the slave devices include peripheral devices
and smart cards. As an example, the slave device could be a security chip embedded
in a mobile phone, providing payment or authentication services to the main processor.
[0029] The lines 21 of the SPI will be described in more detail. The SCLK line 22 carries
a serial clock (SCLK) signal and enables synchronous communication. The MOSI line
23 carries a data signal in the direction from the master device 10 to the slave devices.
The data is synchronised with SCLK. The MISO line 24 carries data sent by a slave
device towards the master device. The data is synchronised with SCLK. The SS line
25-27 permits the selection of one of the slave devices 1-3. If a slave device is
not selected, that slave device ignores data sent on the MISO line 24.
[0030] A particular slave device is selected by changing the SS signal/line for that slave
device from a first (inactive) state to a second (active) state. Typically, the first
(inactive) state is "high" and the second (active) state is "low". Then, data is sent
in one, or both, directions. Data can be sent from the master device 10 to one of
the slave devices 1-3 over the MOSI line 23. Data can be sent from one of the slave
devices 1-3 to the master device 10 over the MISO line 24. Only one of the slave devices
1-3 is selected at a time.
[0031] The master 10 may poll individual slave devices 1-3 according to a polling order.
The polling order may poll the slave devices 1, 2, 3 in sequence, or some other polling
order.
[0032] In addition to the conventional use of the SS line to signal which slave device is
currently selected, it is possible for a slave device to send an interrupt request
(IRQ) to the master using the dedicated SS line for that slave device. The interrupt
request may be sent at any time. For example, the interrupt request may be sent at
a time between the normal polling of slave device 1 and the next polling time of slave
device 1. In this way, the SS lines 25-27 are used for bi-directional communication
between master device and slave device. This contrasts with conventional operation
of the SPI, where the SS line is entirely controlled by the master device in a uni-directional
manner (master to slave).
[0033] Figure 2 shows an example of signalling between the master device 10 and the slave
device 1 over the SPI 20. Figure 2 only shows the SS line 25 between the master device
10 and the slave device 1. Other SS lines 26, 27 are not shown. At time t1 the master
device 10 initiates a data transfer to the slave device 1 by changing the SS line
25 from a high state to a low state. This notifies the slave device 1 that it has
been selected for communication, and can listen to the MOSI line 23. At time t2, the
master device 10 starts to send data to the slave 1. Data is sent synchronously with
the clock signal on line SCLK 22. Data transfer ends at time t3 and at time t4 the
master changes the SS line 25 from a low state to a high state to end the communication
with the slave device 1. At time t5 the slave device 1 signals an interrupt request
to the master device 10 by changing the SS line 25 from a high state to a low state.
The slave device 1 returns the SS line 25 from the low state to the high state at
time t6. The interrupt request is received by the master device 10. At time t7 the
master device 10 changes the SS line 25 from a high state to a low state. This notifies
the slave device 1 that it has been selected for communication, and can use the MISO
line 24. At time t8, the slave device 1 starts to send data to the master device 10.
Data is sent synchronously with the clock signal on line SCLK 22. Data transfer ends
at time t9 and at time t10 the master changes the SS line 25 from a low state to a
high state to end the communication with the slave device 1.
[0034] The interrupt request may be detected on an edge of the signal on the SS line. That
is, the master device 10 may detect the transition from the high state to the low
state. In that case, the duration of the low state (t5-t6) can be a very short period
of time, such as a few nanoseconds. Alternatively, the master device 10 may detect
the state itself (i.e. low state or high state) rather than the transition between
states. Note that, for clarity, the time line of Figure 2 is not necessarily to a
linear scale.
[0035] In the example exchange of Figure 2, the slave device 1 is selected (at time t7)
soon after the signalling of the interrupt request (at time t5). The master device
may have a policy for handling interrupt requests. For example, when the master device
10 receives an interrupt request, it may wait until communication with the currently
selected slave device has completed and then select the slave device which sent the
interrupt request, or it may abandon communication with the currently selected slave
device and then immediately select the slave device which sent the interrupt request.
A slave may signal an important information, such as an alert of a warning condition,
and it may be useful for the master to receive this alert as soon as possible. If
the master device 10 receives interrupt requests from multiple slave devices, then
it may service those requests in order of receipt, by order of priority allocated
to those slave devices, by a combination of order of receipt and priority, or by some
other criterion or criteria.
[0036] The operation described above can require that the master device 10, or the slave
device 1-3, can change the state of the SS line. The slave device can change the state
of the SS line to signal an interrupt request. The master device can change the state
of the SS line to signal slave selection. The inactive state of the SS line is the
high state (logical '1') and the active state of the SS line is the low state (logical
'0'). The functionality can be summarised as:
- the SS line remains in the high state if any of the master device or the slave device
does not want to activate the SS line;
- the SS line can be changed to the low state if one of the master device or the slave
device want to activate the SS line.
Additionally, the SS line can remain in the low state if both the master device and
the slave device want to activate the SS line.
[0037] The SS line can be controlled by the master device in the same way as a conventional
SPI. As soon as the master device 10 has data to send, it can put the SS line to the
low (active) state. When the slave device has data to send, it can put the SS line
low just long enough to signal an interrupt request into the master component. Then,
the master device can activate an SPI exchange to retrieve data from the slave device.
[0038] If the master device and the slave device together change the SS line to the low
state it means that the master device has data to send to the slave device. As SPI
is a full duplex link with MOSI and MISO lines 23, 24, the slave device can send data
to the master device during the period when it is selected. In this case where the
master device and slave device both activate the SS line, the interruption request
will not be seen by the master, as the SS line is already low. However, as the slave
device is already selected, it can send data to the master device 10 over the MISO
line 24.
[0039] Figure 3 shows an example of apparatus 50 at a device. Apparatus 50 can be used at
a master device 10 or at one of the slave devices 1-3. The apparatus 50 comprises
a processor (CPU) 60 and an input/output stage 51 for connecting with the lines of
the SPI 20. In this example, the input/output stage 51 includes General Purpose Input/Output
(GPIO) modules 52. One GPIO 52 is shown in detail. GPIOs are hardware modules present
in most microcontroller chips which enable the microcontroller to control electrical
signals outside the chip. The GPIO 52 can drive a signal on a line to a high state
(logical '1') or a low state (logical '0'). Also, the GPIO can enter a high impedance
state and read the value (state) of a signal on the line. This allows the apparatus
to determine if another device connected to the line 25 has changed the state of the
line. A simplified GPIO comprises an output buffer 53 which can drive the signal connected
to the line of the interface. The output buffer 53 can be controlled by another signal
(oe for output enable) which determines if the buffer 53 can drive this signal (writing
mode) or if the buffer 53 is in the high impedance state (reading mode). Input buffer
54 reads the value present on the line 25. Register 56 stores a value for control
signal oe1. Register 57 stores a value for applying to the output buffer 53. Register
58 stores a value read from the input buffer 54. The registers 56, 57, 58 can be accessed
by the CPU 60, providing full control of the GPIOs.
[0040] The apparatus 50 at a master device 10 also comprises hardware logic 55 which can
notify the CPU 60 when the SS line is changed to an active state by the slave device.
In this example, the logic comprises an AND gate which receives an input from the
input buffer 54 representative of the SS line, and an input IRQ_mask. When the input
from the input buffer equals the IRQ_mask, the IRQ output 59 of gate 55 goes high.
IRQ_mask represents a logic value of the input buffer needed for an IRQ to be signalled,
and can be a logical '0'. An interrupt request (IRQ) 59 is output to the CPU 60 depending
on the state of the input buffer 54 of the GPIO 52. While Figure 3 shows hardware
logic 55 performing the detection of a change of state when a slave device changes
the SS line to an active state, it will be understood that this functionality can
be implemented in other ways. For example, an output of register 3, 58, can be read
by the CPU 60 and logic in the CPU can detect when a slave device changes the SS line
to an active state, by detecting when the signal read from register 3 changes to a
logical '0'. This is a kind of polling method by the CPU. Polling can require processing
resources of the CPU compared to the use of logic which delivers an interrupt signal
input to the CPU, as shown in Figure 3.
[0041] As described above, the functionality of the input/output stage 51 is configured
to:
- allow the SS line to remain in the inactive (high) state if any of the master device
or the slave device does not want to activate the SS line;
- the SS line can be changed to the active (low) state if one of the master device or
the slave device want to activate the SS line.
Additionally, the SS line can remain in the active (low) state if both the master
device and the slave device want to activate the SS line.
[0042] One way of achieving this functionality is for the master device and the slave device
to control the SS line with an open drain (or open collector) output and a pull-up
resistor. The inset to Figure 3 schematically shows an example of this type of output,
applied to a GPIO module 52. The GPIO module 52 can have the elements shown in the
main part of Figure 3. A pull-up resistor 72 connects between SS line 25 and a supply
rail 71. If the device does not want to activate the SS line 25, the line remains
connected to the supply rail 71 via the pull-up resistor 72, thereby ensuring a definite
logical state is signalled to the other device(s) connected to the SS line 25. If
the device, or another device connected to the SS line 25, wants to activate the SS
line 25, the SS line 25 can be put into the active (low) state. The pull-up resistor
72 prevents a short to ground.
[0043] The apparatus 50 shown in Figure 3 can be used at a master device 10 or at a slave
device 1-3. In the case where the apparatus shown in Figure 3 is used at a master
device 10, the other GPIOs shown in Figure 3 can connect to other SS lines 26, 27.
[0044] The processor 60 may be a microprocessor any other suitable type of processor for
executing instructions to control the operation of the device. Processor-executable
instructions 62 may be provided using any computer-readable media, such as memory
61. Memory 61 may be located with the processor 60, or communicatively coupled to
the processor 60. The processor-executable instructions 62 can include instructions
for communicating with one or more slave devices using an SPI link. The processor-executable
instructions 62 can comprise instructions for implementing the functionality of any
of the described methods. For example, when implemented at a master device 10, instructions
62 can cause the processor 60 to determine when a slave device changes the SS line
to an active state. When implemented at a slave device 1-3, instructions 62 can cause
the processor 60 to signal an interrupt request to the master device 10 by changing
a state of the slave select line 25 from a first state indicative of an inactive state
to a second state indicative of an active state. The memory 61 can be of any suitable
type, such as read-only memory (ROM), random access memory (RAM), a storage device
of any type such as a magnetic or optical storage device.
[0045] In the above description, the inactive state of the SS line is the high state (logical
'1') and the active state of the SS line is the low state (logical '0'). This is a
typical convention for SPI. It is possible to use a different convention, where the
inactive state of the SS line is the low state (logical '0') and the active state
of the SS line is the high state (logical '1'), providing all devices follow this
convention.
[0046] Modifications and other embodiments of the disclosed invention will come to mind
to one skilled in the art having the benefit of the teachings presented in the foregoing
descriptions and the associated drawings. Therefore, it is to be understood that the
invention is not to be limited to the specific embodiments disclosed and that modifications
and other embodiments are intended to be included within the scope of this disclosure.
Although specific terms may be employed herein, they are used in a generic and descriptive
sense only and not for purposes of limitation.
1. A method of communicating between a slave device (1) and a master device (10) using
a Serial Peripheral Interface (20), the Serial Peripheral Interface (20) comprising
a slave select line (25), the method comprising at the slave device (1):
signalling an interrupt request to the master device (10) by changing a state of the
slave select line (25) from a first state indicative of an inactive state to a second
state indicative of an active state.
2. A method according to claim 1 wherein the signalling further comprises returning the
slave select line (25) to the first state.
3. A method according to any one of the preceding claims further comprising:
waiting for the master device (10) to put the slave select line (25) to the second
state; and
sending data from the slave device (1) over a data line of the Serial Peripheral Interface
(20).
4. A method according to any one of the preceding claims wherein the slave select line
(25) is connected to an input/output stage (52) of the slave device (1) which:
allows the slave select line (25) to remain in the first state if the master device
(10) or the slave device (1) does not change the state of the slave select line (25);
and
allows the slave select line (25) to change to the second state if the master device
(10) or the slave device (1) wants to change the state of the slave select line (25).
5. A method of communicating between a slave device (1) and a master device (10) using
a Serial Peripheral Interface (20), the Serial Peripheral Interface (20) comprising
a slave select line (25) per slave device, the method comprising at the master device
(10):
determining when the slave device (1) has requested an interrupt by detecting when
the slave device (1) changes the slave select line (25) from a first state indicative
of an inactive state to a second state indicative of an active state.
6. A method according to claim 5 further comprising, in response to determining that
the slave device (1) has requested an interrupt:
selecting the slave device (1) by putting the slave select line (25) into the second
state; and
retrieving data from the slave device (1) over a data line of the Serial Peripheral
Interface (20).
7. A method according to claim 5 or 6 wherein there is a plurality of slave devices (1-3),
each connected to the master device (10) by a respective slave select line (25-27),
and the method comprises monitoring the slave select lines (25-27) of the plurality
of slave devices (1-3).
8. A method according to any one of claims 5 to 7 wherein the slave select line (25)
is connected to an input/output stage (52) at the master device (10) which:
allows the slave select line (25) to remain in the first state if the master device
(10) or the slave device (1) does not change the state of the slave select line (25);
and
allows the slave select line (25) to change to the second state if the master device
(10) or the slave device (1) wants to change the state of the slave select line (25).
9. A method according to claim 4 or 8 wherein the input/output stage is a general purpose
input output module.
10. A method according to any one of the preceding claims wherein the first state is a
high state and the second state is a low state.
11. A method according to any one of the preceding claims wherein the Serial Peripheral
Interface (20) further comprises a clock line (22), a Master Out Slave In data line
(23) and a Master In Slave Out data line (24).
12. Apparatus at a slave device (1) comprising:
a Serial Peripheral Interface (29) to communicate with a master device (10), the Serial
Peripheral Interface (20) comprising a slave select line (25);
wherein the apparatus is configured to signal an interrupt request to the master device
(10) by changing a state of the slave select line (25) from a first state indicative
of an inactive state to a second state indicative of an active state.
13. Apparatus according to claim 12 wherein the Serial Peripheral Interface (29) comprises
an input/output stage (52) which is configured to:
allow the slave select line (25) to remain in the first state if the master device
(10) or the slave device (1) does not change the state of the slave select line (25);
and allow the slave select line (25) to change to the second state if the master device
(10) or the slave device (1) wants to change the state of the slave select line (25).
14. Apparatus at a master device (10) comprising:
a Serial Peripheral Interface (28) to communicate with a slave device (1), the Serial
Peripheral Interface (28) comprising a slave select line (25) per slave device; wherein
the apparatus is configured to determine when the slave device (11) has requested
an interrupt by detecting when the slave device (1) has caused the slave select line
(25) to change from a first state indicative of an inactive state to a second state
indicative of an active state.
15. Apparatus according to claim 14 wherein the Serial Peripheral Interface (28) comprises
an input/output stage (52) which is configured to:
allow the slave select line (25) to remain in the first state if the master device
(10) or the slave device (1) does not change the state of the slave select line (25);
and allow the slave select line (25) to change to the second state if the master device
(10) or the slave device (1) wants to change the state of the slave select line (25).