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.

RTOS/MSP430F5529: how to add two spi driver

Part Number: MSP430F5529

Tool/software: TI-RTOS

Void MSP_EXP430F5529LP_isrDMA(UArg arg)
{
/* Call the SPI DMA function, passing the SPI handle used for WiFi */

SPI_serviceISR((SPI_Handle) &(SPI_config[1])); //how i can use SPI_serviceISR((SPI_Handle) &(SPI_config[0]))?????

}
///////////.cfg文件里增加

var hwiParams = new halHwi.Params();
hwiParams.arg = 0; //////////////how to change this ??????????????????????????????????
halHwi.create(50, "&MSP_EXP430F5529LP_isrDMA", hwiParams);
/////////////////////////
/*
* =============================== SPI ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(SPI_config, ".const:SPI_config")
#pragma DATA_SECTION(spiUSCIBDMAHWAttrs, ".const:spiUSCIBDMAHWAttrs")
#endif

#include <ti/drivers/SPI.h>
#include <ti/drivers/spi/SPIUSCIADMA.h>
#include <ti/drivers/spi/SPIUSCIBDMA.h>

SPIUSCIADMA_Object spiUSCIADMAObjects[MSP_EXP430F5529LP_SPICOUNT]; ///MSP_EXP430F5529LP_SPICOUNT =1
SPIUSCIBDMA_Object spiUSCIBDMAObjects[MSP_EXP430F5529LP_SPICOUNT];
uint8_t spiUSCIADMAscratchBuf[MSP_EXP430F5529LP_SPICOUNT];
uint8_t spiUSCIBDMAscratchBuf[MSP_EXP430F5529LP_SPICOUNT];
const SPIUSCIBDMA_HWAttrs spiUSCIBDMAHWAttrs[MSP_EXP430F5529LP_SPICOUNT] = {
{
.baseAddr = USCI_B0_BASE,
.clockSource = USCI_B_SPI_CLOCKSOURCE_SMCLK,
.bitOrder = USCI_B_SPI_MSB_FIRST,
.scratchBufPtr = &spiUSCIBDMAscratchBuf[0],
.defaultTxBufValue = 0,

/* DMA */
.dmaBaseAddr = DMA_BASE,
/* Rx Channel */
.rxDMAChannelIndex = DMA_CHANNEL_2,
.rxDMASourceTrigger = DMA_TRIGGERSOURCE_18,
/* Tx Channel */
.txDMAChannelIndex = DMA_CHANNEL_0,
.txDMASourceTrigger = DMA_TRIGGERSOURCE_19
}

};

const SPIUSCIADMA_HWAttrs spiUSCIADMAHWAttrs[MSP_EXP430F5529LP_SPICOUNT] = {
{
.baseAddr = USCI_A0_BASE,
.clockSource = USCI_A_SPI_CLOCKSOURCE_SMCLK,
.bitOrder = USCI_A_SPI_MSB_FIRST,
.scratchBufPtr = &spiUSCIADMAscratchBuf[0],
.defaultTxBufValue = 0,

/* DMA */
.dmaBaseAddr = DMA_BASE,
/* Rx Channel */
.rxDMAChannelIndex = DMA_CHANNEL_2,
.rxDMASourceTrigger = DMA_TRIGGERSOURCE_16,
/* Tx Channel */
.txDMAChannelIndex = DMA_CHANNEL_0,
.txDMASourceTrigger = DMA_TRIGGERSOURCE_17
}
};
const SPI_Config SPI_config[] = {
{
.fxnTablePtr = &SPIUSCIBDMA_fxnTable,
.object = &spiUSCIBDMAObjects[0],
.hwAttrs = &spiUSCIBDMAHWAttrs[0]
},
{
.fxnTablePtr = &SPIUSCIADMA_fxnTable,
.object = &spiUSCIADMAObjects[0],
.hwAttrs = &spiUSCIADMAHWAttrs[0]
},
// {NULL, NULL, NULL},
};

/*
* ======== MSP_EXP430F5529LP_initSPI ========
*/
void MSP_EXP430F5529LP_initSPI(void)
{
/*
* NOTE: TI-RTOS examples configure USCIB0 as either SPI or I2C. Thus,
* a conflict occurs when the I2C & SPI drivers are used simultaneously in
* an application. Modify the pin mux settings in this file and resolve the
* conflict before running your the application.
*/

/* SPI CLK */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN2);
/* MOSI/SIMO */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN0);
/* MISO/SOMI */
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN1);

