PIC24EP SPI Write Timing CPOL = 0 CPHA =1


+ Reply to Thread
Results 1 to 8 of 8

Thread: PIC24EP SPI Write Timing CPOL = 0 CPHA =11210 days old

  1. #1
    tadd
    Guest tadd's Avatar

    0 Not allowed!

    Default PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    hello friends

    i try the use AD5293 digital potentiometer, comunication is different spi, Write Timing CPOL = 0 CPHA =1
    CPOL = 0 that's mean , clock must begin low state MsbFirst_L
    CPHA = 1 that's mean i think about data but i did not understand, how can i configure timing ?

    Code:
    Device = 24EP256GU810
    Declare Xtal = 140
    
    
    PLL_Setup(76, 2, 2, $0300)
    Config FGS = GSS_OFF, GSSK_OFF, GWRP_OFF
    Config FOSCSEL = FNOSC_FRCPLL, IESO_ON
    Config FOSC = FCKSM_CSDCMD, IOL1WAY_ON, OSCIOFNC_OFF, POSCMD_NONE
    Config FWDT = FWDTEN_OFF, PLLKEN_ON, WDTPOST_PS32768, WDTPRE_PR128, WINDIS_OFF
    Config FPOR = ALTI2C1_OFF, ALTI2C2_OFF, BOREN_ON, FPWRT_PWR128
    Config FICD = ICS_PGD1, JTAGEN_ON, RSTPRI_PF
    Config FAS = APL_OFF, APLK_OFF, AWRP_OFF
    
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    TRISD.9 = 0
    TRISD.10 = 0
    TRISD.11 = 0
    TRISc.13 = 0  
    
    Symbol SYNC = PORTD.9
    Symbol DTA = PORTD.10
    Symbol CLK = PORTD.11
    Symbol RDY = PORTC.13
    
    
    
    
    MAIN:
    
    
    Set DTA
    Low SYNC
        DelayUS 1
    Set SYNC
        DelayUS 1
    Low SYNC
        SHOut DTA, CLK , MsbFirst_L, [%0001100000000110\16]
        DelayUS 1
    Set SYNC
    Low DTA
    
    delayms 1000
    goto main

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,397
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    With Proton24, it is much easier to create a library of bit-bashed SPI routines. It is also more beneficial because they can be adapted for any SPI format required.

    I've uploaded a library I was working on here:

    Bit-bashed (Software) SPI procedures for Proton24

    It should give you ideas on how to adapt it for your device, and how straightforward SPI actually is compared to other serial interfaces.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    tadd
    Guest tadd's Avatar

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    it's very complex example for me , PIC24_SPI configuration mode 0, i need mode 1

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,397
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Interfacing to an AD5293 with Proton24

    In order to successfully interface with devices, it is highly recommended to understand the underlying mechanism, otherwise debugging any issues becomes a problem, and quess work. I know this can take some time, and is not always straightforward, but the result is always beneficial, not only for the current device being interfaced with, but for future devices that use a similar mechanism.

    A master SPI write sequence is not really complex if you think about it as the equivalent of 3 I/O lines with LEDs connected to them. All it is, is the same as creating a particular flash pattern on the LEDs (if it was slowed down enough to see the flashes).

    Below is a simple program to interface with the AD5293. Adjusting the timing is done by altering the value in the DelayUs command. It may also be possible to use DelayCs because the peripheral has quite a fast SPI interface:

    Code:
    ' Interface to an AD5293 digital potentiometer chip
    ' Written by Les Johnson for the Proton24 compiler
    '
        Device = 24FJ64GA002 
        Declare Xtal = 32
       
        Declare Hserial_Baud = 9600                         ' UART1 baud rate
        Declare Hrsout1_Pin = PORTB.14                      ' Select which pin is to be used for TX with USART1
    '
    ' Setup the pins for the software SPI routines
    '    
        $define AD5293_DIPin PORTB.2                        ' Connects to the AD5293's DIN pin
        $define AD5293_CLKPin PORTB.0                       ' Connects to the AD5293's SCLK pin
        $define AD5293_SyncPin PORTB.1                      ' Connects to the AD5293's SYNC pin
    
        Dim wRDAC_Value As Word                            ' Holds the 10-bit value to write to the chip
    
    '-----------------------------------------------------------------------------------
    ' Write 16-bits to the SPI bus (Most Significant Bit First).
    ' Input     : pDataOut holds the word to transmit to the SPI interface
    ' Output    : None
    ' Notes     : None
    '
    Proc SPI_Write16(pDataOut As Word)
        Dim Index As Byte
        
        For Index = 15 To 0 Step -1             ' 16-bit SPI loop       
            AD5293_DIPin = pDataOut.15          ' Put the current outgoing bit on AD5293_DIPin
            pDataOut = pDataOut << 1            ' Shift the next bit into MSB
            Set AD5293_CLKPin                   ' Set AD5293_CLKpin high
            DelayUS 1
            Clear AD5293_CLKPin                 ' Pull AD5293_CLKpin low       
        Next
    EndProc
    
    '-----------------------------------------------------------------------------------
    ' Adjust the AD5293 digital potentiometer
    ' Input     : pValue holds the 10-bit value to write to the chip
    ' Output    : None
    ' Notes     : None
    '
    Proc AD5293_Write(pValue As Word)
        Clear AD5293_SyncPin                                 ' Enable the SPI interface
        SPI_Write16($1802)                                  ' Unlock the chip
        Set AD5293_SyncPin                                  ' Disable the SPI interface
        pValue.10 = 1                                       ' Set to write serial register to the RDAC (C0)
        Clear AD5293_SyncPin                                ' Enable the SPI interface
        SPI_Write16(pValue)                                 ' Write to the peripheral
        Set AD5293_SyncPin                                  ' Disable the SPI interface   
    EndProc
    
    '-----------------------------------------------------------------------------------
    ' Setup the peripherals and I/O pins
    '
    Proc Setup()
         RPOR7 = 3                                          ' Make Pin RP14 U1TX
         
         CLKDIV = 0                                         ' CPU peripheral clock ratio set to 1:1  
         Write_OSCCONH($10)                                 ' Enable PLL
         
         Low AD5293_DIPin                                   ' SPI DI to output low
         Low AD5293_CLKPin                                  ' SPI CLK to output low
         High AD5293_SyncPin                                ' SPI Sync to output high
    EndProc
        
    '---------------------------------------------------------------- 
    ' The main program loop starts here
    '
    Main:
        Setup()
         
        While
            For wRDAC_Value = 0 To 1023
                AD5293_Write(wRDAC_Value)
                HRSOut Dec wRDAC_Value, 13
                DelayMS 10
            Next
        Wend
    
    '----------------------------------------------------------------
    ' For internal oscillator with PLL
    '   
        Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF, ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
        Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL, FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE 
    The AD5293 chip's datasheet is very obscure, and doesn't quite go into enough details about the interface or the command structure. It's also one of the most obscure digital pots that I've written code for. They are usually very simple to interface with, but this chip requires things that simply don't make sense :-)

    The code has been tested on the Proteus/Isis simulator.
    Last edited by top204; 26th July 2016 at 12:29.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    tadd
    Guest tadd's Avatar

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    thank you very much Les

    i tryed code, i can't see RDY pin set when SYNC set. may be my 5293 damaged, ordered new one

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,397
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    The above code does not use the RDY signal from the chip because it is capable of high speed transactions.

    However, the RDY pin could come in useful just to make 100% sure that the chip is ready for the next cimmand. The code would simply make a pin an input and check that the RDY pin is ready before sending another command, via a While-Wend or Repeat-Until machanism.

    Before you give up on your chip, simply try a delay between the commands sent to the chip. This will indicate that the chip is working because it will operate if OK.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    tadd
    Guest tadd's Avatar

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    my Ad5293 dead and i could not find new one but there is AD5292 in stok Farnell, only difference is 5292 has memory

    Les , can i use AD5292 with this code ?

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    tadd
    Guest tadd's Avatar

    0 Not allowed!

    Default Re: PIC24EP SPI Write Timing CPOL = 0 CPHA =1

    new Ad5293 arrived me and code is working Thank you very much Les

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. pic24EP timer macros and example
      By tadd in forum Absolute Beginners Section
      Replies: 4
      Last Post: 18th February 2017, 17:05
    2. PIC24EP SPI problem
      By tadd in forum Absolute Beginners Section
      Replies: 8
      Last Post: 18th July 2016, 12:06
    3. Timing on 24EP
      By Handyman in forum Proton 24
      Replies: 6
      Last Post: 13th December 2015, 16:13
    4. SPI - (Can't belive a search on SPI yields no results?)
      By Peter Truman in forum Proton Plus Compiler v3
      Replies: 12
      Last Post: 30th September 2012, 10:12
    5. [SOLVED !] Timing and counting
      By pmcleod in forum Proton Plus Compiler v3
      Replies: 6
      Last Post: 26th August 2007, 22:07

    Tags for this Thread

    Posting Permissions

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