各位大虾,这是我一个MSP430G2433 的SPI(B0)口编的一个初始话程序,大家看看有什么问题没有,老是发送不对。
#define SYNC UCB0CTL0__SPI_bit.UCSYNC
#define MODE0 UCB0CTL0__SPI_bit.UCMODE0
#define MODE1 UCB0CTL0__SPI_bit.UCMODE1
#define MST UCB0CTL0__SPI_bit.UCMST
#define BIT UCB0CTL0__SPI_bit.UC7BIT
#define MSB UCB0CTL0__SPI_bit.UCMSB
#define KPL UCB0CTL0__SPI_bit.UCCKPL
#define KPH UCB0CTL0__SPI_bit.UCCKPH
#define SWRST UCB0CTL1__SPI_bit.UCSWRST
#define SSEL0 UCB0CTL1__SPI_bit.UCSSEL0
#define SSEL1 UCB0CTL1__SPI_bit.UCSSEL1
#define BUSY UCB0STAT__SPI_bit.UCBUSY
#define OE UCB0STAT__SPI_bit.UCOE
#define FE UCB0STAT__SPI_bit.UCFE
#define LISTEN UCB0STAT__SPI_bit.UCLISTEN
#define SPIREN IE2_bit.UCB0RXIE
#define SPITEN IE2_bit.UCB0TXIE
#define SPIR IFG2_bit.UCB0RXIFG
#define SPIT IFG2_bit.UCB0TXIFG
#define TXBUF UCB0TXBUF__SPI
#define RXBUF UCB0RXBUF__SPI
void spi()
{
SWRST=1; //关spi
SYNC=1; //选择spi
MST=1; //spi主机模式
BIT=0; //8位数据模式
MSB=0; //低位在前
KPL=0;
KPH=0; //选择时钟与数据关系
MODE0=0;
MODE1=0; //3线spi
SSEL0=1;
SSEL1=0; //选择ACLK时钟
UCB0BR0__SPI=200;
UCB0BR1__SPI=200; //时钟8分频
SWRST=0; //开spi
} |