ADS1299EEG FE Rev A與MSP432P401R的SPI傳輸

我是SPI 的初學者,看到官方CCS的範例都是SPI的3線傳輸的範例。

請問ADS1299EEG FE Rev A與MSP432P401R的SPI傳輸是不是只能使用4線傳輸?

他們之間的SPI傳輸又該如何撰寫?

有什麼方式可以讓我更快入手的嗎?

6 个回复

  • 您可以看一下ADS1229的数据手册内的说明 www.ti.com/.../ads1299.pdf

    The SPI-compatible serial interface consists of four signals: CS, SCLK, DIN, and DOUT.

    使用的是4线的SPI

    关于MSP432的SPI例程,您可以下载 www.ti.com/.../SIMPLELINK-MSP432-SDK

    后在其安装文件夹内找到

    <SDK_INSTALL_DIR>\examples\rtos\MSP_EXP432P401R\drivers\spimaster

    4线SPI的话可以使用 SPI_selectFourPinFunctionality 来使能

    If a post answers your question, please mark it with the "verify answer" button.

    若是回复解决了您的问题,请点击“是”确认答案。谢谢!

  • 回复 Susan Yang:

    SPI_selectFourPinFunctionality  這個如何使用?

    可以舉例說明一下嗎?

  • 回复 user5121970:

    您可以参考一下下面的链接,有详细的函数说明

    dev.ti.com/.../group__spi__api.html

    If a post answers your question, please mark it with the "verify answer" button.

    若是回复解决了您的问题,请点击“是”确认答案。谢谢!

  • 回复 Susan Yang:

    我現在使用兩塊MSP432P401R,我想設定成4線傳輸,並且要讓MASTER接收SLAVE傳送來的資料,可是我不知道我的錯誤在哪,CLOCK沒有任何訊號,我的代碼如下:


    MASTER:
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>

    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>

    /* Statics */
    //static volatile uint8_t RXData = 0;
    //static uint8_t TXData = 0;
    static volatile uint8_t transmitData = 0x01, receiveData = 0x00;
    //![Simple SPI Config]
    /* SPI Master Configuration Parameter */
    const eUSCI_SPI_MasterConfig spiMasterConfig =
    {
    EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
    3000000, // SMCLK = DCO = 3MHZ
    500000, // *** = 500khz
    EUSCI_B_SPI_MSB_FIRST, // MSB First
    EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase
    EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // High polarity
    //EUSCI_B_SPI_3PIN // 3Wire SPI Mode
    EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH // 4Wire SPI Mode
    };
    //![Simple SPI Config]

    int main(void)
    {
    /* Halting WDT */
    WDT_A_holdTimer();

    //![Simple SPI Example]
    /* Selecting P1.5 P1.6 and P1.7 in SPI mode */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
    GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    // GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
    // GPIO_PIN2,GPIO_PRIMARY_MODULE_FUNCTION);

    //CS
    GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN3);
    GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3);
    //CS

    /* Configuring SPI in 3wire master mode */
    SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);

    /* Enable SPI module */
    SPI_enableModule(EUSCI_B0_BASE);

    /* Enabling interrupts */
    SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
    Interrupt_enableSleepOnIsrExit();
    Interrupt_enableInterrupt(INT_EUSCIB0);

    //![Simple SPI Example]
    //TXData = 0x01;
    GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN3);
    /* Polling to see if the TX buffer is ready */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_RECEIVE_INTERRUPT)));

    /* Transmitting data to slave */
    //SPI_transmitData(EUSCI_B0_BASE, TXData);
    GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3);
    //Interrupt_enableMaster();
    PCM_gotoLPM0();
    __no_operation();
    }

    //******************************************************************************
    //
    //This is the EUSCI_B0 interrupt vector service routine.
    //
    //******************************************************************************
    void EUSCIB0_IRQHandler(void)
    {
    //uint32_t status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);
    //uint32_t jj;

    uint32_t status;

    status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);


    SPI_clearInterruptFlag(EUSCI_B0_BASE, status);

    if(status & EUSCI_B_SPI_RECEIVE_INTERRUPT)
    {
    /* USCI_B0 TX buffer ready? */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)));
    //GPIO_setOutputLowOnPin(GPIO_PORT_P5,GPIO_PIN2);
    //RXData = SPI_receiveData(EUSCI_B0_BASE);

    /* Send the next data packet */
    //SPI_transmitData(EUSCI_B0_BASE, ++TXData);
    // SPI_transmitData(EUSCI_B0_BASE, transmitData++);

    /* Delay between transmissions for slave to process information */
    //for(jj=50;jj<50;jj++);
    receiveData = SPI_receiveData(EUSCI_B0_BASE);
    //GPIO_setOutputHighOnPin(GPIO_PORT_P5,GPIO_PIN2);
    }

    }



    SLAVE:
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>

    /* Statics */
    //static volatile uint8_t transmitData = 0x01, receiveData = 0x00;
    static volatile uint8_t RXData = 0;
    static uint8_t TXData = 0;
    /* SPI Slave Configuration Parameter */
    const eUSCI_SPI_SlaveConfig spiSlaveConfig =
    {
    EUSCI_B_SPI_MSB_FIRST, // MSB First
    EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT, // Phase
    EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // Normal Polarity
    //EUSCI_B_SPI_3PIN // 3wire mode
    EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH, // 4線SPI模式

    };

    int main(void)
    {
    /* Stop watchdog timer */
    WDT_A_holdTimer();

    /* Selecting P1.1 P1.2 and P1.3 in SPI mode */
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
    GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    // GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
    // GPIO_PIN2,SPI_selectFourPinFunctionality );
    //CS
    GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN3);
    GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3);
    //CS
    /* Initialize slave to MSB first, inactive high clock polarity and
    * 3 wire SPI */
    SPI_initSlave(EUSCI_B0_BASE, &spiSlaveConfig);

    /* Enable the SPI module */
    SPI_enableModule(EUSCI_B0_BASE);

    /* Enable Receive interrupt */
    SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
    Interrupt_enableSleepOnIsrExit();
    Interrupt_enableInterrupt(INT_EUSCIB0);

    //![Simple SPI Example]
    GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN3);
    TXData = 0x01;

    /* Polling to see if the TX buffer is ready */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));

    /* Transmitting data to slave */
    SPI_transmitData(EUSCI_B0_BASE, TXData);

    Interrupt_enableMaster();
    GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN3);
    PCM_gotoLPM0();
    __no_operation();

    }

    //******************************************************************************
    //
    //This is the EUSCI_B0 interrupt vector service routine.
    //
    //******************************************************************************
    void EUSCIB0_IRQHandler(void)
    {
    //uint32_t status;
    uint32_t status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);
    uint32_t jj;

    //status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);
    //SPI_clearInterruptFlag(EUSCI_B0_BASE, status);

    if(status & EUSCI_B_SPI_RECEIVE_INTERRUPT)
    {
    /* USCI_B0 TX buffer ready? */
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_B_SPI_TRANSMIT_INTERRUPT)));

    // RXData = SPI_receiveData(EUSCI_B0_BASE);
    /* Transmit data to master */
    //SPI_transmitData(EUSCI_B0_BASE, transmitData++);
    SPI_transmitData(EUSCI_B0_BASE, ++TXData);

    //Receive data from master
    //receiveData = SPI_receiveData(EUSCI_B0_BASE);
    for(jj=50;jj<50;jj++);

    }
    }
  • 回复 user5121970:

    代码太长,就不一一看了,CLOCK沒有任何訊號,说明你的SPI外设没有初始化完成,你是否用官方的代码例程进行了测试呢?这样可以找到你代码的错误在哪里。

    苦行僧。

  • 回复 xyz549040622:

    範例程式碼主要是MSTER發送資料給SLAVE
    我的代碼是將SLAVE發送資料給MASTER接收
    我只有將兩個官方範例代碼乎鄉修改而已
    我最後的目的是要MASTER接收SLAVE傳送的資料