Atmega128 : 7 seg Led Display showing Invalid Data

Go To Last Post
32 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all Manish Here,
I am New to this forum.I am working With Atmega128 Interfaced with max7219 decoder and then decoder is interfaced with seven segment Display.I have done all Initialization and configuration.Data is coming on Display but it is invalid so please guide me regarding that.Following is my code

#include
#include
#include

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));

SPCR |= (1<<SPE) | (1<<MSTR);

//SPCR &= ~(BV(2)|BV(6)|BV(7));

}
void spi_select(uint8_t en)
{
if(en)
PORTB &= (~(1 << PIN_SS));
else
PORTB |= 1<< PIN_SS;

}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
if(en)
PORTB &= (~(1 << PIN_SCK));
else
PORTB |= 1<< PIN_SCK;
}
void spi_rw(unsigned char value)
{

SPDR = value;

// while((SPSR & (1<<7))==0);
}

void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
spi_select(1);
spi_rw(data_reg);
spi_rw(data);
spi_select(0);

}
void max7219_Init(void)
{
/* max7219 register cofiguration. */
Decoder_Write_Data( 0x0C , 0x01 ) ; // normal mode
Decoder_Write_Data( 0x0A , 0x0f ) ; // set intensity 0x00 - 0x0F
Decoder_Write_Data( 0x0B , 0x07 ) ; // scan digits 0,1
Decoder_Write_Data( 0x09 , 0x00 ) ; // no decoding
}

int main(void)
{
//unsigned char value=0xFF;
unsigned char data_reg = 0x01,data = 0x30;
max7219_Init();
spi_init();

while(1)
{

Decoder_Write_Data( data_reg, data);
_delay_ms(500);
Decoder_Write_Data( data_reg,0);
_delay_ms(500);
Decoder_Write_Data( data_reg,1);
_delay_ms(500);
Decoder_Write_Data( data_reg,2);
_delay_ms(500);
Decoder_Write_Data( data_reg,3);
_delay_ms(500);
Decoder_Write_Data( data_reg,4);
_delay_ms(500);
Decoder_Write_Data( data_reg,5);
_delay_ms(500);
Decoder_Write_Data( data_reg,6);
_delay_ms(500);
Decoder_Write_Data( data_reg,7);
_delay_ms(500);
Decoder_Write_Data( data_reg,8);
_delay_ms(500);
//_delay_ms(500);
//value= ~ (value);
}

return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the fourm,
Please go back and edit your post to include "code" buttons around code to format it correctly.
The please explain what display invalid means, i.e. what were you expecting to happen, and what did happen?

jc

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

manish2789 wrote:
Hello all Manish Here,
I am New to this forum.I am working With Atmega128 Interfaced with max7219 decoder and then decoder is interfaced with seven segment Display.I have done all Initialization and configuration.Data is coming on Display but it is invalid so please guide me regarding that.Following is my code

#include 
#include 
#include 

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
	DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));
	
	SPCR |= (1<<SPE) | (1<<MSTR);

//SPCR &= ~(BV(2)|BV(6)|BV(7));
	
}
void spi_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SS));
	else
	PORTB |= 1<< PIN_SS;


	
}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SCK));
	else
	PORTB |= 1<< PIN_SCK;
}
void spi_rw(unsigned char value)
{
	
	SPDR = value;
	
//	while((SPSR & (1<<7))==0);
}


void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
		spi_select(1);
		spi_rw(data_reg);
		spi_rw(data);
		spi_select(0);
	
}
void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0C , 0x01 ) ;   // normal mode
    Decoder_Write_Data( 0x0A , 0x0f ) ;   // set intensity 0x00 - 0x0F
    Decoder_Write_Data( 0x0B , 0x07 ) ;   // scan digits 0,1
    Decoder_Write_Data( 0x09 , 0x00 ) ;   // no decoding
}


int main(void)
{
	//unsigned char  value=0xFF;
	unsigned char data_reg = 0x01,data = 0x30; 
	max7219_Init();
	spi_init();
	
	while(1)
	{
	  
		Decoder_Write_Data( data_reg, data);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,0);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,1);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,2);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,3);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,4);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,5);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,6);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,7);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,8);
        _delay_ms(500);
		//_delay_ms(500);		
		//value= ~ (value);
	}

	return 0;
}


