TI中文支持网
TI专业的中文技术问题搜集分享网站

RF430F51xx SPI通讯问题

你好!

     我在做一个项目,使用了RF430F51xx芯片,该芯片包含两个模块MCU(MSP430F5172)和RAIDAES模块,两个模块之间可以通过3线SPI通信。MCU作为master,另一个是slave。问题是: master接收到slave的数据总是不变的0xFF。

相关程序如下:

 

IO模块初始化:

 __disable_interrupt();

  PMAPPWD = 0x02D52;                      // Get write-access to port mapping regs   

PMAPCTL = PMAPRECFG;

P1MAP0 = PM_UCA0CLK;                    // Map UCA0CLK   

P1MAP1 = PM_UCA0SIMO;      // Map UCA0SIMO   

P1MAP2 = PM_UCA0SOMI;            // Map UCA0SOMI /*   

  PMAPPWD = 0;                            // Lock port mapping registers  

 __enable_interrupt();

P1DIR |= BIT1 + BIT0;     // SIMO & SPI_CLK as Outputs  

P1DIR &= (~BIT2);                        //SOMI  

P1SEL |= BIT2 + BIT1 + BIT0;   // P1.1, 1.2, 1.3 to secondary mode -> SPI-Clock,-SOMI,-SIMO

SPI初始化:

void SPI_init() {        

UCA0CTL1 |= UCSWRST;  

 //UCA0CTL0 &= ~UCCKPH;      // stay in reset condition until config is done    

 // UCA0CTL0 |= UCCKPL;   

UCA0CTL0 |=  UCMSB + UCMST + UCSYNC;    // 3-pin, 8-bit, MasterMode   //UCA0CTL0 = 0xA9;  

 UCA0CTL1 |= UCSSEL_2;                      // SMCLK   

UCA0BR0  = 2;        // SPI clock = SMCLK/20   

UCA0BR1  = 0;   

UCA0MCTL = 0;                              // No modulation  

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

}

收发模块程序:

u8 TransceiveSPI (u8 txdata) {  

char rxdata = 0x00;  

 while (BUSY_Pin != 0x00);           // wait until BUSY = 0  

while (!(UCA0IFG & UCTXIFG));             // wait until last SPI-Transmission is finished  

UCA0TXBUF = txdata;                         // send 8 clocks "txdata" and SPI-clocks  

 

 while (!(UCA0IFG & UCRXIFG));            // wait until one byte is received

 return UCA0RXBUF;

 rxdata = UCA0RXBUF;

 return (rxdata);                            // send "rxdata" to main program }

 

请问:

程序的问题在哪里?为什么不能接收slave的数据。

Peter_Zheng:

配置代码

// Display SPI Port Configuration P1DIR |= BIT1 + BIT0; // SIMO & SPI_CLK as Outputs P1SEL |= BIT2 + BIT1 + BIT0; // P1.1, 1.2, 1.3 to secondary mode -> SPI-Clock,-SOMI,-SIMO P1IES = 0;

PMAPPWD = 0x02D52; // Get write-access to port mapping regs  PMAPCTL = PMAPRECFG;

// Display Port Mapping P1MAP0 = PM_UCA0CLK; // Map UCA0CLK P1MAP1 = PM_UCA0SIMO; // Map UCA0SIMO P1MAP2 = PM_UCA0SOMI; // Map UCA0SOMI

PMAPPWD = 0; // Lock port mapping registers

发送代码

char TransceiveSPI (char txdata) { char rxdata = 0x00; while (BUSY_Pin != 0x00); // wait until BUSY = 0 while (!(UCA0IFG & UCA0TXIFG)); // wait until last SPI-Transmission is finished UCA0TXBUF = txdata; // send 8 clocks "txdata" and SPI-clocks while (!(UCA0IFG & UCA0RXIFG)); // wait until one byte is received rxdata = UCA0RXBUF; return (rxdata); // send "rxdata" to main program}

这是一段已经实现的代码,rf430f5xxx的P1.0/1.1/1.2是内部SPI与RAIDAES模块连接。

Peter_Zheng:

这是SPI的内部引脚图。

你的程序应该是demo code。用低频对RF430进行唤醒,查看SPI是否能够读到数据?

赞(0)
未经允许不得转载:TI中文支持网 » RF430F51xx SPI通讯问题
分享到: 更多 (0)