/* p8_3.c Generate sawtooth waveform using DAC LTC1661 on SPI * UCB0 is configured as SPI and connected to DAC LTC1661. * Software control slave select is used. * P1.5 UCB0CLK * P1.6 UCB0SIMO * P2.3 Slave Select * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" int main(void) { int i; EUSCI_B0->CTLW0 = 0x0001; /* disable UCB0 during config */ /* clock phase/polarity:10, MSB first, 8-bit, master, 3-pin SPI, synchronous mode, use SMCLK as clock source */ EUSCI_B0->CTLW0 = 0xA9C1; EUSCI_B0->BRW = 1; /* 3 MHz / 1 = 3 MHz */ EUSCI_B0->CTLW0 &= ~0x0001; /* enable UCB0 after config */ P1->SEL0 |= 0x60; /* P1.5, P1.6 for UCB0CLK, UCB0SIMO */ P1->SEL1 &= ~0x60; P2->DIR |= 8; /* P2.3 set as output for slave select */ P2->OUT |= 8; /* slave select idle high */ while(1) { for (i = 0; i < 1024; i++) { P2->OUT &= ~8; /* assert slave select */ while(!(EUSCI_B0->IFG & 2)) ; /* wait for transmit buffer empty */ EUSCI_B0->TXBUF = 0x90 | (i >> 6); /* write command and upper 4 bits of data */ while(!(EUSCI_B0->IFG & 2)) ; /* wait for transmit buffer empty */ EUSCI_B0->TXBUF = (i << 2) & 0xFF; /* write lower 6 bits of data */ while(EUSCI_B0->STATW & 1) ; /* wait for transmit complete */ P2->OUT |= 8; /* deassert slave select */ } } }