change your function to:

unsigned char spi_rw(unsigned char value)
{
   
   SPDR = value;
   
   while((SPSR & (1<<7))==0);
   return SPDR;
}

Note that you need to connect your wires to the MAX7219 to make it work.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

<br />
 Thanks a lot for your valuable replies</p>
<p>I have changed<br />
void max7219_Init(void)<br />
{<br />
    /* max7219  register cofiguration. */<br />
    Decoder_Write_Data( 0x0C , 0x01 ) ;   // normal mode<br />
    Decoder_Write_Data( 0x0A , 0x05 ) ;   // set intensity 0x00 - 0x0F<br />
    Decoder_Write_Data( 0x0B , 0x02 ) ;   // scan digits 0,1<br />
    Decoder_Write_Data( 0x09 , 0x0f ) ;   // all decoding<br />
}<br />
But it showing all segment glowing which result was same for previous code.<br />
so what i need to modify in code .?</p>
<p>I have  changed void spi_rw to  unsigned char spi_rw<br />
 unsigned char spi_rw(unsigned char value)<br />
{</p>
<p>	SPDR = value;</p>
<p>	while((SPSR & (1<<7))==0);<br />
return SPDR; </p>
<p>}<br />
<br />
But i have one query again that how should i modify<br />
following function <br />
[code]void Decoder_Write_Data(unsigned char data_reg,unsigned char data )<br />
{<br />
		spi_select(1);<br />
		spi_rw(data_reg);<br />
		spi_rw(data);<br />
		spi_se
lect(0);

}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My initialisation for a MAX7219 display:

	sdp8(0x0a, 0x01);	/* low intensity */
	sdp8(0x0b, 0x07);	/* scan limit */
	sdp8(0x09, 0xff);	/* decode each digit */
	sdp8(0x0c, 0x01);	/* not shutdown */
	sdp8(0x0f, 0x00);	/* display test */

i.e. your code looks fine to me.

Note that the MAX7219 starts with full intensity "8.8.8.8.8.8.8.8." as default. So I suspect that you have not connected your hardware correctly.

If you get different digits, say so.

Incidentally, if you want to post code, simply select it with your mouse. Then press the CODE button. Press the PREVIEW button to see what it looks like.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks again for your valuable response.

But till I'm having having few doubts.so what i feel that 1st i will note all Initialization and Configuration and Afterwords I will note my results and quires one by one.

Actually I'm learning AVR so asking so many questions. Extremely sorry For That .

......Initialization ,Configuration ............

1)I am working on atmega128 on Avr studio 4 using WinAVr.
2)I have Interface atmega128 with max7219 decoder and max7219 is connected to & segment Display.
3) I have connected only one Common cathod Seven segment display to max7219. I done Hardware connection as mentioned in max7219 datasheet.which I will be attaching with this.

4) I have connected common pins of 7 segment to ground and Dig0(Digit 0) pin of decoder to connected to 8(common) pin of segment display as i have connected only one LED Display.

5)Address of Dig0 p mentioned 0x01 in datasheet of max7219 so I have take care of that address during Programming.

.....................Results.............
1) when I have load the program then its showing "8."
2) I have tried to change the configuration register of max7219 as follows but it showing same result.

void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0C , 0x01 ) ;   // normal mode
    Decoder_Write_Data( 0x0A , 0x01 ) ;   // set intensity 0x01
    Decoder_Write_Data( 0x0B , 0x02) ;   // scan digits 0,1,2
    Decoder_Write_Data( 0x09 , 0x0f ) ;   // no decoding
}

But it showing same result.

.................questions and queries............
1)Is may hardware connection appropriate...?
2)Is my code fine...?
3)if I have changed configuration but why till it showing same result..?
4)I feel data is fetching But it is not what I'm sending.i.e if I'm sending 0 on address 0x01 till it showing all segment glowing.why it is so..?
5)is here any issue of clk synchronization to get valid data..?
6)How should i proceed further ..?

