SPI instead of SHIFTOUT - MAX7219


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    What have you on hand to debug? Any PICKit 2, logic analyser, scope?

    Any schematic?

    I see HS OSC... it mean not much than >4MHz to me

    More details, more help.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Mar 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default SPI instead of SHIFTOUT - MAX7219

    Quote Originally Posted by mister_e View Post
    What have you on hand to debug? Any PICKit 2, logic analyser, scope?

    Any schematic?

    I see HS OSC... it mean not much than >4MHz to me

    More details, more help.
    Hi Mister-e

    Many thanks for the quick reaction.

    As to the schematic nothing special but a PIC 16F876 with a 20 MHz crystal on a Mel PCB (PICPROTO-USB). I am checking with a scope (PCSU1000) the different signals on the PORTC C, i.e. the Serial Data Out (SDO) and the Serial Clock (SCK). Of course my PIC should be a master (or that's what I am trying to achieve).

    Of course this works fine with other compilers like MikroC and CCS PICC on other hardware (EasyPIC5). And I want to have it running with PBP.

    Please, let me know whether you need further detail on my system.
    Last edited by Momboz; - 19th April 2008 at 19:54. Reason: More details

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    With SSPM3:0 = 0011, it specifies the SSP clock comes from Timer2/2. But you haven't set-up Timer2.

    Since the MAX7219 is a 10mhz device, you can run it at the highest speed available from the PIC.
    SSPM3:0 = 0000 -- SPI master mode, clock = FOSC/4

    And I think CKE should be 1.

    In the Main loop, you need to wait for the SSP to finish sending the last byte, before putting a new one in the buffer.
    Code:
    main:
        toggle PORTB.0 ' to see if something is happening
        SSPBUF = "A" ' write to SSPBUF to start clock
        WHILE !SSPIF : WEND
        SSPIF = 0
    goto main
    Also the MAX7219 needs a Latch(Load) signal from the PIC, to latch the last 16-bit's into the device. Since you're only sending 1 byte, I guess you just haven't made it that far yet though.
    <br>
    DT

  4. #4
    Join Date
    Mar 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default SPI instead of SHIFTOUT - MAX7219

    Quote Originally Posted by Darrel Taylor View Post
    With SSPM3:0 = 0011, it specifies the SSP clock comes from Timer2/2. But you haven't set-up Timer2.

    Since the MAX7219 is a 10mhz device, you can run it at the highest speed available from the PIC.
    SSPM3:0 = 0000 -- SPI master mode, clock = FOSC/4
    Many thanks Darrel Taylor.

    Yes, you are right that's a mistake I have made. I wanted to have SSPM3:0 = 0010, i.e. the lowest speed.

    And I think CKE should be 1.
    I am not that far, I will check this later on.

    In the Main loop, you need to wait for the SSP to finish sending the last byte, before putting a new one in the buffer.
    Code:
    main:
        toggle PORTB.0 ' to see if something is happening
        SSPBUF = "A" ' write to SSPBUF to start clock
        WHILE !SSPIF : WEND
        SSPIF = 0
    goto main
    If I add this while end loop the PIC stops and never gets further. the PORTB.0 is not blinking any more (check with a scope connected to PORTB.0).

    It seems I have a problem with the interrupt setting the SSPIF flag never gets set.

    What I did in my code is:
    Code:
    INTCON = %11000000       ' Set the interrupts, i.e. enable GIE and PEIE
    SSPIE = 1                       ' Enable SSPIE interrupt
    Is there any mistake I have overlooked in my interrupts setting?

    Also the MAX7219 needs a Latch(Load) signal from the PIC, to latch the last 16-bit's into the device. Since you're only sending 1 byte, I guess you just haven't made it that far yet though.
    <br>
    Yes, you are right, I am not that far in the programming. I am adopting rather a pragmatic approach, i.e. doing things step by step.

    Thanks a lot.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Momboz View Post
    What I did in my code is:
    Code:
    INTCON = %11000000       ' Set the interrupts, i.e. enable GIE and PEIE
    SSPIE = 1                       ' Enable SSPIE interrupt
    Is there any mistake I have overlooked in my interrupts setting?
    NO! You don't want to do that.

    You just use the flag to tell when the SSP is finished.
    If you enable interrupts without any interrupt Handlers, it goes off into never never land, overflows Stacks and generally just doesn't work.
    <br>
    DT

  6. #6
    Join Date
    Mar 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default SPI instead of SHIFTOUT - MAX7219

    Quote Originally Posted by Darrel Taylor View Post
    NO! You don't want to do that.

    You just use the flag to tell when the SSP is finished.
    If you enable interrupts without any interrupt Handlers, it goes off into never never land, overflows Stacks and generally just doesn't work.
    <br>
    Sorry DT

    I wasn't complete in my previous answer.

    The first thing I did was to test with the addition of the while loop as you proposed and it wasn't successful, i.e. No toggle on PORTB.0 signal. It looks like the While loop is blocking the process (or like SSPIF is never set). if I suppress the while loop the PORTB.0 will toggle again.

    That's the reason why I thought about setting the interrupts.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Here is some sample code from meLabs. Maybe that would be of help to you.

    http://www.melabs.com/resources/samples/pbp/spimast.bas
    http://www.melabs.com/resources/samp...p/spislave.bas
    Tim Barr

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Momboz View Post
    It looks like the While loop is blocking the process (or like SSPIF is never set). if I suppress the while loop the PORTB.0 will toggle again.

    That's the reason why I thought about setting the interrupts.
    Works fine here.
    Ran your program (with the suggested changes) on an 877, and It sends data from the SSP and blinks the LED.

    It's A VERY FAST blink. Not visible to the naked eye (or clothed ones).

    Try putting a PAUSE 200 in the Main Loop.
    <br>
    DT

Similar Threads

  1. Max7219 cascading problem ?
    By iugmoh in forum General
    Replies: 2
    Last Post: - 13th December 2020, 10:53
  2. 7 Segment Displays and MAX7219
    By Bill Legge in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 31st October 2010, 18:30
  3. Smart Star (how to use shift registers)
    By mackrackit in forum Code Examples
    Replies: 3
    Last Post: - 30th November 2008, 20:06
  4. Shorter Subroutines for MAX7219
    By exelanoz in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th March 2007, 11:35
  5. Replace Shiftout with spi
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 7th January 2007, 16:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts