• AVR Freaks

18F4520 SSPADD Calculation Confirmation

Author
Tuurbo46
Super Member
  • Total Posts : 232
  • Reward points : 0
  • Joined: 2004/09/12 05:05:45
  • Location: UK
  • Status: offline
2019/12/04 04:16:22 (permalink)
0

18F4520 SSPADD Calculation Confirmation

Hi,
 
I have an SPI clock speed error and i think i my have calculated SSPADD incorrectly.  I am using an 18F4520 using an external 32MHz crystal.  I require the SPI to clock at 50kHz.  Below is my calculation:
 
* SSPADD = ((Fosc/4)/Bitrate)-1
 
* 159 = ((32MHz/ 4)/50kHz)-1
 
Many thanks,
 
Tuurbo46
 
#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: 18F4520 SSPADD Calculation Confirmation 2019/12/04 04:23:25 (permalink)
    +1 (1)
    SSPADD is only used for the I2C clock, not SPI.
    The slowest clock NOT using TMR2 is Fosc/64 = 32MHz/64 = 500kHz,
    so you will have to use the TMR2/2 option.
     
    So, you need to setup TMR2 to roll over at 100 kHz, and set the SSPM bits to:
    "0011 = SPI Master mode, clock = TMR2 output/2"
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Tuurbo46
    Super Member
    • Total Posts : 232
    • Reward points : 0
    • Joined: 2004/09/12 05:05:45
    • Location: UK
    • Status: offline
    Re: 18F4520 SSPADD Calculation Confirmation 2019/12/04 06:13:37 (permalink)
    0
    Hi ric,
     
    Sorry i did mean I2C.  Is TMR2 still relevant to I2C?
     
    Thanks,
     
    Tuurbo46
     
     
    #3
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: 18F4520 SSPADD Calculation Confirmation 2019/12/04 12:20:56 (permalink)
    0
    Tuurbo46
    Sorry i did mean I2C.  Is TMR2 still relevant to I2C?

    No, not in I2C mode.
    Review section "17.4.7 BAUD RATE" in the datasheet. In particular, SSPADD is only 7 bits, so the maximum value you can use is 127. I don't think you can get down to 50kHz with a 32MHz Fosc.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5