/* p8_1.c: Using SPI to send A to Z characters via SPI * UCA1 is configured as 4-pin SPI. * Because MSP432 has no SPI with all 4 pins brought out * to the 40-pin headers, Pin Map is used to redirect them: * P2.3 CLK * P2.4 SIMO * P2.5 STE * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" void delayMs(int n); int main(void) { int i; EUSCI_A1->CTLW0 = 0x0001; /* disable UCA1 during config */ /* clock phase/polarity:11, MSB first, 8-bit, master, 4-pin SPI, STE low active, synchronous mode, use SMCLK as clock source, STE for slave enable */ EUSCI_A1->CTLW0 = 0xEDC3; EUSCI_A1->BRW = 1; /* 3 MHz / 1 = 3 MHz */ EUSCI_A1->CTLW0 &= ~0x0001; /* enable UCA1 after config */ PMAP->KEYID = 0x2D52; /* unlock PMAP */ P2MAP->PMAP_REGISTER[1] = 0x0800; /* map P2.3 to PM_UCA1CLK */ P2MAP->PMAP_REGISTER[2] = 0x070A; /* map P2.4 to PM_UCA1SIMO, map P2.5 to PM_UCA1STE */ P2->SEL0 |= 0x38; /* set alternate function to pinmap */ P2->SEL1 &= ~0x38; /* for P2.3, P2.4, P2.5 */ PMAP->CTL = 0; /* lock PMAP */ PMAP->KEYID = 0; while(1) { for (i = 'A'; i <= 'Z'; i++) { while(!(EUSCI_A1->IFG & 2)) ; /* wait for transmit buffer empty */ EUSCI_A1->TXBUF = i; /* write the character */ delayMs(10); } } } /* system clock at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 250; i > 0; i--); /* delay */ }