Texas Instruments MSC1210 User Manual

Page 264

Advertising
background image

Serial Peripheral Interface (SPI)

17-36

SPIEND = 0x0b0;

/*Master mode: set MISO for input, and MOSI, SS & SCK for strong outputs*/

P1DDRH = 0x75;

P1 |= 0xF0;

/*enable SPI interrupt*/

PIREG |= 0x0c;

IE |= 0x80;

EPFI = 1;

}

void transmit_receive () interrupt 6 using 1

{

/*This is a type 6 interrupt (AI). Processor vectors to 0x33,

from which it is redirected to this ISR. Because both SPI transmit

and SPI receive interrupts are enabled, additional steps must be

taken to differentiate between transmit and receive interrupt requests.

Hence, the ”if (AISTAT ...)” statements.*/

int i, k;//, p;

static int

j, l;

Each time the transmit block is selected; the value of the static integer j is increm-
ented by two, and written into the SPIDATA SFR. This automatically advances
the transmit pointer value, and places the value of j into the circular buffer. The
count in the SPITCON SFR is incremented. Note that the SPITCON count will
decrement automatically as soon as a byte has been successfully transmitted.
Finally, the SPIT bit in the AISTAT SFR is cleared before exiting out of this block.

if (AISTAT & 0x08)

{/*Transmitter*/

j += 2;

//set up value of j to be transmitted

SPIDATA = j;

//transmit j. This actually goes to the circular buffer

AISTAT &= ~0x08; //clear SPI transmit interrupt flag

}

The static integer variable i is checked to make sure that the array limits for the
received_data array of characters is not exceeded. If the limit has been
reached, the processor would print out the contents of the array to the Serial
#1 window, and then reset the value for l to 0.

You must mask out the MSB of this SFR in order to extract the number of bytes
because the SPIRCON SFR contains both the number of data bytes available
in the circular buffer for retrieval and the RXFLUSH bit. When the processor reads
a byte from the SPIDATA SFR, the oldest item in the current batch of received
data bytes is read, and the SPIDATA will point to the next item in the batch. This
implies that in order to read the batch of received data bytes that triggered the
current interrupt, you could just read the SPIDATA SFR SPIRCON & 0x7F times
with a FOR loop, and wait for the next time the interrupt is triggered.

Advertising