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.

MSP432P401R: Trouble with SPI communication to MAX7291 IC on MSP432 Launchpad and driverlib

Part Number: MSP432P401R

I am getting started with the driverlib on MSP432 Launchpad. 

Some background: My aim is to control the Common Cathode LED matrix with MSP432 Launchpad though MAX7219 IC.

Here's my code:

/*
 * -------------------------------------------
 *    MSP432 DriverLib - v3_21_00_05 
 * -------------------------------------------
 *
 * --COPYRIGHT--,BSD,BSD
 * Copyright (c) 2016, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * --/COPYRIGHT--*/
/******************************************************************************
 * MSP432 SPI - 3-wire Master Incremented Data
 *
 * This example shows how SPI master talks to SPI slave using 3-wire mode.
 * Incrementing data is sent by the master starting at 0x01. Received data is
 * expected to be same as the previous transmission.  eUSCI RX ISR is used to
 * handle communication with the CPU, normally in LPM0. Because all execution 
 * after LPM0 is in ISRs, initialization waits for DCO to stabilize against 
 * ACLK.
 *
 * Note that in this example, EUSCIB0 is used for the SPI port. If the user
 * wants to use EUSCIA for SPI operation, they are able to with the same APIs
 * with the EUSCI_AX parameters.
 *
 * ACLK = ~32.768kHz, MCLK = SMCLK = DCO 3MHz
 *
 * Use with SPI Slave Data Echo code example.
 *
 *                MSP432P401
 *              -----------------
 *             |                 |
 *             |             P4.3|-> Chip Select
 *             |                 |
 *             |             P1.6|-> Data Out (UCB0SIMO)
 *             |                 |
 *             |             P1.7|
 *             |                 |
 *             |             P1.5|-> Serial Clock Out (UCB0CLK)
 * Author: Timothy Logan
*******************************************************************************/
/* DriverLib Includes */
#include "driverlib.h"

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

/* Statics */
static volatile uint8_t RXData = 0;
static uint8_t TXData = 0;
static uint8_t ii = 0;

// MAX7219 SPI LED Driver
#define MAX7219_TEST 0x0F // in real code put into a .h file
#define MAX7219_BRIGHTNESS 0x0A // in real code put into a .h file
#define MAX7219_SCAN_LIMIT 0x0B // in real code put into a .h file
#define MAX7219_DECODE_MODE 0x09 // in real code put into a .h file
#define MAX7219_SHUTDOWN 0x0C // in real code put into a .h file


/* SPI Master Configuration Parameter */
const eUSCI_SPI_MasterConfig spiMasterConfig =
{
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
        3000000,                                   // SMCLK = DCO = 3MHZ
        500000,                                    // SPICLK = 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
};


int main(void)
{
    volatile uint32_t ii;

    /* Halting WDT  */
    WDT_A_holdTimer();
	
		/* 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);

    /* 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_enableInterrupt(INT_EUSCIB0);
    Interrupt_enableSleepOnIsrExit();
		
		/* SPI --> P4.3 = CS */
		GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN3);
    GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);
		
		/* Selecting P1.0 as LED */
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
		
		/* Delaying waiting for the module to initialize */
    for(ii=0;ii<100;ii++);
		
		/* SPI, put CS Low P4.3 and polling to see if the TX buffer is ready or busy */
    /*GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);
    TXData = 0x40;
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));
    SPI_transmitData(EUSCI_B0_BASE, TXData);
    TXData = 0x00;
    while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT)));
    SPI_transmitData(EUSCI_B0_BASE, TXData);
		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);*/
		
		
		// Run test
		// All LED segments should light up
    
		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS LOW
		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
		TXData = 0x0F;
		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send address.
		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
		TXData = 0x01;
		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send the value.      
		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);  //Finish transfer. CS HIGH
		
		GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0); //Set LED HIGH
		
		for (int j=0; j<400000; j++); //some delay
		
		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
		TXData = 0x0F;
		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send address.
		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
		TXData = 0x00;
		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send value.
		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);  //Finish transfer. CS HIGH
		
		GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0); //Set LED LOW
		
		for (int j=0; j<400000; j++); //some delay
		
		while(1){
			for (uint8_t i = 0; i < 0x10; ++i)
			{
				GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS LOW
				while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
				TXData = 0x01;
				SPI_transmitData(EUSCI_B0_BASE, TXData); // Send address.
				while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
				TXData = i;
				SPI_transmitData(EUSCI_B0_BASE, TXData); // Send value.
				GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);  //Finish transfer. CS HIGH
				//maxTransfer(0x01, i);
				for (int j=0; j<400000; j++); //some delay
			}
		}
		

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

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

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

        /* Delay between transmissions for slave to process information */
        for(jj=50;jj<50;jj++);
    }

}

