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.

MSP430G2553: Drived 7 segment using max7219ENG but doesnt worked MSP430

Part Number: MSP430G2553

I couldnt find any example on ti forums for max7219 to drive 7 segment so i find a code works on PIC microcontroller. And i translate the code to msp430g2553. but nothing happened.here is the site (https://microcontrollerslab.com/max7219-interfacing-8-digit-7-segment-display-pic16f877a/).

This is my code:

#include "io430.h"

#define SPI_SIMO BIT2
#define SPI_CLK BIT4
#define SPI_CS BIT3 // Load or /CS


#define DECODE_MODE_REG 0x09
#define INTESITY_REG 0x0A
#define SCAN_LIMIT_REG 0x0B
#define SHUTDOWN_REG 0x0C
#define DISPLAY_TEST_REG 0x0F
//------------------------------------------------------------------------------
#define DISABLE_DECODE 0x00
#define DECODE_ALL 0xFF
#define BRIGHTNESS 0x0F
#define SCAN_LOW_NIBBLE 0x03
#define SCAN_ALL_DIGITS 0x0F
#define SHUTDOWN_MODE 0x00
#define NORMAL_OPERATION 0x01
#define DISABLE_TEST_MODE 0x00
#define ENABLE_TEST_MODE 0x01
void SPI_Init(void) //SPI initialization
{
UCA0CTL1 |= UCSWRST; // USCI in Reset State (for config)
// Leading edge + MSB first + Master + Sync mode (spi)
UCA0CTL0 = UCCKPH + UCMSB + UCMST + UCSYNC;
UCA0CTL1 |= UCSSEL_2; // SMCLK as clock source
UCA0BR0 |= 0x01; // SPI speed (same as SMCLK)
UCA0BR1 = 0;
P1SEL |= SPI_SIMO + SPI_CLK; // Set port pins for USCI
P1SEL2 |= SPI_SIMO + SPI_CLK;
UCA0CTL1 &= ~UCSWRST; // Clear USCI Reset State
}
void MAX7219_write(char reg1, char data1)
{
P1OUT &= ~(SPI_CS);
__delay_cycles(50);
UCA0TXBUF = reg1 ;
while (UCA0STAT & UCBUSY);
UCA0TXBUF = data1 ;
while (UCA0STAT & UCBUSY);
P1OUT |= SPI_CS;
}
void MAX7219_init()
{
SPI_Init();

MAX7219_write(DECODE_MODE_REG,DECODE_ALL);
MAX7219_write(INTESITY_REG,BRIGHTNESS);
MAX7219_write(SCAN_LIMIT_REG,SCAN_ALL_DIGITS);
MAX7219_write(SHUTDOWN_REG,NORMAL_OPERATION);
MAX7219_write(DISPLAY_TEST_REG,ENABLE_TEST_MODE);
MAX7219_write(DISPLAY_TEST_REG,DISABLE_TEST_MODE);
}
void Max7219Print(unsigned long Number, unsigned short NumberOfDigits)
{
long i;
for(i=1;Number>0||i-NumberOfDigits<=0;Number/=10,i++)
{
P1OUT &= ~(SPI_CS);
__delay_cycles(50);
UCA0TXBUF = i ;
while (UCA0STAT & UCBUSY);
UCA0TXBUF = Number%10 ;
while (UCA0STAT & UCBUSY);
P1OUT |= SPI_CS;
}
}

void Max7219DisplayOff()
{
P1OUT &= ~(SPI_CS);
__delay_cycles(50);
UCB0TXBUF = SHUTDOWN_REG;
while (UCA0STAT & UCBUSY);
UCB0TXBUF = DISABLE_DECODE;
while (UCB0STAT & UCBUSY);
P1OUT |= SPI_CS;
}

void Max7219DisplayOn()
{
P1OUT &= ~(SPI_CS);
__delay_cycles(50);
UCB0TXBUF = SHUTDOWN_REG;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = NORMAL_OPERATION;
while (UCB0STAT & UCBUSY);
P1OUT |= SPI_CS;
}

void Max7219UpdateIntensity(char OnValue)
{
if(OnValue>=0 && OnValue<=15)
{
P1OUT &= ~(SPI_CS);
__delay_cycles(50);
UCB0TXBUF = 0x0a;
while (UCB0STAT & UCBUSY);
UCB0TXBUF = OnValue;
while (UCB0STAT & UCBUSY);
P1OUT |= SPI_CS;
}
}
unsigned long i;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
P1DIR |= SPI_SIMO + SPI_CLK + SPI_CS;
P1OUT &= ~(SPI_CS); // MAX7221 Chip Select is inactive high
SPI_Init();
MAX7219_init();
Max7219DisplayOn();
__delay_cycles(100000);
MAX7219_init();
__delay_cycles(1000);

while(1)// loop forever
{
for(i=0;i<9999;i++)//Count From 0 To 99999 And Display on 8 Seven segemnts
{
Max7219Print(i,8);
__delay_cycles(1000);
}
}

}

  • Are you using a Launchpad? If so, be sure to remove the RXD/TXD jumpers from J101 ("bridge header").

    I'm not familiar with the MAX7219, but I don't see anything obviously wrong with your code. (It's easier to read if you paste it using Insert->Code.)

    Does DISPLAY_TEST_REG show anything? Maybe add a human-size delay between enabling and disabling it.

  • #include "io430.h"
    #include "in430.h"
    #define SPI_SIMO	BIT2
    #define SPI_CLK		BIT4
    #define SPI_CS		BIT3	// Load or /CS
    
    
    #define DECODE_MODE_REG     0x09
    #define INTESITY_REG        0x0A
    #define SCAN_LIMIT_REG      0x0B
    #define SHUTDOWN_REG        0x0C
    #define DISPLAY_TEST_REG    0x0F
    //------------------------------------------------------------------------------
    #define DISABLE_DECODE      0x00
    #define DECODE_ALL          0xFF
    #define BRIGHTNESS          0x0F
    #define SCAN_LOW_NIBBLE     0x03
    #define SCAN_ALL_DIGITS     0x07
    #define SHUTDOWN_MODE       0x00
    #define NORMAL_OPERATION    0x01
    #define DISABLE_TEST_MODE   0x00
    #define ENABLE_TEST_MODE    0x01
    void SPI_Init(void) //SPI initialization
    {
            UCA0CTL1 |= UCSWRST; 		// USCI in Reset State (for config)
    	// Leading edge + MSB first + Master + Sync mode (spi)
    	UCA0CTL0 = UCCKPH + UCMSB + UCMST + UCSYNC;
    	UCA0CTL1 |= UCSSEL_2; 		// SMCLK as clock source
    	UCA0BR0 |= 0x01; 		// SPI speed (same as SMCLK)
    	UCA0BR1 = 0;
    	P1SEL |= SPI_SIMO + SPI_CLK;	// Set port pins for USCI
    	P1SEL2 |= SPI_SIMO + SPI_CLK;
    	UCA0CTL1 &= ~UCSWRST; 		// Clear USCI Reset State
    }
    void MAX7219_write(char reg1, char data1)
    {
      P1OUT &= ~(SPI_CS);
      __delay_cycles(50);
      UCA0TXBUF  = reg1 ;
    while (UCA0STAT & UCBUSY);
      UCA0TXBUF  = data1 ;
      while (UCA0STAT & UCBUSY);
      P1OUT |= SPI_CS;
    }
    void MAX7219_init()
    {
      SPI_Init();
    
      MAX7219_write(DECODE_MODE_REG,DECODE_ALL);
      MAX7219_write(INTESITY_REG,BRIGHTNESS);
      MAX7219_write(SCAN_LIMIT_REG,SCAN_ALL_DIGITS);
      MAX7219_write(SHUTDOWN_REG,NORMAL_OPERATION);
      MAX7219_write(DISPLAY_TEST_REG,ENABLE_TEST_MODE);
      MAX7219_write(DISPLAY_TEST_REG,DISABLE_TEST_MODE);
    }
    void Max7219Print(unsigned long Number, unsigned short NumberOfDigits)
    {
      long i;
      for(i=1;Number>0||i-NumberOfDigits<=0;Number/=10,i++)
      {
      P1OUT &= ~(SPI_CS);
      __delay_cycles(50);
      UCA0TXBUF  = i ;
      while (UCA0STAT & UCBUSY);
      UCA0TXBUF  = Number%10 ;
     while (UCA0STAT & UCBUSY);
      P1OUT |= SPI_CS;
      }
    }
    
    void Max7219DisplayOff()
    {
      P1OUT &= ~(SPI_CS);
      __delay_cycles(50);
      UCB0TXBUF = SHUTDOWN_REG;
      while (UCA0STAT & UCBUSY);
      UCB0TXBUF = DISABLE_DECODE;
      while (UCB0STAT & UCBUSY);
      P1OUT |= SPI_CS;
    }
    
    void Max7219DisplayOn()
    {
      P1OUT &= ~(SPI_CS);
      __delay_cycles(50);
      UCB0TXBUF = SHUTDOWN_REG;
      while (UCB0STAT & UCBUSY);
      UCB0TXBUF = NORMAL_OPERATION;
      while (UCB0STAT & UCBUSY);
      P1OUT |= SPI_CS;
    }
    
    void Max7219UpdateIntensity(char OnValue)
    {
      if(OnValue>=0 && OnValue<=15)
      {
        P1OUT &= ~(SPI_CS);
      __delay_cycles(50);
      UCB0TXBUF = 0x0a;
      while (UCB0STAT & UCBUSY);
      UCB0TXBUF = OnValue;
      while (UCB0STAT & UCBUSY);
      P1OUT |= SPI_CS;
      }
    }
    unsigned long i;
    int main(void)
    {
       WDTCTL = WDTPW | WDTHOLD;
       BCSCTL1 = CALBC1_8MHZ;
       DCOCTL  = CALDCO_8MHZ;
       P1DIR |= SPI_SIMO + SPI_CLK + SPI_CS;
       P1OUT &= ~(SPI_CS); // MAX7221 Chip Select is inactive high
       SPI_Init();
       MAX7219_init();
        Max7219DisplayOn();
       __delay_cycles(100000);
       MAX7219_init();
      __delay_cycles(1000);
    
      while(1)// loop forever
      {
        for(i=0;i<99999999;i++)//Count From 0 To 99999999 And Display on 8 Seven segemnts
        {
           Max7219Print(i,4);
          __delay_cycles(1000);
        }
      }
           
    }

    Hello thank you for responding. İ did what you said, removed tx and rx and also supplied with better source. Now all digits and all segments are flashing. İ also debugged the code,go step by step. Each for loop blink all segments and all digits.  

    İ dont have much time for this project if  i cant make max7219 be worked i will use another method

  • Hi Hakan,

    When you are porting the code, maybe you need to consider some clock frequency differences.
    I think if you grab the PIC and MSP430 waveforms with an oscilloscope, it may help you diagnosis the problem.

    Thanks!

    Best Regards

    Johnson

  • Hello Johnson,

    Becuse of quarantine i cant reach devices like oscilloscope. And i dont think i am capaple of doing it. İ guess i will use a shift register or directly connect segments to the msp430.

    • Thanks you.
  • I ran across some gizmos on Amazon which package the max7219 with a display. The brand is ACEIRMC, but it looks the same as a number of other offers:

    https://www.amazon.com/gp/product/B08L7MGKSD

    One of these connected to a G2ET Launchpad running your code seemed to count just fine. I haven't checked power consumption but as I recall the G2ET can only supply about 60mA.

    Maybe wiring is the next thing to check?

    [Edit: I did notice a power-up thing: When I power up the LP+display, nothing appears, but if I then Reset the MCU it displays. I don't see anything about this in the datasheet, but it's something to watch for.]

  • Hi, because of we have to make a pcb for the project i cant use the device you said. İ already ordered two 75hc595 chip. One for segments another for digits. İ wrote the code if something goes wrong i will ask you again. Thanks. But i will try it later. maybe end of this semester:)

**Attention** This is a public forum