........................My code.....................
#

include 
#include 
#include 

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
	DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));
	
	SPCR |= (1<<SPE) | (1<<MSTR);

//SPCR &= ~(BV(2)|BV(6)|BV(7));
	
}
void spi_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SS));
	else
	PORTB |= 1<< PIN_SS;


	
}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SCK));
	else
	PORTB |= 1<< PIN_SCK;
}
void spi_rw(unsigned char value) 
{
	
	SPDR = value;
	
	while((SPSR & (1<<7))==0);
 

}


void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
		spi_select(1);
		spi_rw(data_reg);
		spi_rw(data);
		spi_select(0);
	
}
void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0C , 0x01 ) ;   // normal mode
    Decoder_Write_Data( 0x0A , 0x01 ) ;   // set intensity 0x00 - 0x0F
    Decoder_Write_Data( 0x0B , 0x07 ) ;   // scan digits 0,1
    Decoder_Write_Data( 0x09 , 0xff ) ;   // all decoding
}


int main(void)
{
	//unsigned char  value=0xFF;
	unsigned char data_reg = 0x01;
	max7219_Init();
	spi_init();
	
	while(1)
	{
	  
		
		Decoder_Write_Data( data_reg,0);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,1);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,2);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,3);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,4);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,5);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,6);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,7);
		_delay_ms(500);
		Decoder_Write_Data( data_reg,8);
               _delay_ms(500);
		//_delay_ms(500);		
		//value= ~ (value);
	}

	

return 0;
}

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Waiting for any helpful reply...it will help me to proceed further.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll have to wait until europe and usa come online - also note it is Christmas, so many will be doing other things. In the meantime there are plenty of things you can check.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some advice: Please don't use silly colours. especially ones that are difficult to read.

I changed your code as follows and ran it on a real mega128 with a real MAX7219 8-digit display:

int main(void)
{
   //unsigned char  value=0xFF;
   unsigned char data_reg = 0x01;
   spi_init();
   max7219_Init();
//   spi_init();
   ...

As you can see, you should call spi_init before the max7219_init().

Yes, it cycles digit #0 through 0 .. 9
I get random values on the other 7 displays.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks again.
I have changed the code as suggested.and send digit 1 on Display.it work fine.But after I have updated code and send 2,3,4,5,6,7 respectively but for this i will not get any result on LED display.
I tried to find reason using Debugging but can not get any clue.why it so..?
What are all the thing i need to update in my code..?

suppose I want to display 1,2,3,4 continuously so how should the code..?
Please guide me regarding that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am confused. You appear to have written your code quite well. So I assume that you understand C quite well.

    Decoder_Write_Data(1, 4);   //4 on display #1
    Decoder_Write_Data(1, 5);   //5 on display #1
    Decoder_Write_Data(3, 4);   //4 on display #3
    Decoder_Write_Data(7, 9);   //9 on display #7
    for (uint8_t n = 1; n < 5; n++)
        Decoder_Write_Data(n, n);   //show 4321
    for (uint8_t n = 1; n < 5; n++)
        Decoder_Write_Data(5-n, n);   //show 1234

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

manish2789 colouring your text doesn't do much for readability but the following helps https://www.avrfreaks.net/index.p...

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot David.
Actually I have Verified my C code many times But even though Placing data into infinite while loop it won't show continuous data.let it appropriate or not.
so I had asked that question.

Now I have Updated My code after verified many times.But I didn't get expected results.

so please guide me that till I need to change the code..?

#include 
#include 
#include 

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
	DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));
	
	SPCR |= (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<< SPR0) ;


	
}
void spi_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SS));
	else
	PORTB |= 1<< PIN_SS;


	
}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SCK));
	else
	PORTB |= 1<< PIN_SCK;
}
unsigned char spi_rw(unsigned char value) 
{
	
	SPDR = value;
	
	while((SPSR & (1<<7))==0);
 return SPDR;

}


