刚搞了个VS1053模块,就试着弄弄正弦测试成功了,但是读寄存器总是不对uint8 RxFlag=0;
uint8 RX_DATA[2];void SPI_Init()
{
U0CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, master
U0TCTL = SSEL1 + SSEL0 + STC; // Polarity, 3-wire
U0TCTL&=~CKPL;
U0BR0 = 0x02; // SPICLK = SMCLK/2
U0BR1 = 0x00;
U0MCTL = 0x00;
ME1 |= USPIE0; // Module enable
U0CTL &= ~SWRST; // SPI enable
IE1|=URXIE0;
P3SEL |= 0x0E; // P3.1,2,3 SPI option select
P3DIR |= 0x0A;
}uint16 SPI_Read() //read from spi port
{
uint16 temp;
while(RxFlag!=2);
RxFlag=0;
temp=RX_DATA[0];
temp<<=8;
temp|=RX_DATA[1];
return temp;
} #pragma vector=USART0RX_VECTOR
__interrupt void UartRx()
{
RX_DATA[RxFlag++]=RXBUF0;
}总是返回的全是0求助啊
[
本帖最后由 yangyifeng01 于 2012-3-11 12:15 编辑 ]
此帖出自
小平头技术问答
参考了别人的程序
uint8 SPI_WriteByte(uint8 byte) //write one byte to spi port
{
while ((IFG1 & UTXIFG0)==0);
TXBUF0 = byte;
while ((IFG1 & URXIFG0)==0);
return RXBUF0;
}
难道是因为SPI是全双工的,在发送的时候,同时也在接收
MISO不连接的话,似乎URXIFG0也会置位,只是URXBUF0全是0
一周热门 更多>