Hi,
I am comparatively new to TIVA C series TM4C123GH6PMI launchpad, and I had a question about SPI.
I set up the SPI registers and everything, and I tried sending data through to another device. I hook up my launchpad to the PC and I want to check if the data is going off the pin. So I put a breakpoint on the line where I actually send the data out, but cannot see any data updated in the SPI2_DR_R register. I wonder what the matter is. Am I setting up SPI wrong? Here's my code:
// Initialize Hardware
void initHw()
{
// Configure HW to work with 16 MHz XTAL, PLL enabled, system clock of 40 MHz
SYSCTL_RCC_R = SYSCTL_RCC_XTAL_16MHZ | SYSCTL_RCC_OSCSRC_MAIN | SYSCTL_RCC_USESYSDIV | (4 << SYSCTL_RCC_SYSDIV_S);
// Set GPIO ports to use APB (not needed since default configuration -- for clarity)
// Note UART on port A must use APB
SYSCTL_GPIOHBCTL_R = 0;
// Enable GPIO port B and E peripherals
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOB | SYSCTL_RCGC2_GPIOE;
// Configure three backlight LEDs
GPIO_PORTB_DIR_R |= 0x20; // make bit5 an output
GPIO_PORTB_DR2R_R |= 0x20; // set drive strength to 2mA
GPIO_PORTB_DEN_R |= 0x20; // enable bit5 for digital
GPIO_PORTE_DIR_R |= 0x30; // make bits 4 and 5 outputs
GPIO_PORTE_DR2R_R |= 0x30; // set drive strength to 2mA
GPIO_PORTE_DEN_R |= 0x30; // enable bits 4 and 5 for digital
// Configure A0 and ~CS for graphics LCD
GPIO_PORTB_DIR_R |= 0x42; // make bits 1 and 6 outputs
GPIO_PORTB_DR2R_R |= 0x42; // set drive strength to 2mA
GPIO_PORTB_DEN_R |= 0x42; // enable bits 1 and 6 for digital
// Configure SSI2 pins for SPI configuration
SYSCTL_RCGCSSI_R |= SYSCTL_RCGCSSI_R2; // turn-on SSI2 clocking
GPIO_PORTB_DIR_R |= 0x90; // make bits 4 and 7 outputs
GPIO_PORTB_DR2R_R |= 0x90; // set drive strength to 2mA
GPIO_PORTB_AFSEL_R |= 0x90; // select alternative functions for MOSI, SCLK pins
GPIO_PORTB_PCTL_R = GPIO_PCTL_PB7_SSI2TX | GPIO_PCTL_PB4_SSI2CLK; // map alt fns to SSI2
GPIO_PORTB_DEN_R |= 0x90; // enable digital operation on TX, CLK pins
// Configure the SSI2 as a SPI master, mode 3, 8bit operation, 1 MHz bit rate
SSI2_CR1_R &= ~SSI_CR1_SSE; // turn off SSI2 to allow re-configuration
SSI2_CR1_R = 0; // select master mode
SSI2_CC_R = 0; // select system clock as the clock source
SSI2_CPSR_R = 40; // set bit rate to 1 MHz (if SR=0 in CR0)
SSI2_CR0_R = SSI_CR0_SPH | SSI_CR0_SPO | SSI_CR0_FRF_MOTO | SSI_CR0_DSS_8; // set SR=0, mode 3 (SPH=1, SPO=1), 8-bit
SSI2_CR1_R |= SSI_CR1_SSE; // turn on SSI2
}
//send command
void sendGraphicsLcdCommand(uint8_t command)
{
CS_NOT = 0; // assert chip select
__asm (" NOP"); // allow line to settle
__asm (" NOP");
__asm (" NOP");
__asm (" NOP");
A0 = 0; // clear A0 for commands
SSI2_DR_R = command; // write command
while (SSI2_SR_R & SSI_SR_BSY); //----> PUT BREAKPOINT HERE
CS_NOT = 1; // de-assert chip select
}
SSI2_DR_R REGISTER is never updated with any value other than 0000.
Thanks!