Max7219 being a real pain!

Ga-Retired

New Member
Hi everyone,been trying to work with the Max7219 to drive a simple indoor temperature display which is a 2 digit CC Led display.To keep this post simple and to the point, I'm using modified programming from the great examples from Westaust55 and Martin57. Unfortunately,the Max7219's that I'm using to do the prototyping with are questionable at best,( Gotten off E-Bay) and give varying results,especially when displaying the test mode.I'm well aware of the associated problems with these counterfeits and believe may be the very source of my frustration.With that being said, I ordered a couple from an reputable dealer (Mouser.)While waiting for the Max7219's to arrive, I'd like to post my code for scrutiny to make sure I've got all my bases covered.All comments are welcome and with this being just my 3rd Picaxe project I'm definitely in the learning stages with this chip.
Code:
#Picaxe 08M2

; SYMBOL Definitions
;
; Control signal lines from PICAXE to MAX7219
SYMBOL DIn_7219    = PinC.0
SYMBOL Load_7219    =    C.1
SYMBOL Clk_7219    =    C.2
SYMBOL DS18B20    =    C.4

SYMBOL No_Op    = 0
;Registers
SYMBOL Decode    = 9
SYMBOL Intens    =10
SYMBOL ScanLim    =11
SYMBOL ShutDwn    =12
SYMBOL Digtest    =15
;
; MAX7219 Data Constants 
SYMBOL Set_Off    = 0
SYMBOL Set_On     = 1
SYMBOL blank    = 15
SYMBOL Digit0     = 1
SYMBOL Digit1     = 2
SYMBOL No_Digits    = 1    ; Scan limit for digits 0 to 1
SYMBOL Dec_Digits = 15    ; decode digits 0 to 1 according to "code B"
SYMBOL Init_Inten = 13    ; 0 (=1/32 PWM on time) to 15 (=31/32 PWM on time)
SYMBOL DigBlank    = 15    ; "Code B" value to black a digit
SYMBOL Decimal    = 10
SYMBOL On_Off    = 12

; Define variables
SYMBOL Temperature= b0
SYMBOL Data_7219    = b2
SYMBOL Register    = b1
SYMBOL Units    = b3
Symbol Tens        = b4


;
;
;===============================================
; Initialise the PICAXE Pins for communication with the MAX7219
;===============================================
Init:
    DirsC= %11100000
    LOW Load_7219
    LOW Clk_7219
    din_7219= 0
    
;===============================================
; Main Program loop
;===============================================    
Main:

    Do
    
    GOSUB Initialise7219


    GOSUB Displaytest
'     
    
     GOSUB Aquiretemp
         
         
    Pause 1000
              
         
             
      Loop
        
    
 
 
;===============================================
; Subroutines
;===============================================

; Subroutine to initialise the MAX7219 7-Seg LED display driver
Initialise7219:
    Register = Decode     : Data_7219 = Dec_Digits : GOSUB ShiftTo7219
    Register = Intens     : Data_7219 = Init_Inten : GOSUB ShiftTo7219
    Register = ScanLim : Data_7219 = No_Digits  : GOSUB ShiftTo7219
    Register = ShutDwn : Data_7219 = Set_on       : GOSUB ShiftTo7219
    Register = Digtest : Data_7219 = set_off       : GOSUB ShiftTo7219
    
    Return
    
; subroutine to send the data for display on the 2 digits to the MAX7219
; leading zero blanking applied when the blanking flag is set to "on"


         return

    
    'Subroutine "Displaytest" test all segments of all digits as a test
    
    Displaytest:
        register =Digtest:Data_7219=set_on :GOSUB Shiftto7219
        pause 5000
        register =Digtest:Data_7219=set_off:GOSUB    Shiftto7219
        pause 1000
        
        Return




; Subroutine to shift the register address and data value out to the MAX7219
; Tests have identified that the MAX7219 incoming data is clocked in through the lsb towards the msb.
; If only one MAX7219 is conencted then the first four significant bits of data can be ignored to
; improve the data transfer speed by 25%
;
ShiftTo7219:
    
    DIn_7219 = bit11: PULSOUT Clk_7219, 1
    DIn_7219 = bit10: PULSOUT Clk_7219, 1
    DIn_7219 = bit9 : PULSOUT Clk_7219, 1
    DIn_7219 = bit8 : PULSOUT Clk_7219, 1
    DIn_7219 = bit7 : PULSOUT Clk_7219, 1
    DIn_7219 = bit6 : PULSOUT Clk_7219, 1
    DIn_7219 = bit5 : PULSOUT Clk_7219, 1
    DIn_7219 = bit4 : PULSOUT Clk_7219, 1
    DIn_7219 = bit3 : PULSOUT Clk_7219, 1
    DIn_7219 = bit2 : PULSOUT Clk_7219, 1
    DIn_7219 = bit1 : PULSOUT Clk_7219, 1
    DIn_7219 = bit0 : PULSOUT Clk_7219, 1
    
                PULSOUT Load_7219,1 
    return
    
    AquireTemp:
    
    Readtemp DS18B20,Temperature
    
