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.

Msp430 Launch pad with MAX7219 by SPI to control 7seg

Other Parts Discussed in Thread: MSP430G2231, MSP430G2553

iam trying to interface MAX7219 with msp430 g2231 by SPI protocol

i tried with this code but its not working can you help me..

this is my code..

#include

<msp430g2231.h>

#define

SDP8_LOAD      BIT6     // PORTB.1

void

spi(unsigned char cData)

{

/* Start transmission */

USISRL  = cData;

/* Wait for transmission complete */

while

(!(USISRL  & (1<<USIIFG)))

;

}

void

sdp8(unsigned char posn, unsigned char val)

{

   P1OUT &= ~SDP8_LOAD; 

// enable SPI

   spi(posn);

   spi(val);

   P1OUT |= SDP8_LOAD;  

// latch the data on rising edge

}

void

initsdp8(void)

{

    sdp8(0x0A, 0x07);  

/* high intensity */

    sdp8(0x0B, 0x07);  

/* scan limit set to digit 0 only, 0x07 for all digits*/

     sdp8(0x09, 0xFF);  

/* no decode (FF for decode all digits)*/

    sdp8(0x0C, 0x01);  

/* not shutdown */

   

//sdp8(0x0F, 0x01);   /* start test*/

  

//_delay_ms(2000);

   sdp8(0x0F, 0x00);  

/* stop test*/

}

 

void

main(void)

{

volatile unsigned int i;

  WDTCTL = WDTPW + WDTHOLD;                

// Stop WDT

 

  P1OUT = 0;

  P1OUT |= SDP8_LOAD;

  P1DIR |= SDP8_LOAD;

  USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE + USILSB;

// Port, SPI Master

  USICTL1 |= USIIE;                    

// Counter interrupt, flag remains set

  USICKCTL = USIDIV_4 + USISSEL_2;     

// /16 SMCLK

  USICTL &= ~USISWRST;                

// USI released for operation

 

//for (i = 0xFFF; i > 0; i--); // Time for slave to ready

  USICNT = 8;

 

   initsdp8();

  

while (1)

   {

  

//sdp8(0x01, 0x01);

    sdp8(0x01, 0x01);

      sdp8(0x02, 0x02);

      sdp8(0x03, 0x03);

      sdp8(0x04, 0x04);

      sdp8(0x05, 0x05);

      sdp8(0x06, 0x06);

      sdp8(0x07, 0x09);

     

//sdp8(0x08, 0x08); 

   }

}

 

thanks a lot...

  • So what is not working? What is it doing instead? Whyt do you expect it to do and what do you observe it doing?

    Simply saying "here is my code and it doesn't work" won't get you a useful answer.

  • Here is my code:

    Remember the Msp430 is powered at 3.3 and MAx7219 is powered at 5.

    The code works on the launchpad with the msp430g2553 on CCS 6

     

    #include <msp430.h>

     

    #define CS BIT0  //2.0 is CS

    #define MOSI BIT7  //1.7 is SPI MOSI

    #define SCLK BIT5  //1.5 is SPI clock

     

    void Init_MAX7219(void);

    void SPI_Init(void); //SPI initialization

    void SPI_Write(unsigned char);

    void SPI_Write2(unsigned char, unsigned char);

    void SPI_Write3(unsigned char, unsigned char, unsigned char);

     

    char led1[]={0x00,0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E};

    //driver one 8*8 dot matrix by SPI

     

    unsigned char disp1[36][8]={

    {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0

    {0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x10},//1

    {0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2

    {0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3

    {0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4

    {0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5

    {0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6

    {0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7

    {0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8

    {0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9

    {0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A

    {0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B

    {0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C

    {0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D

    {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E

    {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F

    {0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G

    {0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H

    {0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I

    {0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J

    {0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K

    {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L

    {0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M

    {0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N

    {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O

    {0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P

    {0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q

    {0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R

    {0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S

    {0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T

    {0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U

    {0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V

    {0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W

    {0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X

    {0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y

    {0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z

    };

     

     

    void SPI_Init(void) //SPI initialization

    {

           P2DIR |= CS;  //cs is output

        P1SEL |= MOSI + SCLK; //spi init

        P1SEL2 |= MOSI + SCLK; //spi init

        UCB0CTL1 = UCSWRST;

         UCB0CTL0 |= UCMSB + UCMST + UCSYNC + UCCKPH; // 3-pin, 8-bit SPI master

         UCB0CTL1 |= UCSSEL_2;                     // SMCLK

         UCB0BR0 = 10;                          // spi speed is smclk/10

         UCB0BR1 = 0;                              //

         UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

     

         __enable_interrupt(); // enable all interrupts

    }

     

    void SPI_Write2(unsigned char MSB, unsigned char LSB) //SPI write one byte

    {

     

           P2OUT &= ~CS;

           _delay_cycles(50);

           UCB0TXBUF = MSB ;

           while (UCB0STAT & UCBUSY);

           UCB0TXBUF = LSB ;

           while (UCB0STAT & UCBUSY);

           P2OUT |= CS;

    }

    void SPI_Write1(unsigned char MSB) //SPI write one byte

    {

     

           P2OUT &= ~CS;

           _delay_cycles(50);

           UCB0TXBUF = MSB ;

           while (UCB0STAT & UCBUSY);

           P2OUT |= CS;

    }

    void SPI_Write3(unsigned char MSB,unsigned char MMSB,unsigned char LSB ) //SPI write one byte

    {

     

           P2OUT &= ~CS;

           _delay_cycles(50);

           UCB0TXBUF = MSB ;

           while (UCB0STAT & UCBUSY);

           UCB0TXBUF = MMSB ;

           while (UCB0STAT & UCBUSY);

           UCB0TXBUF = LSB ;

           while (UCB0STAT & UCBUSY);

           P2OUT |= CS;

    }

     

     

    void Init_MAX7219(void)

    {

           SPI_Write2(0x09, 0x00);       //

           SPI_Write2(0x0A, 0x0F);       //

           SPI_Write2(0x0B, 0x0F);       //

           SPI_Write2(0x0C, 0x01);       //

           SPI_Write2(0x0F, 0x0F);       //

           SPI_Write2(0x0F, 0x00);       //

    }

    int main(void)

    {

           unsigned char i,j;

     

     

               WDTCTL = WDTPW | WDTHOLD;

     

           SPI_Init();

           _delay_cycles(100000);

           Init_MAX7219();

           _delay_cycles(1000);

           while(1)

           {

     

                         for(j=0;j<36;j++)

                         {

                               for(i=1;i<9;i++)

                               SPI_Write2(i,disp1[35-j][i-1]);

                               _delay_cycles(1000000);

                         }

          

           }

     

    }

     

     

     

     

**Attention** This is a public forum