Tool/software: Code Composer Studio
Hi,
I have a codepiece to test an SPI device (LSM9DS0), at which I am in the "handshake" phase. The code below works as expected, but when I move the declaration of
uint8_t cs_pins;
into the main() function, it goes to FaultISR in one of the
while(SSIBusy(SSI2_BASE));
lines.
Why does this happen? The code is below... Thanks.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "driverlib/ssi.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
uint32_t ui32SysClkFreq;
uint8_t cs_pins;
int main(void) {
uint32_t accel_data = 0, gyro_data = 0;
uint32_t *dummy;
cs_pins = GPIO_PIN_2 | GPIO_PIN_3;
ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
GPIOPinConfigure(GPIO_PD3_SSI2CLK);
GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
GPIOPinTypeSSI(GPIO_PORTD_BASE,
GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
SSIConfigSetExpClk(SSI2_BASE, ui32SysClkFreq/100, SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 10000, 8);
SSIEnable(SSI2_BASE);
// SSIAdvModeSet(SSI2_BASE,SSI_ADV_MODE_LEGACY);
while(1)
{
GPIOPinWrite(GPIO_PORTB_BASE, cs_pins, GPIO_PIN_2 + GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTB_BASE, cs_pins, GPIO_PIN_3);
SSIDataPut(SSI2_BASE, 0b10001111);
while(SSIBusy(SSI2_BASE));
SSIDataGet(SSI2_BASE, dummy); //dummy thing to clear FIFO
while(SSIBusy(SSI2_BASE));
SSIDataPut(SSI2_BASE, 0b0); //dummy thing to clear FIFO
while(SSIBusy(SSI2_BASE));
SSIDataGet(SSI2_BASE, &accel_data);
while(SSIBusy(SSI2_BASE));
GPIOPinWrite(GPIO_PORTB_BASE, cs_pins, GPIO_PIN_2);
SSIDataPut(SSI2_BASE, 0b10001111);
while(SSIBusy(SSI2_BASE));
SSIDataGet(SSI2_BASE, dummy); //dummy thing to clear FIFO
while(SSIBusy(SSI2_BASE));
SSIDataPut(SSI2_BASE, 0b0); //dummy thing to clear FIFO
while(SSIBusy(SSI2_BASE));
SSIDataGet(SSI2_BASE, &gyro_data);
while(SSIBusy(SSI2_BASE));
GPIOPinWrite(GPIO_PORTB_BASE, cs_pins, GPIO_PIN_2 + GPIO_PIN_3);
SysCtlDelay(SysCtlClockGet()/3);
}
return 0;
}