您好!
我想在两个 MSP430FR2355之间累积一个 SPI 通信。 我有一个主微控制器和五个从微控制器(所有微控制器均为 MSP430FR2355)。
我的主器件在3Wire 中进行 SPI 配置、我使用5个 IO 为芯片选择正确的从器件。 所有从器件都采用4线配置。
我的问题如下:
使用从 SPI (芯片选择低电平有效)的 MODE_2时、我无法发送和接收任何数据。 但是、当我使用 MODE_1 (芯片选择高电平有效)时、我可以发送和接收数据。 我的 IO 连接到 STE 引脚保持高电压在1.6V、即使我将 IO 配置为低电平。
使用这种类型的微控制器是否可以将 STE 连接到 IO?
//SLAVE SPI #include <msp430.h> #include "gpio.h" int main(void) { WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer //Configuration SPI pins on Hardawre P4SEL0 |= BIT0 | BIT1 | BIT2 | BIT3; // set 4-SPI pin as second function GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN3); //indication alimentation GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN3); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4); //indication reception GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); UCA1CTLW0 |= UCSWRST; // **Put state machine in reset** UCA1CTLW0 |= UCSYNC|UCMSB|UCMODE_1|UCSTEM; // 3-pin, 8-bit SPI slave // Clock polarity high, MSB UCA1CTLW0 |= UCSSEL__SMCLK; // ACLK UCA1BR0 = 0x02; // BRCLK = ACLK/2 UCA1BR1 = 0; // UCA1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine** PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings UCA1IE |= UCRXIE; // Enable TX interrupt __bis_SR_register(GIE); // Enter LPM0, enable interrupts } #pragma vector=USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) { while (!(UCB1IFG&UCTXIFG)); // USCI_B1 TX buffer ready? UCA1TXBUF = UCA1RXBUF; // Echo received data GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN4); }
//MASTER SPI #include <msp430.h> #include "gpio.h" /** * main.c */ //3.6 CS //UCA1 SPI unsigned char TXData; unsigned char RXData; // Holds TX data int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer P4SEL0 |= BIT3 | BIT2 | BIT1; // set 3-SPI pin as second function GPIO_setAsOutputPin(GPIO_PORT_P3, GPIO_PIN6); GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN3); UCA1CTLW0 |= UCSWRST; // **Put state machine in reset** UCA1CTLW0 |= UCMST|UCSYNC|UCMSB; // 3-pin, 8-bit SPI master // Clock polarity high, MSB UCA1CTLW0 |= UCSSEL__SMCLK; // Select SMCLK UCA1BR0 = 0x02; // BRCLK = SMCLK/2 UCA1BR1 = 0; // UCA1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine** TXData = 0x01; // Holds TX data PM5CTL0 &= ~LOCKLPM5; GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN3); //GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN6); while(1) { UCA1IE |= UCTXIE; // Enable TX interrupt __bis_SR_register(GIE); // enable global interrupts, enter LPM0 __no_operation(); // For debug,Remain in LPM0 __delay_cycles(10000); // Delay before next transmission TXData++; // Increment transmit data } } #pragma vector=USCI_A1_VECTOR __interrupt void USCI_A1_ISR(void) { switch(__even_in_range(UCA1IV,USCI_SPI_UCTXIFG)) { case USCI_NONE: break; // Vector 0 - no interrupt case USCI_SPI_UCRXIFG: RXData = UCA1RXBUF; UCA1IFG &= ~UCRXIFG; break; case USCI_SPI_UCTXIFG: GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_PIN6); UCA1TXBUF = TXData; // Transmit characters GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN6); UCA1IE &= ~UCTXIE; break; default: break; } }