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.

reference code for configuring I2S using SPI on MSP432P411VIPZ

Hi,

i need to validate the ICS43434(Acoustic sensor) which is connected to MSP432P411VIPZ using I2S interface.

As we know that I2S interface is not available on MSP432P411VIPZ, i need to mimic the SPI to act as I2S interface.

if there is any reference code that can be used to mimic the SPI as I2S, will be very helpful.

with regards to the below given link: 

https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/547391?MSP432-I2S-implementation

what is the input given here?

whether this code can be used for mimic the SPI as I2S interface?, if yes, whether the project code is available to be shared?

Thank you,

Maniram

  • Hi Maniram,

    I do not think we have reference code for MSP432P411 that mimics the SPI to behave as an I2S interface. 

    You can follow the template in the above e2e post and the available resource at http://dev.ti.com/tirex/explore/node?node=AAZETqFnTWz.CIUEYs8whg__z-lQYNj__LATEST as a starting point. It also references the application note http://www.ti.com/lit/an/slaa449a/slaa449a.pdf for a possible approach to interface to a I2S sensor using SPI.

    Srinivas

  • hi Srinivas,

    thank you for the sharing the points, i had developed the code for configuring the I2S WRT the link https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/547391?MSP432-I2S-implementation 

    whether there are any register to set this particular clock high and low configurations?

    2. whether for the audio input can i use the SPI receive interrupt instead of a DMA interrupt?

    3. is there any example code where i can change the clock configurations, to set a particular frequency?

    for example: i want to set a sampling frequency 3.3024 and my source to be SMCLK, how toset this configuration?

    Thank you,

    Maniram

     

  • hi srinivas, 

    the below shared code is used to mimic the SPI to work as a I2S communication:

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

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

    /* Statics */

    static uint8_t TXData = 0x00;
    static DMA_ControlTable DMAControlTable[32];
    //![Simple SPI Config]
    /* SPI Master Configuration Parameter */
    const eUSCI_SPI_MasterConfig spiMasterConfig = {
    EUSCI_B_SPI_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
    12000000, // SMCLK = 12Mhz
    1500000, // SPICLK = 1.5Mhz
    EUSCI_B_SPI_MSB_FIRST, // MSB First
    EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, // Phase
    EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, // High polarity
    EUSCI_B_SPI_3PIN // 3Wire SPI Mode
    };
    //![Simple SPI Config]
    /*************************************
    * Interrupt routines declaration
    *************************************/
    void DMA_Interrupt();

    /************************************
    * Global variables
    ************************************/
    //Digital audio buffers, read/wrote by DMA
    int32_t AudioDataIn;
    //Data ready flag, to start audio processing
    bool AudioDataReady = false;

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

    /***********************************************
    * Clocking
    ***********************************************/
    //Pins
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(
    GPIO_PORT_PJ, GPIO_PIN3 | GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
    //Setting the external clock frequency
    CS_setExternalClockSourceFrequency(32000, 48000000);
    //Starting HFXT in non-bypass mode without a timeout. Before we start
    //we have to change VCORE to 1 to support the 48MHz frequency
    MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
    MAP_FlashCtl_setWaitState(FLASH_A_BANK0, 2);
    MAP_FlashCtl_setWaitState(FLASH_A_BANK1, 2);
    CS_startHFXT(false);
    //Initializing clock signals */
    MAP_CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //ACLK=32kHz
    MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //MCLK=48kHz
    MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_4); //SMCLK=12MHz

    /****************************************************
    * EUSCI_B0 SPI (for I2S interface)
    ****************************************************/
    //Pins
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(
    GPIO_PORT_P1, GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION); //MISO
    MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(
    GPIO_PORT_P1, GPIO_PIN5 | GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION); //SCLK, MOSI

    //SPI setup
    SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);

    //Enable SPI
    SPI_enableModule(EUSCI_A3_BASE);

    /* 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);

    /****************************************************
    * DMA (coupled with SPI to make I2S)
    ****************************************************/
    //Enable DMA module
    MAP_DMA_enableModule();
    MAP_DMA_setControlBase(DMAControlTable);
    //Assign channel 6 to EUSCI_A3_TX, channel 7 to EUSCI_A3_RX
    DMA_assignChannel(DMA_CH7_EUSCIB0RX3);

    //Set RX transfer
    DMA_setChannelControl(DMA_CH7_EUSCIB0RX3 | UDMA_PRI_SELECT,
    UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 | UDMA_ARB_1);

    //Assign DMA interrupt : INT1 to RX channel
    DMA_assignInterrupt(INT_DMA_INT1, 7);
    //Register interrupt to a defined subroutine
    DMA_registerInterrupt(INT_DMA_INT1, DMA_Interrupt);
    //Flag set by default, so we have to clear it
    DMA_clearInterruptFlag(7);
    while (1)
    {
    if (AudioDataReady == true)
    {
    //Reset flag
    AudioDataReady = false;

    }
    }
    }

    //** Interrupt routines */
    /* Completion interrupt for DMA */
    void DMA_Interrupt()
    {
    //Set flag for audio processing
    AudioDataReady = true;

    DMA_setChannelTransfer(
    DMA_CH7_EUSCIA3RX | UDMA_PRI_SELECT,
    UDMA_MODE_BASIC,
    (void*) MAP_SPI_getReceiveBufferAddressForDMA(EUSCI_B0_BASE),
    (void*) AudioDataIn, 4);
    //Everything is set up, we can enable the two DMA channels
    DMA_enableChannel(6);
    DMA_enableChannel(7);

    DMA_clearInterruptFlag(7);

    }

    1.here i am not getting how to change the SPI desired frequency 3.3024 Mhz?

    2.As i have dont have the board (launchpad MSP432P411), i require some code validation to be done:

    whether the DMA interrupt is configured correctly, which is configured on the channel 7, so that on the RX if there is any event the audio sample to be collected ?

    whether the AudioDataIn will have the audio samples?

    could please help me validating my code.

    Thank you,

    Maniram

**Attention** This is a public forum