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

Interfacing 8051 to LED driver MAX7221

Discussion in '8051/8951' started by mikemania, Nov 12, 2014.

  1. mikemania

    mikemania New Member

    Joined:
    Nov 12, 2014
    Messages:
    3
    Likes:
    0
    Hi,

    I am having some difficulties interfacing the 8051 to the MAX7221 driver chip using SPI. As I understand it, it receives a 16bit signal and that would require bit-banging as the 8051 only sends 8bits. I am having trouble understanding how to do this in the assembly language.

    The uC is 8051f340 from SiLabs.

    Thanks
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK
    This is the next tutorial in my 8051 series.... It's been on hold for a few weeks but I aim to get it back on track soon.

    With SPI you can send a byte twice in succession to achieve 16 bit.. So.. Clear the CS bit load the SPI reg with the HIGH byte... Send...Load with the LOW byte... Send... Then Set the CS bit.... All done..

    If you can send a byte, then you can send a double byte... The trick is to control the CS pin, so choose your own CS pin..
     
  3. mikemania

    mikemania New Member

    Joined:
    Nov 12, 2014
    Messages:
    3
    Likes:
    0
    Thanks for the reply. I actually found this site after landing on your tutorials. As my luck would have it, you stopped right before the info I needed haha.

    Here is a snippet of what I'm doing.

    If I'm reading the MAX7221 datasheet correctly, I am sending the normal operation command first then display "5" on digit 1.

    Nothing seems to show up. I am thinking it may be a configuration problem, specifically with SPI. Here's what I'm doing:
    http://i.imgur.com/HbMy3H6.jpg

    Code (text):

    clr   SPIF
    clr     CS
    nop
    ;Send Normal Operation Command
    mov   SPI0DAT, #0CH
    jnb   SPIF,$
    mov   SPI0DAT, #01H
    jnb   SPIF,$
    nop
    setb  CS

     lcall delay2

    clr     CS
    nop
    ;Display #5 on Digit 1
    mov   SPI0DAT, #01H
    jnb   SPIF,$
    mov   SPI0DAT, #5BH
    jnb   SPIF,$
    nop
    setb  CS
    nop
                           
    lcall delay2
     
  4. dave

    Dave New Member

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


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK

    You have to send the high byte first...... MSB to LSB Data is always shifted high to low.
     
  6. mikemania

    mikemania New Member

    Joined:
    Nov 12, 2014
    Messages:
    3
    Likes:
    0
    Alright, so with the following code and format, I was able to successfully talk to the 7221 chip. However, I am using 6 digits and the last 2 7-segments do not display what they should. They instead display a random symbols that do not seem to correlate to the intended value. I set the scan limit to the number of characters I'm using, and still the 5th and 6th are jumbled. Not sure if this is an 8051 issue anymore.

    Code (text):
       
        clr    CS               ;SET CHIP-SELECT LOW
        nop
        mov   SPI0DAT, #0C0H    ;SHUTDOWN REGISTER
        jnb   TXBMT,$                    ;TRANSMIT BUFFER EMPTY
        mov   SPI0DAT, #010H    ;NORMAL OPERATION
        jnb   TXBMT,$
        nop
        setb  CS                            ;SET CS HIGH
        clr     SPIF                        ;CLEAR SPI INTERRUPT
        nop        
     

Share This Page