I'm trying to run an SPI communication protocol with a third party ADC as fast as possible.
I initially configured the SPI modules using interrupt service routines. However with the ISR there were several microseconds of delay between bytes. I've now decided to use a busy-wait method, polling UCBUSY to try and save time.
I've configured my SPI module(s) in the following way (same for module A0):
const eUSCI_SPI_MasterConfig spiA1MasterConfig =
{
EUSCI_A_SPI_CLOCKSOURCE_SMCLK, //SMCLK
24000000, //Source clock rate=24MHz
8000000, //SPI clock rate=8MHz
EUSCI_A_SPI_MSB_FIRST, // MSB First
EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, // Phase
EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // Polarity: Active LOW
EUSCI_A_SPI_3PIN // 3wire mode
};
I send garbage data using the driverLib SPI function MAP_SPI_transmitData, then wait until the eUSCI_A busy signal has finished "transmitting or receiving," then load use MAP_SPI_receiveData to load the freshly received data into a buffer.
Here's my source code to do this with two SPI module, 3 bytes per ADC:
// -----------A1-----------
// set A1 CONVST high to start its conversion
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN4);
for(int i =0; i<1; i++);
// Set CONVSTA1 low (chip select)
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN4);
// send garbage byte and listen for response
MAP_SPI_transmitData(EUSCI_A1_MODULE, 0);
// ...wait...
while(UCA1STATW & BIT0);
// -->receive
receiveDataA1[0] = MAP_SPI_receiveData(EUSCI_A1_MODULE);
// send garbage-->
MAP_SPI_transmitData(EUSCI_A1_MODULE, 0);
// ...wait...
while(UCA1STATW & BIT0);
// -->receive
receiveDataA1[1] = MAP_SPI_receiveData(EUSCI_A1_MODULE);
// send garbage-->
MAP_SPI_transmitData(EUSCI_A1_MODULE, 0);
// ...wait...
while(UCA1STATW & BIT0);
// -->receive
receiveDataA1[2] = MAP_SPI_receiveData(EUSCI_A1_MODULE);
// set CONVST back high
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN4);
CONVSTa1 = 1;
// ------A0-------
// start conversion NOW
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);
// wait for conversion to happen
for(int i =0; i<1; i++);
// Set CONVSTA0 low (chip select)
MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P5, GPIO_PIN3);
// send garbage byte and listen for response
MAP_SPI_transmitData(EUSCI_A0_MODULE, 0);
// ...wait...
while(UCA0STATW & BIT0);
// -->receive
receiveDataA0[0] = MAP_SPI_receiveData(EUSCI_A0_MODULE);
//testBuf[0] = UCA0RXBUF;
// send garbage-->
MAP_SPI_transmitData(EUSCI_A0_MODULE, 0);
// ...wait...
test = UCA0STATW;
while(UCA0STATW & BIT0);
// -->receive
receiveDataA0[1] = MAP_SPI_receiveData(EUSCI_A0_MODULE);
//testBuf[1] = UCA0RXBUF;
// send garbage-->
MAP_SPI_transmitData(EUSCI_A0_MODULE, 0);
// ...wait...
while(UCA0STATW & BIT0);
// -->receive
receiveDataA0[2] = MAP_SPI_receiveData(EUSCI_A0_MODULE);
//testBuf[2] = UCA0RXBUF;
// set CONVST back high
MAP_GPIO_setOutputHighOnPin(GPIO_PORT_P5, GPIO_PIN3);
CONVSTa0 = 1;
This method works well for SPI clocks up to 8MHz when I'm running both SPI modules back to back. Oddly, when I comment out the second SPI method (A0), I can run A1 up to 12MHz.
At clock speeds higher than this the loop runs through healthy ONCE, then get gets hung up at the second
while(UCA1STATW & BIT0);
(ie UCBUSY is stuck high, "transmitting or receiving").
What could be causing UCBUSY to stay high forever?
