Code One:
1 //******************************************************************************2 //Description:spi slave talks to SPI master using 3-wire mode. Data is sent3 //To the master starting at 0x00 and increments. Received Data from the4 //Master is expected-to-start at 0xFF and decrements with each transmission.5 //******************************************************************************6#include <msp430x14x.h>7 CharMst_data =0x00, Slv_data =0XFF;8 voidMain ()9 {TenWdtctl = Wdtpw +Wdthold; One AP6dir |=BIT0; -P6out |=BIT0; -P3sel =0X0E;//p3.1,2,3 SPI Option Select theP3dir |=BIT1; -P3out |=BIT1; - -U0ctl |= Swrst + SYNC + MM +char;//Master SPI 8-bit +U0tctl |= ckph + SSEL1 +STC; -U0tctl &= ~CKPL; + AU0br0 =0X02;//SPICLK = SMCLK/2 atU0BR1 =0x00; -U0mctl =0x00; - -ME1 =USPIE0; -U0ctl &= ~Swrst; -IE1 |= URXIE0;//receive Enable in _eint (); - to while(1) + { -TXBUF0 =Mst_data; the LPM0; * } $ }Panax Notoginseng #pragmaVector=usart0rx_vector -__interruptvoidSpi_rx () the { +P6out ^=BIT0; A while((IFG1 & UTXIFG0) = =0); the if(U0rxbuf = =slv_data) + { -Slv_data = Slv_data-1; $Mst_data = Mst_data +1; $U0txbuf =Mst_data; - } - Else theTXBUF0 =Mst_data; -}
Code two:
1#include <msp430x14x.h>2 CharMst_data =0x00, Slv_data =0xFF;3 voidMain ()4 {5Wdtctl = Wdtpw +Wdthold;6P3sel =0X0E;7Uoctl = CHAR + SYNC +Swrst;8U0tctl = CKPL + SSEL1 +STC;9U0CLT &= ~ckph;Ten OneME1 |=USPIE0; AU0ctl &= ~Swrst; -IE1 |=URXIE0; - _eint (); the while(1) - { -TXBUF0 =Slv_data; - LMP4; + } - } + #pragmaVector=usart0rx_vector A__interruptvoidUsart0_rx () at { - while((IFG1 & OFIFG) = =0); - if(U0rxbuf = =mst_data) - { -Slv_data = Slv_data-1; -Mst_data = Mst_data +1; inTXBUF0 =Slv_data; - } to Else +TXBUF0 =Slv_data; -}
The road of msp430f149 learning--spi