View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19551
|
|
Posted: Thu Jul 29, 2010 2:54 pm |
|
|
Study the data sheet.
Note the comment that "On initial power-up, all control registers are reset, the display is blanked, and the MAX7219/MAX7221 enter shutdown mode".
This is controlled by register 0xC. You are not taking the chip out of shutdown...
Best Wishes |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Fri Jul 30, 2010 7:45 pm |
|
|
Wow, I completely overlooked that section. I was so concerned about the actual sending of the data that I didn't even pay two cents to it! But unfortunately after modifying the code, it still seems to not work. I tried for a good hour before work changing this and changing that, reworking the code to try and make of sense of the this.. still nothing
And although you brought up a valid point, this baffles me even more. I say this because if it is in shutdown mode, then nothing should be happening with the chip at all. Yet for past couple of days that I have been playing around with the code trying to get it to work, I have been able to see a variety of changes to the LEDs connected to the chip. Why would this happen if the chip is in shutdown mode and supposedly not in an operating mode? The only way to get out of shutdown mode (other than returning it to normal mode) is by overriding it with the display test. This again goes back to a previous post I made about the bits in the packet possibly being sent in the wrong order. But I was proven wrong rather quickly by an MPLAB simulation done by PCM programmer. Although now I am starting to disbelieve this test for the sole fact that his test was based on a separate PIC that had a UART (which mine doesn't, thus the bit banging.) And I am inclined to stick with this belief because by reversing the order of the bits, I got the closest that I have gotten to the results that I am looking for [At the time I had 3 digits hooked up and was trying to light only one digit, which I eventually only got one digit working but not nearly in the fashion that I wanted it to or how my code was written for it to. I then moved on to a simple one digit test but only with 2 LEDs within that digit as a simpler method of seeing if I can just control one of the two LEDs instead of the whole digit].
I guess a new question to add to this problem would be: Is there a way to reverse the order of the bits without the programmer having to sit there and think about how the packet would look in reverse? I ask for the sole fact that it is much simpler to look at the datasheet and and type what I see and just have the program reverse it for me.
Here is my new modified code that I have settled with for the time being:
Code: |
#include <16F684.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#define MAX7219_DIN PIN_C0
#define MAX7219_LOAD PIN_C1
#define MAX7219_CLK PIN_C2
void send_word(int16 data)
{
int8 i;
output_low(MAX7219_CLK);
output_low(MAX7219_LOAD);
for(i=0; i<8; i++)
{
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(MAX7219_CLK); // Create a positive clock pulse
delay_cycles(1);
output_low(MAX7219_CLK);
}
output_high(MAX7219_LOAD);
}
//==========================================
void main()
{
//MAX7219 Setup
send_word(0x0C01); //Take out of Shutdown Mode
send_word(0x0900); //Set to No Decode Mode
send_word(0x0A0F); //Set Intensity to full
send_word(0x0B00); //Set Scan Limit to Digit 0 only
while(1)
{
send_word(0x0140); //Turn LED1 on
delay_ms(1000);
send_word(0x0100); //Turn LEDs off
delay_ms(1000);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 30, 2010 8:18 pm |
|
|
Quote: |
for(i=0; i<8; i++)
|
This isn't sending a word. It's sending a byte. It should be 16, not 8.
Because of that, your code below will only send the upper byte
in each line. That's probably why it doesn't work:
Quote: |
send_word(0x0C01); //Take out of Shutdown Mode
send_word(0x0900); //Set to No Decode Mode
send_word(0x0A0F); //Set Intensity to full
send_word(0x0B00); //Set Scan
|
|
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Fri Jul 30, 2010 8:26 pm |
|
|
Yea I just literally saw that when I was trying some new stuff and saw the e-mail notification pop up. But I changed and tried it before I logged back in here, and it still didn't work unfortunately. But good catch! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 30, 2010 9:19 pm |
|
|
I think you should initialize all the control signals at the start of main(),
followed by a short delay. Example:
Code: |
void main()
{
output_high(MAX7219_DIN);
output_low(MAX7219_LOAD);
output_low(MAX7219_CLK);
delay_ms(1);
|
Also, why don't you try the Display Test mode. It might do something.
What value are you using for the Rset resistor ? |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Fri Jul 30, 2010 9:48 pm |
|
|
Yea I have tried all of that... still nothing. I have even stepped away from this PIC and tried interfacing the MAX7219 with the Arduino... still nothing. So I am not sure what is not happening in the code, but at least I know now that it's not just because of my MCU. Unfortunately this means that I am still stuck trying to debug the hell out this code.
And originally when I was using 3 digits worth of LEDs, I was using an 18k resistor even though my forward voltage was 2.0 and it recommends 17.1K. But just like this MAX IC, I have the 18k on hand; so I used it. Since I am only using two LEDs right now (and only one is suppose to be on at a time) I just stuck a 220 resistor in there. |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Aug 12, 2010 1:19 pm |
|
|
So after taking a break from this for a while, I decided to give this another go. For starters, I tried to send the chip into Test Mode.. no cigar. Then I decided that maybe I should try the MAX7221 instead. Maybe there is something that my MCU isn't happy with on the MAX7219. So I just received those today, but I am still having the same issues. I have checked the data sheet a million times to make sure everything is being sent in the right order. If there is anyone who has a fresh idea on this, I would be most grateful.
Thank you! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 12, 2010 1:48 pm |
|
|
Post your latest (complete and compilable) test program for the Max7221. |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Aug 12, 2010 2:37 pm |
|
|
Code: |
#include <16F684.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#define DIN PIN_C0
#define CS PIN_C1
#define CLK PIN_C2
void send_word(int16 data)
{
int8 i;
output_low(CS);
output_low(CLK);
for(i=0; i<16; i++)
{
output_bit(DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(CLK); // Create a positive clock pulse
delay_cycles(1);
output_low(CLK);
delay_cycles(1);
}
output_high(CS);
}
//==========================================
void main()
{
//MAX7221 Setup
send_word(0x0C01); //Take out of Shutdown Mode
send_word(0x0900); //Set to No Decode Mode
send_word(0x0A0F); //Set Intensity to full
send_word(0x0B00); //Set Scan Limit to Digit 0 only
while(1)
{
send_word(0x0140); //Turn LED1 on
delay_ms(1000);
send_word(0x0100); //Turn LEDs off
delay_ms(1000);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 12, 2010 4:01 pm |
|
|
The Max7221 data sheet says the Display Test register must be initialized
and your code doesn't do that. I've added a call to the program to do it.
Quote: |
Note: The MAX7219/MAX7221 remain in display-test mode
(all LEDs on) until the display-test register is reconfigured
for normal operation.
|
I would add all the lines shown in bold, below. This adds a call to init the
Display Test register, and also it initializes all the SPI i/o lines to the
correct default state. The PIC inits all these pins to be floating input pins
upon power-up. It's important to set them to be output pins, and put
them in the correct idle state before calling any driver routines.
The init routine given below does this.
Quote: |
void init_max7221(void)
{
output_high(CS);
output_low(CLK);
output_low(DIN);
delay_ms(10);
}
//=================================
void main()
{
init_max7221(); // Init SPI i/o lines
//MAX7221 Setup
send_word(0x0C01); //Take out of Shutdown Mode
send_word(0x0900); //Set to No Decode Mode
send_word(0x0A0F); //Set Intensity to full
send_word(0x0B00); //Set Scan Limit to Digit 0 only
send_word(0x0F00); // Turn off Display Test
while(1)
{
send_word(0x0140); //Turn LED1 on
delay_ms(1000);
send_word(0x0100); //Turn LEDs off
delay_ms(1000);
}
} |
|
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Aug 12, 2010 4:23 pm |
|
|
Well that is a valid point. But here is an interesting question then, why is it that none of the LEDs turn on at all? This was the problem I was having before, and I still have the same problem after adding the code you gave me. Maybe the problem can be fixed by splitting the 16bit packet into two 8bit packets being sent one after the other? I would like to know your thoughts on that. Unfortunately I am heading out for the night, so I will have to try this tomorrow at some point. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 12, 2010 4:29 pm |
|
|
I would disconnect the 7-segment display and just test it with a single
discrete LED. |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Aug 12, 2010 4:31 pm |
|
|
That's actually what I am doing. My whole design is based on using discrete LEDs instead of 7-Segment Displays. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 12, 2010 4:42 pm |
|
|
What's the manufacturer and part number of the LEDs ? |
|
|
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Aug 12, 2010 4:46 pm |
|
|
Everlight Electronics
Part No: 339-1SRVGW/S150
These are 5mm Bi-Color LEDs, common cathode |
|
|
|