| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Mon Jul 26, 2010 1:55 pm |
|
|
| I don't need to use the MAX7219 per se, but I do have a handful of them sitting on my desk. I did choose this chip because I like MAXIM's line of chips (I actually have a couple different chips being implemented into this project from them), and as of right now I need 24 LEDs to be powered. I do see areas in my project that may need to be added, which would in turn add more LEDs. This chip seems perfect because I can utilize 64 LEDs if need be. I can't see myself ever needing that many LEDs for this project, but I certainly need more than 16. And again I have a handful of these, so I thought this would be a good project to utilize them and learn a little C that is outside of my comfort zone. |
|
 |
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Mon Jul 26, 2010 2:24 pm |
|
|
| StingzLD wrote: | NEVERMIND! I figured it out! There was only one thing you left out. You needed to make the MAX7219_DIN pin low before sending the data through it.So:
| Code: |
for(i=0; i<16; i++)
{
output_low(MAX7219_DIN);
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(MAX7219_SCLK); // Create a positive clock pulse
output_low(MAX7219_SCLK);
}
|
Thanks again for your help! |
Try putting in a delay (10us or so) between:
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
and
output_high(MAX7219_SCLK); // Create a positive clock pulse
You want to make sure your data is stable before the chip samples on the rising edge of the clock. You shouldn't need to but it can't hurt.
Also try putting a 0.1uF cap on the Vcc pin of the MAX7219 (and make sure you have one on the Vcc pin of the PIC). |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Mon Jul 26, 2010 2:36 pm |
|
|
| Ahh, that is a very good point. I will have to try that out when I get out of work later (well by later I mean 10/11 EST haha). I will let you know if that works out! |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Tue Jul 27, 2010 12:26 am |
|
|
| Sorry for a reply later than expected. The shoot I was working on ended up running pretty long. I tried adding a delay in between the two, but it still didn't work. I even tried adding the "delay_cycles," but that still didn't work. If anyone has any suggestions as to what might be going on, I would love some input. I am at a blank as to what else could possibly be added to this code to make it work properly. |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jul 27, 2010 12:30 am |
|
|
Put the schematic for your project on a free image hosting service, such as ImageShack:
http://imageshack.us/
Then post a link to it, so we can look at it. |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Tue Jul 27, 2010 11:42 am |
|
|
Now here's a question. Judging from this photo I found, do I need to pull the LOAD line low/high even though in the datasheet it says that it doesn't matter what the state of LOAD is for the 7219?
 |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jul 27, 2010 12:42 pm |
|
|
| StingzLD wrote: | NEVERMIND! I figured it out! There was only one thing you left out. You needed to make the MAX7219_DIN pin low before sending the data through it.
So:
| Code: |
for (i=0; i<16; i++)
{
output_low(MAX7219_DIN);
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(MAX7219_SCLK); // Create a positive clock pulse
output_low(MAX7219_SCLK);
}
|
| This change is very suspicious because it doesn't change anything, you have only introduced an extra delay and maybe a very short spike on the data line.
| Quote: | | Now here's a question. Judging from this photo I found, do I need to pull the LOAD line low/high even though in the datasheet it says that it doesn't matter what the state of LOAD is for the 7219? | I guess you are referring to this: | Quote: | | For the MAX7219, serial data at DIN, sent in 16-bit packets, is shifted into the internal 16-bit shift register with each rising edge of CLK regardless of the state of LOAD. | But when you continue to read on, one sentence further:
| Quote: | | The data is then latched into either the digit or control registers on the rising edge of LOAD/CS. LOAD/CS must go high concurrently with or after the 16th rising clock edge, but before the next rising clock edge or data will be lost. | The text is confusing, you could think this is meant to be only valid for the MAX7221, but if you check page 4, the description of the pins: | Quote: | | LOAD (MAX7219) - Load-Data Input. The last 16 bits of serial data are latched on LOAD’s rising edge. |
So yes, you have to control the LOAD line after all 16 bits have been sent.
| Code: | #include <16F684.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#define MAX7219_SCLK PIN_C2
#define MAX7219_LOAD PIN_C1
#define MAX7219_DIN PIN_C0
void send_word(int16 data)
{
int8 i;
output_low(MAX7219_SCLK);
output_low(MAX7219_LOAD); // Set CS/LOAD line low. Doing it at start for compatibility with MAX7221
for(i=0; i<16; i++)
{
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(MAX7219_SCLK); // Create a positive clock pulse
output_low(MAX7219_SCLK);
}
output_high(MAX7219_LOAD); // Create a positive edge to load the data
}
//==========================================
void main()
{
send_word(0x1234);
while(1);
} |
|
|
 |
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Jul 27, 2010 12:48 pm |
|
|
| Why don't you just use a 7221 which is truly SPI (uses CS line). Then there is no ambiguity. |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Tue Jul 27, 2010 3:02 pm |
|
|
I really thought that the code change was going to work. But I tried it real quick before I left for work, and it's still kicking me in the rear. Unfortunately I didn't have any time to work more on it. Will do later.
And as for the MAX7221, I mentioned earlier that I have a handful of the 7219s laying around. So that is my reasoning for using this chip. |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Wed Jul 28, 2010 3:01 pm |
|
|
| Okay, so I have been playing around with this a lot since my last post; and I still seem to be getting nowhere! Does anybody have any last little tricks up their sleeves that might be able to remedy this non-responsive MAX7219? |
|
 |
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Wed Jul 28, 2010 3:44 pm |
|
|
You might try googling 'max7219 c code'. If you haven't yet..
There's a lot of code cut for it already,don't think it's that hard to translate into CCSC code. Even PH Anderson has done it....
Best to start off small, one led at a time....build on that.
If I had the chip, i'd do it, as I like designing 'optimal' drivers...
kind of a mind challenge...keep the grey cells operating !
Jay |
|
 |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 29, 2010 2:01 am |
|
|
I'd also like to see what you have so far. Can you post your small test program including the results you see from this test program.
Also post your compiler version number. |
|
 |
StingzLD
Joined: 18 Jul 2010 Posts: 42 Location: Richmond, VA
|
|
Posted: Thu Jul 29, 2010 1:40 pm |
|
|
Well it's not exactly a "test" program, but this is the code I have been using trying to get this to work:
Compiler V 4.084
| 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); // Set CS/LOAD line low. Doing it at start for compatibility with MAX7221
for(i=0; i<16; i++)
{
output_bit(MAX7219_DIN, shift_left(&data, 2, 0)); // Send data bit
output_high(MAX7219_CLK); // Create a positive clock pulse
output_low(MAX7219_CLK);
}
output_high(MAX7219_LOAD); // Create a positive edge to load the data
}
//==========================================
void main()
{
while (1)
{
send_word(0x01FF);
delay_ms(1000);
send_word(0x0100);
delay_ms(1000);
}
}
|
The only thing this seems to be doing is turning on every single LED and keeping it on, even though it is just suppose to be the first LED on and then the LED off and then back to the LED on. At first I thought that maybe the bits were not being sent MSB (because test mode starts out with xxxx1111 and this code ends in 11111111 [x = don't care bits] ), but then PCM programmer told me that he ran the code through a simulator and it showed the bits being sent MSB. Since then I have been trying a lot of different code trying to get it to work properly, but nothing so far. Although now that I am sitting here thinking about it, maybe I am suppose to be sending two 8-bit packets back to back MSB... Hmmm I will try that and let y'all know if it works. |
|
 |
|