void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
		spi_select(1);
		spi_rw(data_reg);
		spi_rw(data);
		spi_select(0);
	
}
void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0C , 0x01 ) ;  
    Decoder_Write_Data( 0x0B , 0x07) ;
    Decoder_Write_Data( 0x0A , 0x0f ) ;  
    Decoder_Write_Data( 0x09 , 0xff ) ;
    Decoder_Write_Data( 0x0F , 0x00 ) ;   
}



int main(void)
{
	unsigned char data_reg = 0x01;
	spi_init();
	max7219_Init();

	
	while(1) 
	{
	  
		
		Decoder_Write_Data( data_reg,1);
		_delay_ms(500);
	 
	}

	return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
int main(void)
{
   unsigned char data_reg = 0x01;
   spi_init();
   max7219_Init();

   
   while(1)
   {
    
      
      Decoder_Write_Data( data_reg,1);
      _delay_ms(500);
   
   }

   return 0;
}

What do you expect? This code sends 1 to 1st digit.
0x01 is exactly the same constant value as 1.

I showed you how to use variables in an earlier reply. Your original code showed different digits but did not use variables. This should do the same using a loop:

    for (uint8_t n = 0; n < 10; n++) {
        Decoder_Write_Data(1, n);   //show 0-9 on 1st digit
        _delay_ms(500);
    }

Please don't post the same thing in different threads. Whereas silly colours for text is mildly irritating, duplicate posts actually annoy people.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks David.
1st i am apologizes about posting thread with different color. I will take care of it now onward.
I have again updated code as per your suggestion.

#include 
#include 
#include 

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
	DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));
	
	SPCR |= (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<< SPR0) | (1<<SPI2X);


	
}
void spi_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SS));
	else
	PORTB |= 1<< PIN_SS;


	
}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SCK));
	else
	PORTB |= 1<< PIN_SCK;
}
unsigned char spi_rw(volatile unsigned char value) 
{
	
	SPDR = value;
	
	while((SPSR & (1<<7))==0);
 return SPDR;

}


void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
		spi_select(1);
		spi_rw(data_reg);
		spi_rw(data);
		spi_select(0);
	
}
void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0C , 0x01 ) ;  
    Decoder_Write_Data( 0x0F , 0x00 ) ;     
    Decoder_Write_Data( 0x09 , 0xff ) ;  
    Decoder_Write_Data( 0x0A , 0x0f ) ;  
    Decoder_Write_Data( 0x0B , 0x07) ;
   
  
}



int main(void)
{
	//unsigned char data_reg = 0x01;
	spi_init();
	max7219_Init();

	for (uint8_t n = 0; n < 10; n++) { 
        Decoder_Write_Data(1, n);   //show 0-9 on 1st digit 
        _delay_ms(500); 
    }
	/*while(1) 
	{
	  
		
		Decoder_Write_Data( data_reg,1);
		//_delay_ms(500);
	 
	}*/

	return 0;
}

But I'm getting strange results.
As I'm Using AVR studio 4 with WinAVR I will list all step what i perform and respective result.so it becomes simplified and easy to understand.

1)I had created project,written code,save it,then Buid+Run for 1st time then i get result as follows

1st iteration -> "1" and then after sometime "9" and then display become blank.

2)Then I have clean project i.e went to Build->clean.and again did Build+Run at that time I got following result
2nd iteration -> "E" and then after sometime "8."
and then display become blank.

3)I followed step 2 in may iterations so it get random results as below
3rd iteration -> "8" and then after sometime "e"
and then display become blank.

4th iteration -> "8" and then after sometime "1"
and then display become blank.

4th iteration -> "8" and then after sometime "1"
and then display become blank.

5th iteration -> "1" and then after sometime "E"
and then display become blank.

but actually code is same that i have loaded.

So is that problem of AvR studio or till my code is not appropriate.?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The explanation is quite simple. I bet that you have no 100nF capacitors and are using a breadboard.

The MAX7219 will respond to whatever commands you send to it. And noise is quite likely to be interpreted as commands.

How experienced are you with C language?
Do you own a pencil?

You can trace the operation of your program on paper.

