English
Language : 

AN1445 Datasheet, PDF (5/7 Pages) STMicroelectronics – USING THE ST7 SPI TO EMULATE A 16-BIT SLAVE
USING THE ST7 SPI TO EMULATE A 16-BIT SLAVE
In the case of concurrent interrupts, the SPI interrupt must always be the first served. The only
way to ensure this happens is to have only the SPI interrupt enabled. Otherwise, if another in-
terrupt is served between two received words, an overrun condition will occur.
In the case of nested interrupts, the SPI interrupt only needs to have the highest priority, to be
always immediately served.
CONCLUSION: The maximum baud rate, which can be reached is 2 MBaud.
4 MEASUREMENTS
The goal of the measurement is to verify the above theory and to see whether the software
correctly receives both bytes. What is especially important is the time needed to read the data
register, which releases the shift register for the reception of the 2nd byte. To measure this
time an I/O port pin is used and cleared after reading the data register. The interrupt routine is
therefore slightly modified for the measurement (Figure 6.). The timing conditions are: SPI
baud rate = 2 Mbaud and fCPU = 8 MHz.
Figure 6. Measurement Software
C code
if (ValBit(SPISR,SPIF))
{
twobytesDR.b_form.low=SPIDR;
PBDR=0x00;
while(!ValBit(SPISR,SPIF));
twobytesDR.b_form.high=SPIDR;
PBDR=0xFF;
}
else
{
SPICR=0xC4;
}
Assembly code
_SPI_Interrupt:
btjf _SPISR,#7,L522
ld a,_SPIDR
ld _SPI_Interrupt$L-1,a
clr _PBDR
L332:
btjf _SPISR,#7,L332
ld a,_SPIDR
ld _SPI_Interrupt$L-2,a
ld a,#255
ld _PBDR,a
iret
L522:
ld a,#196
ld_SPICR,a
iret
The time to be measured is the time taken by the “LD a,SPIDR” instruction (Ax in Figure 7.).
The point we can measure is the transition when the port pin goes low (Bx in Figure 7.). The
time between both is the time needed by “ld _SPI_Interrupt$L-1,a“and “clr PBDR”, which is
4cy+5cy=1,125us. So to Ax is 1,125us before Bx.
The measurement shows that Ax is always before the deadline. This proves that the 8-bit SPI
can be used to receive 16-bit SPI messages at speeds up to 2MBaud.
5/7