以下是我对时钟配置和两个SPI的配置初始化代码
//调试时钟配置
void halInitMCU(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//
P5SEL |= BIT2+BIT3; // Port select XT2
UCSCTL6 &= ~XT2OFF; // Enable XT2
UCSCTL3 |= SELREF_2; // FLLref = REFO
// Since LFXT1 is not used,
// sourcing FLL with LFXT1 can cause
// XT1OFFG flag to set
UCSCTL4 |= SELA_2; // //ACLK=REFO,SMCLK=DCO,MCLK=DCO
}
//初始化与CC1120连接的spi
void CC1120_SpiInit(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P1DIR |= BIT7; // Set P1.7 for CSN
P2DIR |= BIT3; // Set P2.3 for slave reset
P3SEL |= BIT3+BIT4; // P3.3,4 option select
P2SEL |= BIT7; // P2.7 CLK
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; // 4-pin, 8-bit SPI master
//Clock polarity high, MSB
UCA0CTL1 |= UCSSEL_3; // SMCLK
UCA0BR0 = 0x02; // /2
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
P1OUT &= ~0x80; // p1.7 CSN low
P2OUT &= ~0x08; // p2.3 Now with SPI signals initialized,
P2OUT |= 0x08; // reset slave
//The ISR for SPI RX Date/Tx Data
for(i=50;i>0;i–); // Wait for slave to initialize
// __bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
}
//初始化与Flsah连接的spi
void Init_CC1120_SpiFlash()
{
P2DIR |= BIT4; //CS_N ouput
P3SEL |= BIT0+BIT1; // P3.0,1,2 option select
P3SEL |= BIT2; // P3.2 clk
UCB0CTL1 |= UCSWRST; // **Put state machine in reset**
UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB+UCMODE0; // 4-pin, 8-bit SPI slave,
// Clock polarity high, MSB
UCB0CTL1 |= UCSSEL_2; // SMCLK
// UCB0BR0 = 0x00; // /2
// UCB0BR1 = 0; //
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
}
kqian0327:
你好,
你有截取的波形吗?
是两个SPI都不能使用还是只开启一个是ok的,同时开启才会有问题呢?
feng wang6:
回复 kqian0327:
单独开启任何一个都是ok的,同时开启都没法用了
然后我尝试两个SPI配置不同的时钟源也没法一起工作,注释掉任何一个SPI的时钟源配置,另一个就能正常使用。
kqian0327:
回复 feng wang6:
你好,
如果两个SPI模块是使用的不同的时钟源呢?
feng wang6:
回复 kqian0327:
我尝试两个SPI用不同的时钟源也不能同时工作