In my experience with MAX7219 in an electrically noisy environment, I re-initialise the controller and refresh the display on a regular basis.

Note that an 8-digit display at full brightness takes a massive current. If the device gets reset it will revert to test mode at full brightness.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your Each reply learn me many new things thanks for that.
You are absolutely correct I'm using bread board with no 100uF.actually I dont aware that why it is needed..?
from your post it seem it require to filter noise.
Actually I am working with C since 1 year on linux platform .its 1st time I'm working with any IDE on windows.
But I will respect you suggestion and try to trace code on paper.
I will modify my code with Refreshing Display and with low intensity.
But only thing i need to make sure that is my code till write expect above two things.?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

100nF is 100 nanoFarad (0.1uF or 0.1 microFarad)
100uF is something completely different.

Actually, your MAX7219 will need both. 47uF as reservoir and 100nF for digital decoupling.

I note that the MAX7219 data sheet seems to omit the capacitors !

The AVR data sheet, app notes, dev boards, ... always have 100nF capacitors.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok Now from your comment I have analyse that
1)My code is quite correct.
2)I need to reduce/remove noise with MAX7219 using 100nf and 47uf capacitors.
But across which pins of max7219 capacitor should be connected..?
please suggest me any link or datasheet related to that.or suggest me 7 segment display with inbuilt decoder with SPI support.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First off, add proper 100nF capacitors to your AVR VCC/GND and AVCC/AGND.
Then add 100nF and 47uF across V+/GND on the MAX7219.

It is surprising just how tolerant the AVR is to glitches. Many people ignore the advice about local decoupling capacitors, and their projects 'work'.

In the old days before the USBASP, hobbyists used appalling LPT port adapters with long wires and no signal conditioning. 60% of posts here were all about "my LPT dongle does not work".

In practice, glitches on an SPI line are only critical on the SCK line. So if you remove ringing from SCK, everything seems to be ok.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a Lot David.I Have tried few things except clock ringing from sck. But Now it shows full Display ON when trying to load code.so I'm thinking to start from scratch.For that shall I create new ..? so I can note thing from schematic to program one by one.

Manish

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With any SPI device, you should use an external pull-up resistor on /CS pin. So the device is unselected when the AVR is not running. e.g. when being programmed.

Do you just own a single 7-segment?
You can buy 2-digit and 4-digit displays.
Obviously you need 8 x 1-digit or 2 x 4-digit parts to use the full power of your MAX7219.

And you can chain MAX7219s to drive 16, 24, 32, ... digits.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Connected 10k pull-up resistor on /CS pin.But nothing happened Different.
Manish

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where did you get your MAX7219 chips from?

If they came from China, via a well known online auction site, and were very very cheap - they may not be genuine and may not work properly.

How do I know - I bought some, to see if the price really was too good to be true - it was...they wouldn't initialise properly every time although once they did, they seemed to work OK. I had the full datasheet spec decoupling/smooothing capacitors in place (yes, they are not in the datasheet diagrams, but they are in the words), but it made no difference.

The seller feigned surprise and I got my money back - but they are in my parts drawer probably never to see a circuit ever again

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had bought this chip from local Indian Electronics shop.I'm not aware from where he bought.But its prices is 320 Indian rupees.
can you suggest any other Decoder chip with SPI support for Driving 7 LED display..?

Manish

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looking at the MAX7219 chip on my boards, the date codes have no + character. Otherwise, they look like the photos on Ebay. Note that my chips are from 2004-5.

Ebay also shows chips with a very different legend.

I see that MAX7219 from RS or Farnell is a lot more expensive than the Ebay "MAX7219".

All the same, I would expect the 'clone' chips to work. Just wire them properly and run proper software. Since you have a mega128, I assume that you have a properly soldered AVR on a proper pcb.

I ran your software on a real chip and it works.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

manish2789 wrote:
Can you suggest (any other) Decoder chip with SPI support for Driving 7 LED display..

AS1107 - pin compatible with MAX7219, a few more functions available, cheaper than Maxim

...but if you can't get a MAX7219 to work, you'll not get a AS1107 to work ;)