/* SPI CLK */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN7);
/* MOSI/SIMO */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3, GPIO_PIN3);
/* MISO/SOMI */
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3, GPIO_PIN4);

SPI_init();
}

i am sure that sigle spi driver is right .But  how to use two at the same time?

  • In your application, you will use SPI_open(0, &params) and SPI_open(1, &params) to access the respective indices of SPI_config[].

    uint8_t spiUSCIADMAscratchBuf[4];
    uint8_t spiUSCIBDMAscratchBuf[4];
    
    const SPIUSCIBDMA_HWAttrs spiUSCIBDMAHWAttrs[MSP_EXP430F5529LP_SPICOUNT] = {
        {
            .baseAddr = USCI_B0_BASE,
            .clockSource = USCI_B_SPI_CLOCKSOURCE_SMCLK,
            .bitOrder = USCI_B_SPI_MSB_FIRST,
            .scratchBufPtr = spiUSCIBDMAscratchBuf,
            .defaultTxBufValue = 0,
    
            /* DMA */
            .dmaBaseAddr = DMA_BASE,
            /* Rx Channel */
            .rxDMAChannelIndex = DMA_CHANNEL_2,
            .rxDMASourceTrigger = DMA_TRIGGERSOURCE_18,
            /* Tx Channel */
            .txDMAChannelIndex = DMA_CHANNEL_0,
            .txDMASourceTrigger = DMA_TRIGGERSOURCE_19
        }
    };
    
    const SPIUSCIADMA_HWAttrs spiUSCIADMAHWAttrs[MSP_EXP430F5529LP_SPICOUNT] = {
        {
            .baseAddr = USCI_A0_BASE,
            .clockSource = USCI_A_SPI_CLOCKSOURCE_SMCLK,
            .bitOrder = USCI_A_SPI_MSB_FIRST,
            .scratchBufPtr = spiUSCIADMAscratchBuf,
            .defaultTxBufValue = 0,
    
            /* DMA */
            .dmaBaseAddr = DMA_BASE,
            /* Rx Channel */
            .rxDMAChannelIndex = DMA_CHANNEL_2,
            .rxDMASourceTrigger = DMA_TRIGGERSOURCE_16,
            /* Tx Channel */
            .txDMAChannelIndex = DMA_CHANNEL_0,
            .txDMASourceTrigger = DMA_TRIGGERSOURCE_17
        }
    };


    Note the change with spiUSCIADMAscratchBuf & spiUSCIBDMAscratchBuf. Per the documentation in SPIUSCI[AB]DMA.h:

    /*! Address of a scratch buffer of size uint32_t */
    uint8_t *scratchBufPtr;


    Derrick

  • thanks to your reply!now i konw how to add 2 spi.change the isr like this:
    void MSP_EXP430F5529LP_isrDMA(UArg arg)
    {


    SPIUSCIADMA_HWAttrs const *hwAttrsA;
    SPIUSCIBDMA_HWAttrs const *hwAttrsB;

    hwAttrsA = ((SPI_Handle)&(SPI_config[1]))->hwAttrs;
    hwAttrsB = ((SPI_Handle)&(SPI_config[0]))->hwAttrs;


    //Call the SPI DMA function, passing the SPI handle used for WiFi
    if(DMA_getInterruptStatus(hwAttrsA->txDMAChannelIndex) == DMA_INT_ACTIVE||
    DMA_getInterruptStatus(hwAttrsA->rxDMAChannelIndex) == DMA_INT_ACTIVE
    ){
    //DMA_clearInterrupt(hwAttrsA->txDMAChannelIndex);
    //DMA_clearInterrupt(hwAttrsA->rxDMAChannelIndex);
    //NOTE: PRINT CAN'T REMOVE AS DELAY
    System_printf("SPIA-SPI_serviceISR------------------\r\n");
    System_flush();
    SPI_serviceISR((SPI_Handle) &(SPI_config[0]));
    }
    if(DMA_getInterruptStatus(hwAttrsB->txDMAChannelIndex) == DMA_INT_ACTIVE||
    DMA_getInterruptStatus(hwAttrsB->rxDMAChannelIndex) == DMA_INT_ACTIVE
    ){
    //DMA_clearInterrupt(hwAttrsB->txDMAChannelIndex);
    //DMA_clearInterrupt(hwAttrsB->rxDMAChannelIndex);
    //NOTE: PRINT CAN'T REMOVE AS DELAY
    System_printf("SPIB-SPI_serviceISR------------------\r\n");
    System_flush();
    SPI_serviceISR((SPI_Handle) &(SPI_config[1]));
    }
    }

**Attention** This is a public forum