SPI instead of SHIFTOUT - MAX7219


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Mar 2007
    Posts
    13

    Default SPI instead of SHIFTOUT - MAX7219

    Hi guys

    I have been looking around for a while (almost the whole day) to find an example on how to use the SPI interface on a PIC 16F876 and I couldn't succeed. It works fine with SHIFTOUT but I would liek to try something else :-). This is to drive a MAX7219 display driver.

    I am trying to get my PIC sending me data and clock signals via PORT C via the MSSP module in my PIC and no way.

    That would be nice if some one could help.

    I have been trying the examples given on the Mel web site and these are expecting input on the SPI bus and I couldn't make them running as well.

    Here is my basic testing progamme:

    ' Pic Configuration
    ' =================
    asm
    device pic16F876A, hs_osc, wdt_off, lvp_off, protect_off, bod_off
    endasm

    SSPEN VAR SSPCON.5 'SSP Enable bit
    CKP VAR SSPCON.4 'Clock Polarity Select
    SSPM3 var SSPCON.3
    SSPM2 var SSPCON.2
    SSPM1 var SSPCON.1
    SSPM0 var SSPCON.0
    SMP VAR SSPSTAT.7 'Data input sample phase
    CKE VAR SSPSTAT.6 'Clock Edge Select bit
    SSPIF VAR PIR1.3 'SPI interrupt flag

    TRISC = 0 'set PORTC I/O
    'TRISB = 0
    ADCON1 = %00000100
    TRISA = %00100000
    'PORTA = %00100000

    SSPEN = 1 'enable SPI pins
    CKP = 0 'clock idle low
    CKE = 0 'transmit on idle to active transition
    SSPIF = 0 'clear buffer full status
    SMP = 0 'sample in middle of data

    SSPM0 = 1
    SSPM1 = 1
    SSPM2 = 0
    SSPM3 = 0

    main:
    toggle PORTB.0 ' to see if something is happening
    SSPBUF = "A" ' write to SSPBUF to start clock
    goto main
    end

  2. #2
    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.

  3. #3
    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

  4. #4
    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

  5. #5
    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.

  6. #6
    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

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