/* p8_1.c: Using SSI1 to send A to Z characters via SPI1 */ #include "TM4C123GH6PM.h" void init_SSI1(void); void SSI1Write(unsigned char data); int main(void) { unsigned char i; init_SSI1(); for(;;) { for (i = 'A'; i <= 'Z'; i++) { SSI1Write(i); /* write a character */ } } } void SSI1Write(unsigned char data) { GPIOF->DATA &= ~0x04; /* assert SS low */ while((SSI1->SR & 2) == 0); /* wait until FIFO not full */ SSI1->DR = data; /* transmit high byte */ while(SSI1->SR & 0x10); /* wait until transmit complete */ GPIOF->DATA |= 0x04; /* keep SS idle high */ } void init_SSI1(void) { SYSCTL->RCGCSSI |= 2; /* enable clock to SSI1 */ SYSCTL->RCGCGPIO |= 8; /* enable clock to GPIOD for SSI1 */ SYSCTL->RCGCGPIO |= 0x20; /* enable clock to GPIOF for slave select */ /* configure PORTD 3, 1 for SSI1 clock and Tx */ GPIOD->AMSEL &= ~0x09; /* disable analog for these pins */ GPIOD->DEN |= 0x09; /* and make them digital */ GPIOD->AFSEL |= 0x09; /* enable alternate function */ GPIOD->PCTL &= ~0x0000F00F; /* assign pins to SSI1 */ GPIOD->PCTL |= 0x00002002; /* assign pins to SSI1 */ /* configure PORTF 2 for slave select */ GPIOF->DEN |= 0x04; /* make the pin digital */ GPIOF->DIR |= 0x04; /* make the pin output */ GPIOF->DATA |= 0x04; /* keep SS idle high */ /* SPI Master, POL = 0, PHA = 0, clock = 4 MHz, 16 bit data */ SSI1->CR1 = 0; /* disable SSI and make it master */ SSI1->CC = 0; /* use system clock */ SSI1->CPSR = 2; /* prescaler divided by 2 */ SSI1->CR0 = 0x0007; /* 8 MHz SSI clock, SPI mode, 8 bit data */ SSI1->CR1 |= 2; /* enable SSI1 */ } void SystemInit(void) { /* Grant coprocessor access */ /* This is required since TM4C123G has a floating point coprocessor */ SCB->CPACR |= 0x00f00000; }