This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于从F1611中 USART下的SPI移植到F5528 的 USCI_B0下的SPI程序

Other Parts Discussed in Thread: MSP430F1611, MSP430F5528

以下是正常工作的MSP430F1611程序里的SPI初始化和读写操作。

LSpiInit(void)

{

    /* config SPI interface */

    U0CTL = 0;

    U0CTL = SWRST;  //HOLD reset

    U0CTL |= CHAR + SYNC + SWRST + MM;   // 0001 0111

    U0TCTL = STC | SSEL0 | CKPH;    //1001 0010

    /* set baud rate = 1MHz , ACLK = 8MHz*/

    U0BR0 = 0x08;

    U0BR1 = 0X00;

    U0MCTL = 0X00;

    /* enable SPI mode for USART */

    ME1 |= USPIE0;   

    /* release USART from reset */

    U0CTL &= ~SWRST; 

    P3SEL = BIT1 + BIT2 + BIT3;

    return(0);

}

LSpiRead(UINT addr)

{

    U0TXBUF = (UD8)addr;

    while(!((IFG1) & ((0x80))));

    /*

     * Write dummy byte to SPI TX buf, then wait for SPI interface to finish

     * transmitting both the address and the dummy byte to the device. Note

     * when the SPI interface transmits the dummy byte, it will also receive

     * the data value from the device.

     */

    U0TXBUF = 0;

    while(!((U0TCTL) & ((0x01))));

    /* return value received from device */

    return(U0RXBUF);

}

LSpiWrite(UINT addr, UINT val)

{

    U0TXBUF = (UD8)addr;

    while(!((IFG1) & ((0x80))));

    /*

     * Write value to SPI TX buf, then wait for SPI interface to finish

     * transmitting both the address and the value to the device.

     */

    U0TXBUF = (UD8)val;

    while(!((U0TCTL) & ((0x01))));

}

 本人将以上程序移植到MSP430F5528中时,却不行,读到的值都为0。程序如下:

LSpiInit(void)

{

    UCB0CTL1 = 0;

    UCB0CTL1 = UCSWRST;   // USCI logic held in reset state

    UCB0CTL0 |= UCMST + UCSYNC + UCMSB + UCMODE_0 + UCCKPH;

    UCB0CTL1 |= UCSSEL__ACLK + UCSWRST;

    /* set baud rate = 1MHz , ACLK = 8MHz*/

    UCB0BR0 = 0x08;

    UCB0BR1 = 0x00;

    P3SEL |= BIT2 + BIT0 + BIT1;

    P3DIR |= BIT2 + BIT0;

    UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

    return(0);

}

LSpiRead(UINT addr)

{

    UCB0TXBUF = (UD8)addr;

    while (!( UCB0IFG & UCTXIFG));  

    UCB0TXBUF = 0;

//  while(UCB0STAT & UCBUSY);

    while (!( UCB0IFG & UCRXIFG));

    return(UCB0RXBUF);

}

LSpiWrite(UINT addr, UINT val)

{

    UCB0TXBUF = (UD8)addr;

    while (!( UCB0IFG & UCTXIFG));

       UCB0TXBUF = (UD8)val;

//     while(UCB0STAT & UCBUSY);

       while (!( UCB0IFG & UCRXIFG));

}

求大侠指教啊

  • 楼主你好!

    没有必要移植,安装msp430ware,里面有所有的例程,包括SPI的各种模式。 

  • 我后来修改了标志位,就实现了之前在430F1611上的功能。我把SPI标志位判断的地方全部用了while(UCB0STAT & UCBUSY); 就可以了,功能是实现了,不过还是没想明白怎么这样就ok了。

    非常感谢  Bruce Wei 推荐的 msp430ware,很不错的资源,3Q3Q