Convert:Temperature = Temperature *9/5+32

    'send temp data to the 2 digits
    
    Tens=Temperature/10
    Units=Temperature//10

            If tens=0 then
    tens=blank
    
    endif

         register = Digit1 : Data_7219 = Tens   : GOSUB ShiftTo7219
        register = Digit0 : Data_7219 = Units  : GOSUB ShiftTo7219

    
    SERTXD (CR, LF, "Temperature  ",#Temperature,"  Degrees F", CR, LF)
 
     pause 1000
 
      goto AquireTemp
 
Last edited:

westaust55

Moderator
At a quick scan through most of your code is a simple cut and paste.
However for the Main program section:
Code:
Main:
    Do
    GOSUB Initialise7219
    GOSUB Displaytest
     GOSUB Aquiretemp
    Pause 1000
      Loop
Move the line
GOSUB Initialise7219​
Up to be located between the Main: label and the DO statement.

Then try again with the first chips you have purchased - they may show more if you are not re- initialising every pass through the DO loop
 

Ga-Retired

New Member
Thank you Westaust55 for taking a look at this code and I'm doing as you suggested,I'll get back with my results.I'm a little concerned that I'm messing up on the proper way to send the data from the temp sensor to the Max7219 to read out on the 2 digit Led display.my best,Ga-Retired
 

Ga-Retired

New Member
Update on this post, having done as you have suggested with no results.Also the 'Real' Maxin chips have arrived with the same results as the 'Fakes'.I know all the wiring is correct because I can run Westaust55's 4 digit counter code reduced down to 2digits and it works just as expected,even with the 'Fakes'!If some very smart experts (Westaust55,Martin57 and others)could have a look see at the code above and tell me where I have messed up.It appears I'm not giving the max7219 the info it wants to see to display the digits.Much thanks to everyone,I need to get this project done!My best,Jeff
 

binary1248

Senior Member
The data says
MAX7221 is compatible with SPI™, QSPI™, and MICROWIRE™
How do you setup which protocol is used.
Perhaps your setup for the wrong com setup. I didn't read the max7219 details, but there must be a way to define the com protocall befor you can communicate.
EDIT: Big red face, the 7219 is setup for SPI. :mad:
 
Last edited:

RexLan

Senior Member
I did a thermometer for my greenhouse 5-6 years ago and it works. I used an 8M so you will need to change your pins. I also ran 3 digits and min/max readings which is easy to modify too.

Maybe it will give you an idea of why yours is not working.
 

Attachments

Ga-Retired

New Member
Well guys I'm back and unfortunately I'm still unable to display any digits from the Max7219.I'm in the "Crazy" state right now,trying the same thing over and over and expecting different results!I've used so many different programs and have differing results.Running a "Test Mode" only will sometimes work,yet most of the time running with the complete program it won't,just nuts!The only program that has worked correctly is Westaust55's 4 bit counter which I have modified to a 2 digit display so I know all that wiring is correct.This can't be this hard to program.My thought is maybe the info the Max 7219 needs is not in the proper format (Read from the DS18B20 sensor on C.4 of the 08M2) The terminal window displays my temperature correctly even converted to F* and the simulator runs the program like a charm,I'm also at the end of what the heck to try next!I've got all of this on a good breadboard with a regulated PS at 4.97 volts DC @1amp.Any thoughts or suggestions welcome,thanks everyone!
 

MPep

Senior Member
Do you have sufficient capacitors across the power rails? Near each IC?
On the circuit board, 100 - 1000uF, and near each IC say use a 100nF.

Read this and more info here

Hope this helps
 

hippy

Technical Support
Staff member
The only program that has worked correctly is Westaust55's 4 bit counter which I have modified to a 2 digit display so I know all that wiring is correct.This can't be this hard to program.
Perhaps post your modified version of Westaust55's code and your own and it may be clearer to others what the difference and problem is. If the first works that suggests the second should work so it seems to be a programming or coding issue.
 

Ga-Retired

New Member
Update! My problem with the Max7219 has been solved and I couldn't be happier.The problem was solved with a combination of Westaust55 and MartinM57 test code and a solid code to lead me to where my problem was.Long story short with the modified code everything is working very well.Thankyou guys for your help it was a nice experience but very glad its done.Now to complete the PCB and wrap up the project!
my best,Ga-Retired
 

xtech007

Senior Member
Great!

Any videos we can see results !
Would you add it to finalize project on the forum so we all can learn?
 
Top