EDIT:Are you still getting random characters when programming the AVR even with 10K from /CS to Vcc - if you are, there is something electrically wrong somewhere

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot to all For your valuable responses.
Actually I'm trying on atmega128 evaluation board.Now I will try on properly soldered AVR on a proper pcb.

Manish

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,
I'm glad to convey you that my code works with no change in hardware connections just I have
change the one line in code

 Decoder_Write_Data( 0x0b , 0x00) ;

Its scan limit resistor configuration of Max7219 for Displaying only Digit "0".
But In reality its shows all Digits with same configuration .so there might be correction in datasheet or may be max7219 chip is not correctly build

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 0x0b register will not make much difference in practice. I have 8 digits but you only have a single digit. It just means that you will have a very high current for a very short amount of time.

I was intrigued by Martin's comments. So I have ordered a couple of 'cheap' Chinese chips. They will probably take 2-6 weeks to arrive. I can then compare them with my 'assumed' genuine chips.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have couple of question to ask.
1.When I tried to place code in loop it didn't work with loop convention means loop works for only single Iteration.
2._delay_ms() function also not working even though I have included related header file.
I have added "comment" to link above question respective to my Code.
Final Updated code

#include 
#include 
#include 

#define PIN_SCK 1

#define PIN_MOSI 2

#define PIN_SS 0

#define SPE 6

#define MSTR 4

void spi_init(void)
{
	DDRB |= ((1<<PIN_SCK) | (1<<PIN_MOSI) | (1<<PIN_SS));
	
	SPCR |= (1<<SPE) | (1<<MSTR) | (1<<SPR1) | (1<< SPR0);


	
}
void spi_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SS));
	else
	PORTB |= 1<< PIN_SS;


	
}//to select slave by writing 0 on portB 0;

void clk_select(uint8_t en)
{
	if(en)
	PORTB &= (~(1 << PIN_SCK));
	else
	PORTB |= 1<< PIN_SCK;
}
unsigned char spi_rw(volatile unsigned char value) 
{
	
	SPDR = value;
	
	while((SPSR & (1<<7))==0);
 return SPDR;

}


void Decoder_Write_Data(unsigned char data_reg,unsigned char data )
{
		spi_select(1);
		spi_rw(data_reg);
		spi_rw(data);
		spi_select(0);
	
}
void max7219_Init(void)
{
    /* max7219  register cofiguration. */
    Decoder_Write_Data( 0x0c , 0x01 ) ;   
    Decoder_Write_Data( 0x09 , 0x00 ) ;  
    Decoder_Write_Data( 0x0a , 0x01 ) ;  
    Decoder_Write_Data( 0x0b , 0x00) ;
   
  
}



int main(void)
{
	uint8_t n=0;//I have putted 1,2....9 to n for that values its works fine
	spi_init();
	max7219_Init();
        Decoder_Write_Data(0x01, n); 
	/*********************asked question realted to below code*************************
         
        for ( uint8_t n = 0; n < 10; n++) {
                Decoder_Write_Data(0x01, n); 
		 _delay_ms(100);
       }**********************************************************************************/
	

	return 0;
}


  
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At this stage, you only need to post the relevant function. e.g.

int main(void)
{
   spi_init();
   max7219_Init();

   while(1) {
       for ( uint8_t n = 0; n < 10; n++) {
           Decoder_Write_Data(0x01, n);
           _delay_ms(100);
       }
   }  

   return 0;
}

If you add the comment delimiters like this:

int main(void)
{
   spi_init();
   max7219_Init();
/*  comment out the next few lines
   while(1) {
       for ( uint8_t n = 0; n < 10; n++) {
           Decoder_Write_Data(0x01, n);
           _delay_ms(100);
       }
   }  
*/
   return 0;
}

it is easy for people to read on this forum.

Now look at your particular code. There is no while() loop to keep things going forever.

Seriously, coding is not complicated. If you write it neatly with proper indentation, you can follow the logic easily. Then if you still have a problem, print it out on paper. Trace the logic with a pencil and you will soon see the solution.

David.