1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Control a MAX7219 by Oshonsoft?

Discussion in 'Oshonsoft' started by revave, Jul 3, 2013.

  1. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello,

    Is it possible to control a MAX7219 LED-driver by Oshonsoft code? The serial communication to a MAX7219 is not 100% compatible to SPI.
    The MAX7219 is communicating by folowing ports:
    -DIN
    -CLK

    CS will not be used at the MAX7219, so for the selection of the chip LOAD must be high i think?
    Is it true that i don't have to use slave adresses? I want to use two drivers and each driver has it's own function.
    With normal SPI you'll give a slaveadress, but is it correct that i only have to make the LOAD-input high at the driver i want to write to?


    Does anyone have a working example for this kind of communication?
    (I know that the MAX7221 if fully compatible to SPI, but i bought by mismatch 10pcs of MAX7219 chips and they are not cheap)

    Thank you!

    Reijnko Vast
     
    Last edited: Jul 3, 2013
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,

    It should be possible to create a 16 bit serial Data WORD string and Clock it out, using Oshonsoft Basic.

    The upper 8 bits of the WORD would be XXXX[addr] and the lower 8 bits the displayed data for that DIGIT.

    What is you clock speed and PIC type.??

    E
     
  3. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello,

    The clockspeed is 16 Mhz and the chip is a 16f628a. Maybe this chip will be replaced by a 18f2550.

    Reijnko
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE

    hi,
    I would consider assigning a 'labelled' 16 bit WORD for each LED Digit [8 WORD's]

    Preload the upper BYTE of each WORD with the xxxx and the LED's address

    Load as required the lower BYTE of the WORD with the required Digit to be displayed.

    You could then either cycle thru all the digit WORD's or select a Digit label.
    Then the serial WORD transfer to the 7219 would be a Data/Clock sub routine.

    Do you have Code you could post so that we can check it.?

    E.
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK
    Take a look at the microchip mcp4921 DAC.. This uses a 16 bit transfer I write to this in Oshonsoft.

    Code (basic):


    Define SPI_CS_REG = PORTC
    Define SPI_CS_BIT = 0
    Define SPI_SCK_REG = PORTC
    Define SPI_SCK_BIT = 3
    Define SPI_SDI_REG = PORTC
    Define SPI_SDI_BIT = 5
    Define SPI_SDO_REG = PORTC
    Define SPI_SDO_BIT = 4
    SPIPrepare
     


    Code (basic):

    Proc sendspi(x As Word, t As Byte)
        If x > 4095 Then x = 4095
        x = x + 0x3000

        PORTD = t
        SPISend x.HB
        SPISend x.LB
        PORTD = 0xff
    End Proc                    

     
     
  7. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello E,

    I do not have any code yet. First i want to do some research for the communication and after i understand the logic about the communication i'll write the code for the PIC's.

    Is it correct that CLK must be high and then folwwed by the 16 bit WORD at the DATA-line. Then make CLK low and repeat this routine for the following words? LOAD is then used for the chip i want to write to?

    Reijnko
     
  8. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello Ian,

    This is a normal SPI routine. Does that mean that the SDO won't be used for the 7219?
    CS is then used for LOAD at the 7219?

    That means then that the 7219 can be controlled by an standard SPI routine ithout using the SDO-port?


    Reijnko
     
  9. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    As Ian points out the Oshonsoft 'high or low' SPI commands can be used to transfer serial data.

    There are examples in the Oshonsoft Basic manual documentation.

    I expect that you will selecting either of the two individual 7219 by a PIC pin.?
    E
     
  10. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hi Eric,

    Yes. I understand the normal spi statements in Oshonsoft. Still wondering where SDO portc.4 is used for. Can i ignore the sdo connection? Because i only write to the 7219.

    You are right. Each chip uses an io port for the load/cs bit.

    So, as a summary: i can use the normal SPI instructionset in Oshonsoft and can ignore the SDO port?
     
  11. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Just use the SPI send commands [ initialise the SPI pins first]
    I use this code for writing to an EEPROM.



    Code (text):

    For addr = 0 To 10
    data = 200 - addr
    SPICSOn
    SPISend 0x06
    SPICSOff
    SPICSOn
    SPISend 0x02
    SPISend addr
    SPISend data
    SPICSOff
    Lcdcmdout LcdClear
    Lcdout "Write To EEPROM"
    Lcdcmdout LcdLine2Home
    Lcdout "(", #addr, ") = ", #data
    WaitMs 500
    Next addr
     
    Added init style code: Change the pins to suit your application

    Code (text):

    Here is one example for using 25C040 SPI eeprom:
    AllDigital
    Define SPI_CS_REG = PORTC
    Define SPI_CS_BIT = 0
    Define SPI_SCK_REG = PORTC
    Define SPI_SCK_BIT = 3
    Define SPI_SDI_REG = PORTC
    Define SPI_SDI_BIT = 5
    Define SPI_SDO_REG = PORTC
    Define SPI_SDO_BIT = 4
    SPIPrepare
     
     
  12. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hi Eric,

    I saw this code in an example. You write as first 0x06 followed by 0x02.
    The last one is the slaveadress i think. What is the reason of 0x06?
    At init the 7219 doesn't have an adress....

    Reijnko.
     
  13. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK
    Yep.... I do! Its a continuous buffer link anyway... The thing about Oshonsoft is its a software implementation anyway so the other pin isn't used anyway.
     
  14. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    The addresses for the 7219 are its Digit location address.

    The 'sample' code I posted is for an EEPROM which requires the 0x02 and 0x06 codes to command the EEPROM to perform a certain internal action.

    The 7219 will required this type of internal Command instruction, they are listed in the d/sheet.

    Check the d/s for the required code and use SPISend.

    E
     

    Attached Files:

  15. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello Eric and Ian,

    Thank you both for your quick reply's.
    Tonight i want to do some experiments with softwarecode.
    If i'll get it work then i will post the softwarecode here. Then other people can use it too.

    Best regards,
    Reijnko
     
  16. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Use the Oscilloscope module in the Tools section of Oshonsoft to check the SPI output pin.

    E
     
  17. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello,

    Here's a piece of testcode. It doesn't work yet. I'm still investigating to a solution, but reply's at the code are very welcome..

    Code (text):

    'PIC 16F628A, with 16Mhz crystal and pull ups (10k) at SDI and CLK
    'This program has to energize led 0,1 and 7 of row 2 at a 8x8 ledmatrix (rownumbers numbered 1..8)

    Define CONF_WORD = 0x3f42

    AllDigital
    Define CLOCK_FREQUENCY = 16

    Define SPI_CS_REG = PORTB
    Define SPI_CS_BIT = 1
    Define SPI_SCK_REG = PORTB  'with pull up (10k)
    Define SPI_SCK_BIT = 2
    Define SPI_SDI_REG = PORTB  'with pull up (10k)
    Define SPI_SDI_BIT = 0
    Define SPI_SDO_REG = PORTB
    Define SPI_SDO_BIT = 3
    SPIPrepare

    '****************************************
    'Init MAX7219
    SPICSOn
    SPISend 12  'Registeradress shutdown
    SPISend 1  'value written To registry
    SPICSOff
    WaitMs 10

    SPICSOn
    SPISend 9  'Registeradress decode mode
    SPISend 0  'value written to registry
    SPICSOff
    WaitMs 10

    SPICSOn
    SPISend 11  'Registeradress scanlimit
    SPISend 7  'value written to registry
    SPICSOff
    WaitMs 10

    SPICSOn
    SPISend 10  'Registeradress intensity
    SPISend 1  'value written to registry
    SPICSOff
    WaitMs 10

    SPICSOn
    SPISend 15  'Registeradress testmode/ normal mode
    SPISend 0  'value written to registry
    SPICSOff
    WaitMs 10
    'End of init
    '****************************************

    main:
    SPICSOn
    SPISend 0x02  'Registeradress (digit 1)
    SPISend 131  'bit 0, 1 and 7 for test
    SPICSOff
    WaitMs 10
    Goto main
    'End of mainprogram
    '****************************************

     
    Best regards,
    Reijnko
     
    Last edited: Jul 8, 2013
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,185
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    ONLINE
    hi,
    Looks OK to me.:D

    Three images of the scope,, image3 is the 'main' loop


    Eric
     

    Attached Files:

  19. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK
    The registers on that chip are odd.... Really odd

    Data

    D7 D6 D5 D4 D3 D2 D1 D0

    Segments
    DP..A...B...C...D...E...F...G..

    So to write 131 as you did

    01100001.. Which is 0x61 or 97 decimal

    If you turn decode on ( 0xff ) then if you write 2 then it displays 2
     
  20. revave

    revave Member

    Joined:
    Oct 11, 2011
    Messages:
    48
    Likes:
    1
    Location:
    Netherlands
    Hello Ian,

    For a 7-segment i can understand, but for a led matrix 8x8 is it binary i think?
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,163
    Likes:
    909
    Location:
    Rochdale UK
    Why!!! Are you using a matrix?? I thought it was a row of 4 led common cathode LED's you were using.
     

Share This Page