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.

MSP430FR6877: SPI Loopback stucks

Part Number: MSP430FR6877

I have an issue with SPI communication with MFRC522, so I am trying to use SPI listen mode to test my configuration, however when I do, SPI stucks on waiting for UCRXIFG which is never set. Should it be set in the listen mode?

My code for initialization:

//Initialize Master
EUSCI_B_SPI_initMasterParam param = {0};
param.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK;
param.clockSourceFrequency = CS_getSMCLK();
param.desiredSpiClock = 4000000;
param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
param.spiMode = EUSCI_B_SPI_3PIN;
EUSCI_B_SPI_initMaster(EUSCI_B1_BASE, &param);
UCB1STATW |= UCLISTEN;
//Enable SPI module
EUSCI_B_SPI_enable(EUSCI_B1_BASE);

My code for testing:

        unsigned char ByteCount= 0, dummy= 0, workingaddr= addr;

        P9OUT &= ~enpin; //CS
        
        //__delay_cycles(10);
        
        UCB1IFG &= ~UCRXIFG;
        EUSCI_B_SPI_transmitData(EUSCI_B1_BASE, addr);
        while   (!(UCB1IFG & UCRXIFG));
        dummy= EUSCI_B_SPI_receiveData(EUSCI_B1_BASE);
        
        while   ( ByteCount < len )
        {       workingaddr += inc;
                UCB1IFG &= ~UCRXIFG;
                EUSCI_B_SPI_transmitData(EUSCI_B1_BASE, workingaddr);
                while   (!(UCB1IFG & UCRXIFG));
                data[ByteCount]= EUSCI_B_SPI_receiveData(EUSCI_B1_BASE);
                ByteCount++;
        }
        
        //__delay_cycles(10);
        
        P9OUT |= enpin; //CS

  • I put this code on an FR6989 Launchpad, and it ran fine. If the SPI clock is enabled, every Tx should get an RXIFG, with or without UCLISTEN. I don't see any relevant errata for the FR6877, so I expect it would act the same.

    We must be doing something differently.

  • It seems that the loopback mode doesn't work on the simulator, when I tried it on the hardware, it worked.

    But can anyone help me with MFRC522, the SOMI line is always high.

    I raise its reset pin before I start the communication with it, but I am not sure what is wrong?

  • What board are you using? Specifically, how are the I2C and EA pins set? Seeing SOMI always high is consistent with I2C=EA=0 (UART-Tx). [Ref data sheet (Doc 112139 rev 3.9) Table 5].

  • Sorry for not showing the details.

    I am using MSP4306877 connected to MFRC522 through UCB1 in SPI 3-pins mode. The SPI configuration is as following (already mentioned above):

    //Initialize Master
    EUSCI_B_SPI_initMasterParam param = {0};
    param.selectClockSource = EUSCI_B_SPI_CLOCKSOURCE_SMCLK;
    param.clockSourceFrequency = CS_getSMCLK();
    param.desiredSpiClock = 4000000;
    param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
    param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
    param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
    param.spiMode = EUSCI_B_SPI_3PIN;
    EUSCI_B_SPI_initMaster(EUSCI_B1_BASE, &param);
    UCB1STATW |= UCLISTEN;
    //Enable SPI module
    EUSCI_B_SPI_enable(EUSCI_B1_BASE);

    The port configuration is as following:

      /* set as primary function */
      GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P3,(GPIO_PIN0|GPIO_PIN1|GPIO_PIN2),GPIO_PRIMARY_MODULE_FUNCTION);
      
      /* Configure RFID reset pin as output */
      GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN5);
      GPIO_setOutputLowOnPin(GPIO_PORT_P4,GPIO_PIN5);
      
      /* Configure RFID chip select pin as output */
      GPIO_setAsOutputPin(GPIO_PORT_P9,GPIO_PIN3);
      GPIO_setOutputHighOnPin(GPIO_PORT_P9,GPIO_PIN3);

    The communication sequence is as following:

    1- Set reset pin to high:

    P4OUT &= ~GPIO_PIN5;
    __delay_cycles(50);  //wait 50 micro for full-on shutdown
    P4OUT |= GPIO_PIN5;
    __delay_cycles(50000);  //wait 50 milliseconds for startup // Exit power down mode. This triggers a hard reset.

    2- Set command register to Idle:

        unsigned char dummy=0,i=0;
        P9OUT &= ~GPIO_PIN3; //set CS low to select chip
        
        while(UCB1STATW & UCBUSY);//make sure the bus is not in use
        UCB1TXBUF= (0x01<<1);
        while(!(UCB1IFG & UCTXIFG));//wait for room in tx bufer
        UCB1TXBUF= 0x10;
        while(UCB1STATW & UCBUSY);//wait for communication to complete
        dummy=UCB1RXBUF; //clear the rxready flag
        dummy++;
    
        P9OUT |= GPIO_PIN3; //set CS high to deselect chip

    3- I try to read any register after sending its address but it is always giving back high.

  • The loobpack is not enabled. This line was just for testing.

    UCB1STATW |= UCLISTEN;

  • What board are you using? Specifically, how are the I2C and EA pins set? Seeing SOMI always high is consistent with I2C=EA=0 (UART-Tx). [Ref data sheet (Doc 112139 rev 3.9) Table 5].

  • Sorry, I didn't realize your question about I2C and EA pins.

    I am not using a standard board where I2C and EA pins are left float, so can it work in SPI mode in that case? are there any solution without the need to update the hardware?

  • I don't see anything about internal pullups/pulldowns on those pins. Are they really not-connected to anything? Or could you connect them to your MCU and set them using GPIOs?

    Maybe a schematic (or even a photo) would help.

**Attention** This is a public forum