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: Launchpad uses SPI problem

Part Number: MSP432P401R

Hi ,

I use the spi of the Launchpad to connect to the MAX7219.

This is my hardware connection:

I am using three pins p9.4, p9.5 and p9.7.

Below is my source code.

#include "msp.h"

#include <stdint.h>

#include "Clock.h"

#include "string.h"

#include "driverlib.h"

void SPI_INIT(void)

{

    EUSCI_A3->CTLW0 = 0x0001;             // hold the eUSCI module in reset mode

    EUSCI_A3->CTLW0 = 0xAD83;  //a

    EUSCI_A3->BRW = 120;

     // modulation is not used in SPI mode, so clear UCA3MCTLW

    EUSCI_A3->MCTLW = 0;

    P9->SEL0 |= 0xB0;

    P9->SEL1 &= ~0xB0;// configure P9.7, P9.5, and P9.4 as primary module function

 

   EUSCI_A3->CTLW0 &= ~0x0001;           // enable eUSCI module

    EUSCI_A3->IE &= ~0x0003;              // disable interrupts

}

void Write_Max7219_byte(uchar DATA)

{

    while(EUSCI_A3->STATW & 0x01); 

    while((EUSCI_A3->IFG & 0x02))

    EUSCI_A3->TXBUF = DATA;

}

void Write_Max7219(uchar address,uchar dat)

{

    Write_Max7219_byte(address);           

    Write_Max7219_byte(dat);               

}

void Init_MAX7219(void)

{

    Write_Max7219(0x09, 0x00);      

    Write_Max7219(0x0a, 0x03);      

    Write_Max7219(0x0b, 0x07);      

    Write_Max7219(0x0c, 0x01);       

}

void clear(void)

{

    Write_Max7219(0x01,0x00);

    Write_Max7219(0x02,0x00);

    Write_Max7219(0x03,0x00);

    Write_Max7219(0x04,0x00);

    Write_Max7219(0x05,0x00);

    Write_Max7219(0x06,0x00);

    Write_Max7219(0x07,0x00);

    Write_Max7219(0x08,0x00);

}

/**

 * main.c

 */

void main(void)

{

    unsigned char test_buf[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

    WDT_A_holdTimer();

    Clock_Init48MHz();

    SPI_INIT();

    uint i,j;

    Clock_Delay1ms(50);

    Write_Max7219(0x0f,0x01);

    Clock_Delay1ms(1000);

    Write_Max7219(0x0f,0x00);

    Clock_Delay1ms(50);

    Init_MAX7219();

    Clock_Delay1ms(50);

    clear();

    Clock_Delay1ms(1000);

    while(1){

    for(i = 0;i < 8;i++){

        Write_Max7219(i+1,test_buf[i]);

    }

    if(i == 8)

        i = 0;

    }

}

I do not use interrupts, directly manipulate registers to control data transmission.

But when I send the character array "test_buf", the first five data are ok, and the last three send past results errors.

When I execute to Write_Max7219 (6,0x04), the result from the digital tube is the execution of Write_Max7219 (6,0x04) and Write_Max7219 (8,0x06).

I suspect that after the TXBUF data is transferred to the transmit shift register, the shift register is not cleared when the next data is sent.

Because I used CCS debugging to see that the value of the TXBUF register is the same as what I wrote.

How can I tell if something is causing this error, or can I manually clear the transmit shift register to eliminate the effects of the shift register?

Thanks,

Better

  • Hello Better,

    It would be easy to debug if you use the Driverlib APIs from the SimpleLink MSP432P4 SDK. These APIs are tested by TI and customers so most of them might work without having to modify the registers directly.

    The examples using Driverlib APIs are in the folder "./examples/nortos/MSP_EXP432P401R/driverlib/ " of the SDK. Please use an example that is closest to you applications and modify it for your needs.

    Hope this helps!

    Thanks,

    Sai

  • Hello,

    You could clear the contents by resetting the peripheral.  I am a little concerned about the operation in the byte write routine.

    void Write_Max7219_byte(uchar DATA)
    
    {
    
        while(EUSCI_A3->STATW & 0x01); 
    
        while((EUSCI_A3->IFG & 0x02))
    
        EUSCI_A3->TXBUF = DATA;
    
    }

    When you write a value to the TXBUF and there is nothing in the shift register, then it will automatically move to the shift register and the TXIFG will be set again.  Can you change the logic of your function to wait in the while loop while the TXIFG is '0' and then move on to load the data?

    while (!(EUSCI_A3->IFG & EUSCI_A_IFG_TXIFG));

    Regards,

    Chris

**Attention** This is a public forum