All the LEDs in the matrix are lit up, other than that nothing happening. When I debugged, the code does not pass the line number 154. Hence the LED also didn't come to HIGH state. What's wrong with this code?

Connections:

Connections between MSP432 to MAX7219 (though a 3.3V to 5V Level Shifter
MSP432 MAX7219
5V VCC
GND GND
P4.3 CS (LOAD)
P1.5 CLK
P1.6 DIN

Connections between MAX7219 to Common Cathode LED Matrix
MAX7219 LED MATRIX (Pin Number)
SEG A 9
SEG B 14
SEG C 8
SEG D 12
SEG E 1
SEG F 7
SEG G 2
SEG DP 5
DIG 0 13
DIG 1 3
DIG 2 4
DIG 3 10
DIG 4 6
DIG 5 11
DIG 6 15
DIG 7 16
  • Hello,
    I believe the issue is due to a conflict between the second transmission and the polling for interrupts. You have two instances where you are polling the IFG before transmitting in the main loop. The first is precautionary to ensure that the buffer is clear and the second is not needed because you have interrupts enabled so that when the IFG occurs then the CPU will go to the interrupt handler. Also in your code you are using the API “enableSleepOnISRExit” which means that the CPU will go to sleep once the interrupt handler is complete.

    Regards,
    Chris
  • Hey Chris,

    Thanks a lot. Disabling the interrupt made the code to progress further. But I guess that the SPI Communication is not happening. Nothing on the LED matrix.

    Here my code:

    /*
     * -------------------------------------------
     *    MSP432 DriverLib - v3_21_00_05 
     * -------------------------------------------
     *
     * --COPYRIGHT--,BSD,BSD
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /******************************************************************************
     * MSP432 SPI - 3-wire Master Incremented Data
     *
     * This example shows how SPI master talks to SPI slave using 3-wire mode.
     * Incrementing data is sent by the master starting at 0x01. Received data is
     * expected to be same as the previous transmission.  eUSCI RX ISR is used to
     * handle communication with the CPU, normally in LPM0. Because all execution 
     * after LPM0 is in ISRs, initialization waits for DCO to stabilize against 
     * ACLK.
     *
     * Note that in this example, EUSCIB0 is used for the SPI port. If the user
     * wants to use EUSCIA for SPI operation, they are able to with the same APIs
     * with the EUSCI_AX parameters.
     *
     * ACLK = ~32.768kHz, MCLK = SMCLK = DCO 3MHz
     *
     * Use with SPI Slave Data Echo code example.
     *
     *                MSP432P401
     *              -----------------
     *             |                 |
     *             |             P4.3|-> Chip Select
     *             |                 |
     *             |             P1.6|-> Data Out (UCB0SIMO)
     *             |                 |
     *             |             P1.7|
     *             |                 |
     *             |             P1.5|-> Serial Clock Out (UCB0CLK)
     * Author: Timothy Logan
    *******************************************************************************/
    /* DriverLib Includes */
    #include "driverlib.h"
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdlib.h>
    #include <stdbool.h>
    
    /* Statics */
    static volatile uint8_t RXData = 0;
    static uint8_t TXData = 0;
    static uint8_t ii = 0;
    
    // MAX7219 SPI LED Driver
    #define MAX7219_TEST 0x0F // in real code put into a .h file
    #define MAX7219_BRIGHTNESS 0x0A // in real code put into a .h file
    #define MAX7219_SCAN_LIMIT 0x0B // in real code put into a .h file
    #define MAX7219_DECODE_MODE 0x09 // in real code put into a .h file
    #define MAX7219_SHUTDOWN 0x0C // in real code put into a .h file
    
    
    /* SPI Master Configuration Parameter */
    const eUSCI_SPI_MasterConfig spiMasterConfig =
    {
            EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
            3000000,                                   // SMCLK = DCO = 3MHZ
            500000,                                    // SPICLK = 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	
    };
    
    
    void send16BitData(uint8_t addr, uint8_t value){
    		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS LOW
    		//while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
    		TXData = addr;
    		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send address.
    		//while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
    		TXData = value;
    		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send value.
    		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);  //Finish transfer. CS HIGH
    //		for(ii=0;ii<100;ii++); //delay to provide a rising edge on the LOAD
    //		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);
    }
    
    
    int main(void)
    {
        volatile uint32_t ii;
    
        /* Halting WDT  */
        WDT_A_holdTimer();
    	
    		/* 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);
    
        /* 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_enableInterrupt(INT_EUSCIB0);
        //Interrupt_enableSleepOnIsrExit();
    		
    		/* SPI --> P4.3 = CS */
    		GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN3);
        GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);
    		
    		/* Selecting P1.0 as LED */
        GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    		
    		/* Delaying waiting for the module to initialize */
        for(ii=0;ii<100;ii++);
    
    		//Enable Mode B - decode mode
    		send16BitData(0x09, 0x00);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		//Use Lowest Intensity
    		send16BitData(0x0A, 0x03);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		// scan limit
    		send16BitData(0x0B, 0x07);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		//Turn on Chip
    		send16BitData(0x0C, 0x01);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED
    		
    		//Display test - disable
    		send16BitData(0x0F, 0x00); 
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		 unsigned char disp1[19][8]={
    			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Heart Pattern
    			0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 
    			0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x00, 0x00, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x00, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x40, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x60, 0x80, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x60, 0x90, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x60, 0x90, 0x88, 0x40, 0x40, 0x00, 0x00, 0x00, 
    			0x60, 0x90, 0x88, 0x44, 0x40, 0x00, 0x00, 0x00, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x00, 0x00, 0x00, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x00, 0x00, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x00, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x20, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x10, 0x60, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x08, 0x90, 0x60, 
    			0x60, 0x90, 0x88, 0x44, 0x44, 0x88, 0x90, 0x60, // Heart Pattern
    		 
    		};
    		
    		while(1){
    			for(int h=0;h<19;h++)
    			{
    				for(int k=1;k<9;k++)
    					send16BitData(k,disp1[h][k-1]);
    					for (int j=0; j<1000; j++); //some delay
    					GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    			} 
    		}
    		
    
        //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;
    
        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);
    
            /* Send the next data packet */
            SPI_transmitData(EUSCI_B0_BASE, ++TXData);
    
            /* Delay between transmissions for slave to process information */
            for(jj=50;jj<50;jj++);
        }
    
    }
    

    Should I try to use some other module base other than B0? Some people have used EUSCI_A0_MODULE and some other have used EUSCI_B0_MODULE but I am not able to find it in the documentation.

  • Solved by reducing the clock speed of SPI to 32khz. I am using the TXS0108E level shifter to level shift the SPI signals from MSP432 to MAX7219. Initially, in my code, the SPI Clock speed was 500KHz, for which it wasn't working. I am not sure which IC (MAX7219 or TXS0108E) could not handle the 500KHz speed. As per the datasheets both the ICs can handle more than 1MHz. Here's my final code:

    /*
     * -------------------------------------------
     *    MSP432 DriverLib - v3_21_00_05 
     * -------------------------------------------
     *
     * --COPYRIGHT--,BSD,BSD
     * Copyright (c) 2016, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    /******************************************************************************
     * MSP432 SPI - 3-wire Master Incremented Data
     *
     * This example shows how SPI master talks to SPI slave using 3-wire mode.
     * Incrementing data is sent by the master starting at 0x01. Received data is
     * expected to be same as the previous transmission.  eUSCI RX ISR is used to
     * handle communication with the CPU, normally in LPM0. Because all execution 
     * after LPM0 is in ISRs, initialization waits for DCO to stabilize against 
     * ACLK.
     *
     * Note that in this example, EUSCIB0 is used for the SPI port. If the user
     * wants to use EUSCIA for SPI operation, they are able to with the same APIs
     * with the EUSCI_AX parameters.
     *
     * ACLK = ~32.768kHz, MCLK = SMCLK = DCO 3MHz
     *
     * Use with SPI Slave Data Echo code example.
     *
     *                MSP432P401
     *              -----------------
     *             |                 |
     *             |             P4.3|-> Chip Select
     *             |                 |
     *             |             P1.6|-> Data Out (UCB0SIMO)
     *             |                 |
     *             |             P1.7|
     *             |                 |
     *             |             P1.5|-> Serial Clock Out (UCB0CLK)
     * Author: Timothy Logan
    *******************************************************************************/
    /* DriverLib Includes */
    #include "driverlib.h"
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdlib.h>
    #include <stdbool.h>
    
    /* Statics */
    static volatile uint8_t RXData = 0;
    static uint8_t TXData = 0;
    static uint8_t ii = 0;
    
    
    /* SPI Master Configuration Parameter */
    const eUSCI_SPI_MasterConfig spiMasterConfig =
    {
            EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
            32000,                                     // SMCLK = DCO = 32khz
            32000,                                     // SPICLK = 32khz
            EUSCI_B_SPI_MSB_FIRST,                     // MSB First
            EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,    // Phase
    				EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW, 
            EUSCI_B_SPI_3PIN                           // 3Wire SPI Mode
    				
    };
    
    
    void send16BitData(uint8_t addr, uint8_t value){
    		GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS LOW
    		TXData = addr;
    		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send address.
    		TXData = value;
    		SPI_transmitData(EUSCI_B0_BASE, TXData); // Send value.
    	
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS HIGH
    		for (int j=0; j<400; j++); //some delay
    	  GPIO_setOutputLowOnPin(GPIO_PORT_P4, GPIO_PIN3);  // CS LOW	
    	
    }
    
    
    int main(void)
    {
        volatile uint32_t ii;
    
        /* Halting WDT  */
        WDT_A_holdTimer();
    	
    		/* Selecting P 1.4 P1.5 P1.6 and P1.7 in SPI mode */
        GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                GPIO_PIN4 | GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    
        /* Configuring SPI in 3wire master mode */
        SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);
    
        /* Enable SPI module */
        SPI_enableModule(EUSCI_B0_BASE);
    		//EUSCI_B_SPI_enable(EUSCI_B0_BASE);
    
        /* Enabling interrupts */
        //SPI_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_SPI_RECEIVE_INTERRUPT);
        //Interrupt_enableInterrupt(INT_EUSCIB0);
        //Interrupt_enableSleepOnIsrExit();
    		
    		/* SPI --> P4.3 = CS */
    		GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN3);
        GPIO_setOutputHighOnPin(GPIO_PORT_P4, GPIO_PIN3);
    		
    		/* Selecting P1.0 as LED */
        GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
        GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
    		
    		/* Delaying waiting for the module to initialize */
        for (int j=0; j<400; j++); //some delay
    		
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE,EUSCI_B_SPI_TRANSMIT_INTERRUPT))); /* Polling to see if the TX buffer is ready */
    		
    //		// Run test
    //		// All LED segments should light up
    //    
    //		send16BitData(0x0F, 0x01);
    //		for (int j=0; j<40000; j++); //some delay
    //		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    
    		//Enable Mode B - decode mode
    		send16BitData(0x09, 0x00);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		//Use Lowest Intensity
    		send16BitData(0x0A, 0x0F);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		// scan limit
    		send16BitData(0x0B, 0x07);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    		//Display test - disable
    		send16BitData(0x0F, 0x00); 
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED
    		
    		//Turn on Chip - Shutdown Mode
    		send16BitData(0x0C, 0x01);
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED
    		
    		//No test
    		send16BitData(0x00, 0xFF); 
    		for (int j=0; j<400; j++); //some delay
    		GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); //Toggle LED 
    		
    
    		
    		int up[8] = {0x18, 0x0C, 0x06, 0xFF, 0xFF, 0x06, 0x0C, 0x18};
    		int left[8] = {0x0C, 0x1E, 0x3F, 0x0C, 0xFC, 0xFC, 0x00, 0x00};
    		int right[8] = {0x00, 0x00, 0xFC, 0xFC, 0x0C, 0x3F, 0x1E, 0x0C};
    		
    		
    		while(1){
    			for (int p=0x00; p<0x08; p++){	
    					send16BitData(p+1,up[p]);
    					for (int j=0; j<100; j++); //some delay
    			}
    			
    			for (int j=0; j<1000000; j++); //some delay
    			
    			for (int p=0x00; p<0x08; p++){	
    					send16BitData(p+1,left[p]);
    					for (int j=0; j<100; j++); //some delay
    			}
    			
    			for (int j=0; j<1000000; j++); //some delay
    			
    			for (int p=0x00; p<0x08; p++){	
    					send16BitData(p+1,right[p]);
    					for (int j=0; j<100; j++); //some delay
    			}
    			
    			for (int j=0; j<1000000; j++); //some delay
    			
    		}
    		
    		
    }
    
    //******************************************************************************
    //
    //This is the EUSCI_B0 interrupt vector service routine.
    //
    //******************************************************************************
    void EUSCIB0_IRQHandler(void)
    {
        uint32_t status = SPI_getEnabledInterruptStatus(EUSCI_B0_BASE);
        uint32_t jj;
    
        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);
    
            /* Send the next data packet */
            SPI_transmitData(EUSCI_B0_BASE, ++TXData);
    
            /* Delay between transmissions for slave to process information */
            for(jj=50;jj<50;jj++);
        }
    
    }
    

**Attention** This is a public forum