Today 02:58
Forum: Proton Plus Compiler v3
Starter: xldaedalus
Views: 0
Replies: 1
Go to last post By: xldaedalus
Yesterday 21:59
Forum: Proton 24
Starter: Jezsmith
Views: 9273
Replies: 29
Yesterday 17:16
Forum: Capture Compare / PWM Modules and Enhanced versions
Starter: dansagenius
Views: 0
Replies: 4
Yesterday 09:03
Forum: Printed Circuit Construction
Starter: myeeplacee
Views: 0
Replies: 2
+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 30
  1. #1
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    111
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Default DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810?

    Hello everyone,

    A while back I used a DSPIC33EP512MU810 in a triple processor voting system.The project went well and it was used to do fast serial communication between three processors.

    I now have a new project where I need very fast SPI communication and I have ordered another DSIC33EP512MU810 development board

    The project is to read multiple SPI sensor devices,

    The sensors will be 10 * LDC1000 inductive sensing chips for 10 channels vibration monitoring,
    3 * LTC2983 Temperature sensing chips for Type K thermocouples and RTD monitoring,

    Firstly when I played with the DSPIC33EP512MU810 I hand coded all the following to learn the peripherals and didn't use any proton 24 commands!

    TX,RX hardware Interrupt driven Uarts 1, Uarts 2 Uart 3
    A/D 12 bit convertor hardware
    PWM Output Compare Module

    it all worked lovely but took me weeks to read the data sheet and hand code all the register setups for the peripherals. I avoided using proton 24 commands and did everything at the register level to learn the peripherals. UART, a/d Ouput compare pwm etc etc

    I have played allot with the LDC1000 inductive sensing chip using a slower 8 bit processor,
    Now I am very comfortable with the LDC1000 I am ready to try it on a faster processor,

    The 33EP512MU810 has 4 Hardware SPI Channels (3 re-mappable PPS, one is fixed SDI2 SDo2 sck2 etc)

    Is there a Proton24 command to do hardware SPI from the proton24 compiler, rather than hand coding and learning all spi peripheral registers
    SPI read SPI write using SPI hardware peripherals SPi1,Spi2,SPi3,SPi4 etc

    I cant seem to find a SPI hardware command

    SHIN and SHOUT are not appropriate software bit banged serial packets. I need to make use of the SPI Hardware for speed.

    Using chip selects I need 10 LCD1000 vibration sensors say five on each SPI1, SPi2 with individual CS chip select for each LDC1000 chip

    Can I modify the SPI_24.inc files to work with the 33EP512MU810 ? is there a SPI_33EP.Inc file anywhere

    or do I have to re-invent the wheel and hand code everything studying Section 18 of the 33EP Reference Manual Serial Peripheral Interface SPI.

    Also is there any examples of DMA transfer with SPI Hardware with proton, there is c30 examples out there it looks very complex.

    However even without DMA if I can use the Hardware SPI with this fast CPU then I can quickly sample all ten LDC1000 sensors.

    Thanks

    Matty

  2. #2
    Member RayEllam's Avatar
    Join Date
    Nov 2004
    Posts
    250
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    0

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Hi Matty,
    What may help is to create a project in MPLABX for the given processor and use the code configurator (MCC) to generate C files for a chosen peripheral. Obviously you will need to translate this to proton but it should give you a good starting point to set up the peripherals required.

    Ray
    [COLOR="Red"][I]A six volt man in a twelve volt world[/I][/COLOR] :cool:

  3. #3
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,113
    Thumbs Up
    Received: 82
    Given: 24
    Total Downloaded
    765.90 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Quote Originally Posted by matty View Post
    Hello everyone,

    ...However even without DMA if I can use the Hardware SPI with this fast CPU then I can quickly sample all ten LDC1000 sensors.

    Thanks

    Matty
    I remember Less commenting the PIC24's are faster bit banging than use of hardware SPI. I'm not 100% sure if this includes the PIC33EP512MU810 or at what Mhz. See Les has just uploaded Bit-bashed (Software) SPI procedures for Proton24!

    Norm

  4. #4
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,113
    Thumbs Up
    Received: 82
    Given: 24
    Total Downloaded
    765.90 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    See Les's post #6
    You should remember, on a PIC24 device, software SPI can be faster than hardware SPI, and the code efficiency for software SPI is excellent because of the architecture of the devices.

    Why do you wish to use the SPI peripheral instead of bitbashed?
    Norm

  5. #5
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    111
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Smile Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Dear, Ray and Normnet

    Thank you both for your helpful replies.

    Ray:
    I do not have MPLAB X I have MPLAB and the older C30 compiler,
    Although I could try downloading MPLAB it and XC16 demo to see if I can generate the files that way and convert to proton.
    There are also some C30 Examples of hardware SPI I could try and convert to proton.

    Normnet:

    Ok so I agree the DSPIC I am using in last project which is clocked at full 70Mips its so fast I could just do a hand coded bit bang routine to get the data.

    In proton 18 I have done such a similar bit bang routine interfacing to a 14 bit absolute rotary encoder.

    I will try and just do a hand coded bit bang routine.

    If I cant get this to work I will go back to Rays Idea to try and convert some C code to get the register setups for the peripheral.

    Either way I will tie the LDC 1000 to SPI2 pins 10,11,12 on the 33EP512Mu810, the other three channles are all PPS peripheral pin select the only spi hardwired is SPI2 10,11,12 pins on the 33EP512Mu810.

    This way I can start of with attempting software bit bashed, by closely studying the spi timing diagrams from the ldc1000 data sheet.

    And if I cant get that bit bash working try hardware spi using some c code examples from microchip as a starting point and convert to proton.

    the new 33EP dev board wont come for a couple of weeks. While im waiting I can start attempting a bit bash routine.

    Will let you know when I get stuck or if I have solved it will post my solution in couple of weeks whe board comes

    Thanks to you both for taking time to guide me.

    Best regards matty

  6. #6
    Fanatical Contributor pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    3,040
    Thumbs Up
    Received: 29
    Given: 29
    Total Downloaded
    832.68 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Hi Matty,
    I don't think the Code Configurator works with DSPIC33, unless there has been an update since I last used it.
    Unless you really like a challenge, I would avoid using the SPI with DMA if possible. Lots of examples in C, but not easy to port over to PDS. I tried it with CAN bus, after success with CAN on PIC18F's, (Thanks Bob!) but after a frustrating week with no joy using DMA with CAN, I realised that putting a hot soldering iron in my eyeball or a week would have been less painful.

    Good luck!

    Regards
    John

  7. #7
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    111
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Hi John,

    Firstly sorry for the delayed reply, I have been away for a few days,

    Well thanks for the advice I agree it will be very difficult to port SPI with DMA examples in C over to proton.

    What I am going to do is first attempt to just do a bit bash version of the LDC100 spi driver and if it works problem solved. If not I will have to study the 33f reference manual section 18 SPi and try and manually setup all the SPI registers.

    I agree it is very difficult trying to convert C30 code to proton.
    I made a DC motor positioner with a large actuator using a 33FJ32Gp202 all done in c30 I also post in C30 see thread about that project here

    http://www.microchip.com/forums/m858053.aspx

    I tried converting the C30 code from this into proton 24 spend nearly a weekend on it just couldn't convert the code it was just to different.

    I have attempted a bit bash routine for the LDC 1000 it is so close to working just not quite right ill post it here later today when I have tidied the code up

    thanks for the support john will post the bit bash version later today along with a hardware spi version that does work.

  8. #8
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    111
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    Dear All,


    I have attempted to write a hand coded bit bash routine. for LDC1000

    I have done it on an 18F252 just to practice before my new 33EP512MU810 arrives in the post.


    The following is all done on a 18F252 I have 2 programs


    1) I have a Hardware SPI version which works lovely and successfully gets the data out of the LDC1000
    2) I have a a Software bit-bashed SPI this is so close it actually works and gets LDC1000 data but its but not quite correct data is twice as big as it should be.


    The LDC1000 SPI is digital inductance converter and measures proximity distance from a inductive sensot to a metal target.
    It works from say 0mm to 4mm gap from sensor to metal target = 0-32768 on proximity register.

    So hardware spi works fine
    But software spi actually works to but I am getting the wrong numbers

    gap is set to 0.5mm so im getting a solid reading approx of 27,200 from the proximity register using the hardware SPI code
    gap is set to 0.5mm so im getting a jumpy reading of 54,400 from the proximity register using software SPI Code.

    It is so close to working with the Software SPI it actually reads proximity but the reading is exactly twice as big as it should be and more jumpy

    I think I know why but I cant solve it

    The proximity register is 16 bits 8lsb and 8msb to make a 16 bit register.
    I think the 16 bits are read correctly using hardware SPI but using software SPI something gets out of step and the reading is twice as big
    Because the software spi bit bash proximity reading is twice as big its almost is if effectively proximity = proximity << 1 so all the bits are shifted one to the left making the answer twice as big and making the bits more jumpy.


    I have tried for 3 solid days with the bit bashed spi and cant get it to stop reading double the answer as in reading is twice as big and jumpy.
    I thinks the hand coded bit bash I have attempted is some how missing the the MSB proximity.15 and taking proximity.14 as .15 almost offsetting all the answer or bitshifting the whole 16 bit proximity reading to the left by 1 .

    I have tried again and again cant get it to read correctly using software bit bash my attempt works it reads but the answers double what it should be and readings are jumpy


    Haware spi code

    Code:
    Device = 18F252
    
    
    Xtal = 10
    
    
    Optimiser_Level = 1
    
    
    Dead_Code_Remove = On
    
    Include "SPI.inc"
    
    
    
    
    Dim SPI_data As Byte
    Dim PROXLSB As Byte
    Dim PROXMSB As Byte
    Dim freqlsb As Byte
    Dim freqmsb As Byte
    Dim LOOP As Byte
    Dim prox As Word
    prox = 1000
      
    
     
     
    Output PORTC.0
      
    
    
    
    
    
    
    
    'Declare Rsout_Pin PORTC.6
     
    
    'Declare Rsin_Pin PORTC.7
     
    
    'Declare Rsout_Mode = true
     
    
    'Declare Serial_Baud 9600'38400'19200'9600 
     
    
    'Declare Rsin_Timeout 20
     
    
    'Declare Rsin_Mode 0
     
    
     
     
    
    
    
    
    
    Declare Hserial_Baud = 9600    ' Set baud rate to 9600
    
    
    Declare Hserial_RCSTA = 010000 ' Enable continuous receive
    
    
    Declare Hserial_TXSTA = 100000 ' Enable transmit and asynchronous mode
    
    
    Output PORTC.6
     
    
     Input PORTC.7 
    
    
    PORTC.0 = 1 'CHIP SELECT LINE INITIALLY HIGH
    
    
    Output PORTC.5 'sdo
    
    
    Input PORTC.4  'sdi
    
    
    
    
    
    
      
    
     
     
    
    
    
    
    
    Output PORTC.2 'cs
    
    
    TRISC.2 = 0
    
    Symbol cs = PORTC.2
    
    
      
    
     
     
    
     
     
    
     
     
    GoSub INITIALISE 'WRITE ALL THE CONFIGURATION REGISTERS OF THE LDC 1000
    
    
    
    
    
    
      
    
     
     
    
    
    
    
    
    Main:
      
    
    'PIE1.5 = 1
     
    
    'OpenSPI(SPI_FOSC_64 , MODE_00 , SMPEND)
     
    
    '
     
    
    
    
    
    
    cs = 0
     
    
    WriteSPI($A1)
     
    
    'ReadSPI()
     
    
    
    
    
    
    If DataReadySPI() = 1 Then
    PROXLSB = ReadSPI()'DataReadySPI()
    
    
    
    
    
    
      
    
    'WRITESPI($A2)
     
    
    
    
    
    
    PROXMSB = ReadSPI()'DataReadySPI()
    
    
    
    
    
    
     
    
    'PROXLSB = ReadSPI()'DataReadySPI()
     
    
    'PROXLSB = ReadSPI()'DataReadySPI()
     
    
    
    
    
    
    EndIf
     
    
    
    
    cs = 1
    
    
      
    DelayUS 10
      
    
    'PORTC.0 = 0
     
    
    'WriteSPI($A2)
     
    
    'ReadSPI()
     
    
    'If DataReadySPI() = 1 Then
     
    
    'PROXMSB = ReadSPI()'DataReadySPI()
     
    
    'EndIf
     
    
    'PORTC.0 = 1
     
    
    'DelayUS 200
      
    
     
     
    
    'HRSOut loopd'RSOut loopd
     
    
    'HRSOut loope'RSOut loope
     
    
    
    
    
    
    prox.LowByte = PROXLSB
     
    
    prox.HighByte = PROXMSB
      
    HRSOut  Dec prox,13 
     
    
    'HRSOut PROXLSB
     
    
    'DelayMS 1
     
    
    'HRSOut PROXMSB
     
    
    'DelayMS 1
      
    
    'HRSOut $0
     
    
    'DelayMS 1
     
    
    'HRSOut $0
     
    
    'DelayMS 1
      
    
    'HRSOut $4
     
    
    'DelayMS 1
      
    
    
    
    
    
    GoTo Main
      
    
     
     
    
    CloseSPI()
     
    
    
    
    Stop
      
    
     
     
    
    INITIALISE:
      
    
    cs = 1    'INITIALLY CHIP SELECT HIGH
    
    
    DelayMS 1 'WAITS 1MS
    
    
    
    
    
    
      
    
     
     
    
    'OpenSPI(SPI_FOSC_64 , MODE_11 , SMPEND)
     
    
    
    
    
    
    OpenSPI(SPI_FOSC_4 , MODE_00 , SMPEND)
      
    
     
     
    
    'SET POWER MODE IDLE TO CONFIGURE STUFF
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($0B) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($00) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'RP MAX
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($01) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($0C) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'RP MIN
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($02) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($3A) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'DISABLE ALL INTERRUPT MODES
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($0A) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($02) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET THRESH HI LSB
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($06) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($50) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'THRESH HIGH MSB
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($07) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($14) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'THRESH LOW LSB
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($08) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($C0) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET THRESH LOW MSB
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($09) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($12) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET WATCHDOG MIN
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($03) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($94) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET LDC CONFIG
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($04) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($17) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET CLOCK CONFIG
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($05) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($02) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    'SET POWER MODE TO ACTIVE MODE
     
    
    
    
    
    
    cs = 0 'CHIPS SELECT LOW FOR WRITE
    
    
    WriteSPI($0B) 'WRITE FOLLOWING DATA TO REG 01 RP MAX
    
    
    WriteSPI($01) ''was $13
    
    
    cs = 1 'CHIP SELECT HIGH FOR READ
    
    
    
    
    DelayMS 1
      
    
    
    
    Return
      
    
    
    
    'GoTo Main
      
    
            
      
    
         
     
    
            
      
    
            
     
    
            
     
    
            
      
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
    
    
    
    
    


    Here is the my hand coded bit bash
    it works and reads proximity data but everything seems to be twice as big double the value as if the whole 16 bit data packet is shifted to the left by one


    Code:
    
     
     
    Device = 18F252
      
    
    
    
    
    
    
    
    'On_Interrupt GoTo Isr 
     
    
    
    
    
    
    Xtal = 40'40'10
    
    
    
    
    
    
     
    
     
     
    
    
    
    
    
    Declare Hserial_Baud = 9600    ' Set baud rate to 9600
    
    
    Declare Hserial_RCSTA = 010000 ' Enable continuous receive
    
    
    Declare Hserial_TXSTA = 100000 ' Enable transmit and asynchronous mode
    
    
    Output PORTC.6
     
    
     Input PORTC.7 
     
    
    'Declare Hserial_Clear = On    ' Clear the buffer before receiving
    
    
    All_Digital = True
    
    Input PORTA.4
    
    
      
    
     
     
    
     
     
    
    Config_Start
     
    
    
    
    
    
    PWRT     = On     ' Power Up Timer Enabled
    
    
    WDT      = OFF    ' Watchdog Timer Disabled
    
    
    LVP      = OFF    ' Low Voltage ICSP Disabled
    
    
    Debug    = OFF    ' Background Debugger Disabled
    
    
    osc = hspll'pll
     
    
    
    
    
    
    
    
    Config_End
      
    
    
    
      
    
     
     
    Output PORTC.2        'CHIP SELECT
    
    
    Symbol CS = PORTC.2
    
    
     
    
    CS = 0
      
    Output PORTC.3 'SCK CLOCK
    
    
    Symbol SCK = PORTC.3
    
    
     
    
    SCK = 0
      
    Output PORTC.5 'SDO COMMAND TO LDC1000 SDI
    
    
    Symbol SDO = PORTC.5
    
    
     
    
    SDO = 0
      
    Input PORTC.4 'SDI recieves data from LDC100 SDO
    
    
    
    
    
    
     
    
    'TRISC.4 = 1 ' INPUT
     
    
    
    
    
    
    Symbol SDI = PORTC.4
    
    
      
    
     
     
    Dim SCKLOOP As Byte
    Dim COMMAND As Byte
    Dim COMMAND_POINTER As Byte
    COMMAND_POINTER = 8 
     
    Dim REF As Byte
    
    
      
    
     
     
    
     
     
    
    
    
    'For Index = 7 to 0 Step -1 ' Create a loop for 8 bits
     
    
    'Var1 = GetBit ExVar,Index ' Examine each bit of ExVar
     
    
    'Print Dec1 Var1 ' Display the binary result
     
    
    'DelayMs 100
      
    
    
    
    
    
    Dim PROXLSB As Byte
    Dim PROXMSB As Byte
    Dim PROXIMITY As Word
    Dim COMMANDA As Byte
    Dim COMMANDB As Byte
    Dim INTLOOP As Byte
    GoSub initalise
      
    Dim WASTE As Byte
    WASTE = 230
      
    
     
     
    
    main:
      
    
     
     
    
    CS = 0 'START A TRANSACTION ______
    
    
    
    
    DelayUS 4
      
    
    COMMAND = $A1   'this tells ldc1000 to read proximity register LSB 
    
    
    SDO = 1'COMMAND.7
    
    
    SCK = 1    'clock 1
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 0'COMMAND.6
    
    
    SCK = 1    'clock 2
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 1'COMMAND.5
    
    
    SCK = 1    'clock 3
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 0'COMMAND.4
    
    
    SCK = 1    'clock 4
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 0'COMMAND.3
    
    
    SCK = 1    'clock 5
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 0'COMMAND.2
    
    
    SCK = 1    'clock 6
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = 0'COMMAND.1
    
    
    SCK = 1    'clock 7
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
     
     
    
    SDO = 1'COMMAND.0
    
    
    SCK = 1    'clock 8
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0 'stays high till next cycle
    
    
    
    
    DelayUS 4
      
    
    ''''''''''''''''''''''''''''''''''''''''now reads data so command = $00
      
    
    
    
    
    
    COMMAND = $00   'this tells ldc1000 to read proximity register LSB
    
    
    SDO = 0'COMMAND.7
    
    
    SCK = 1    'clock 1
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.7 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.6
    
    
    SCK = 1    'clock 2
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.6 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.5
    
    
    SCK = 1    'clock 3
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.5 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.4
    
    
    SCK = 1    'clock 4
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.4 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.3
    
    
    SCK = 1    'clock 5
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.3 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.2
    
    
    SCK = 1    'clock 6
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.2 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.1
    
    
    SCK = 1    'clock 7
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXLSB.1 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.0
    
    
    SCK = 1    'clock 8
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 1
     
    
    PROXLSB.0 = SDI
     
    DelayUS 4'
    
    
    
    
    
    
      
    
     
     
    
     
     
    
    
    
    
    
    COMMAND = $00   'this tells ldc1000 to read proximity register LSB
    
    
    SDO = 0'COMMAND.7
    
    
    SCK = 1    'clock 1
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.7 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.6
    
    
    SCK = 1    'clock 2
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.6 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.5
    
    
    SCK = 1    'clock 3
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.5 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.4
    
    
    SCK = 1    'clock 4
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.4 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.3
    
    
    SCK = 1    'clock 5
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.3 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.2
    
    
    SCK = 1    'clock 6
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.2 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.1
    
    
    SCK = 1    'clock 7
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.1 = SDI
     
    DelayUS 1
      
    
     
     
    
    SDO = 0'COMMAND.0
    
    
    SCK = 1    'clock 8
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    
    PROXMSB.0 = SDI
     
    DelayUS 4
      
    
    CS = 1
     
    
    SDO = 1
      
    
     
     
    
    PROXIMITY.LowByte = PROXLSB
     
    
    PROXIMITY.HighByte = PROXMSB
      
    
    'PROXIMITY.15 = PROXMSB.7
     
    
    'PROXIMITY.14 = PROXMSB.6
     
    
    'PROXIMITY.13 = PROXMSB.5
     
    
    'PROXIMITY.12 = PROXMSB.4
     
    
    'PROXIMITY.11 = PROXMSB.3
     
    
    'PROXIMITY.10 = PROXMSB.2
     
    
    'PROXIMITY.9 = PROXMSB.1
     
    
    'PROXIMITY.8 = PROXMSB.0
      
    
    'PROXIMITY.7 = PROXLSB.7
     
    
    'PROXIMITY.6 = PROXLSB.6
     
    
    'PROXIMITY.5 = PROXLSB.5
     
    
    'PROXIMITY.4 = PROXLSB.4
     
    
    'PROXIMITY.3 = PROXLSB.3
     
    
    'PROXIMITY.2 = PROXLSB.2
     
    
    'PROXIMITY.1 = PROXLSB.1
     
    
    'PROXIMITY.0 = PROXLSB.0
      
    
    'PROXIMITY = PROXIMITY >> 1
      
    
    'PIE1.5 = 1 'enable ISR driven comms
      
    
    'If var1 = 55 Then txflag = 1
     
    
    'If var1 = 56 Then txflag = 0
      
    
     
     
    
    'If txflag = 1 Then HRSOut loopd' transmits lowbyte of result
      
    
    
    
    
    
    HRSOut Dec PROXIMITY,13
     
    
    'hrsout "beans",13
     
    
    'HRSOut  PROXLSB
     
    
    'DelayMS 1
     
    
    'HRSOut  PROXMSB
     
    
    
    
    
    
    DelayMS 1
      
    
     
     
    
    'HRSOut $0
     
    
    'DelayMS 1
     
    
    'HRSOut $0
     
    
    'DelayMS 1
      
    
    'HRSOut $4
     
    
    'DelayMS 1
      
    
    
    
    
    
    GoTo main
      
    
    initalise:
      
    
    CS = 1
     
    DelayMS 1
      
    For INTLOOP = 0 To 11 '24 registers to write
    
    
    
    
    
    
      
    
     
     
    
     
     
    
    
    
    
    
    CS = 0 'START A TRANSACTION ______
    
    
    
    
    If INTLOOP = 0 Then COMMANDA = $0B:COMMANDB = $00
     
    If INTLOOP = 1 Then COMMANDA = $01:COMMANDB = $0C
     
    If INTLOOP = 2 Then COMMANDA = $02:COMMANDB = $3A
     
    If INTLOOP = 3 Then COMMANDA = $0A:COMMANDB = $02
     
    If INTLOOP = 4 Then COMMANDA = $06:COMMANDB = $50
     
    If INTLOOP = 5 Then COMMANDA = $07:COMMANDB = $14
     
    If INTLOOP = 6 Then COMMANDA = $08:COMMANDB = $C0
     
    If INTLOOP = 7 Then COMMANDA = $09:COMMANDB = $12
     
    If INTLOOP = 8 Then COMMANDA = $03:COMMANDB = $94
     
    If INTLOOP = 9 Then COMMANDA = $04:COMMANDB = $17
     
    If INTLOOP = 10 Then COMMANDA = $05:COMMANDB = $02
     
    If INTLOOP = 11 Then COMMANDA = $0B:COMMANDB = $01
      
    
     
     
    
     
     
    
    SDO = COMMANDA.7
     
    
    SCK = 1    'clock 1
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.6
     
    
    SCK = 1    'clock 2
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.5
     
    
    SCK = 1    'clock 3
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.4
     
    
    SCK = 1    'clock 4
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.3
     
    
    SCK = 1    'clock 5
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.2
     
    
    SCK = 1    'clock 6
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDA.1
     
    
    SCK = 1    'clock 7
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
     
     
    
    SDO = COMMANDA.0
     
    
    SCK = 1    'clock 8
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 1 'stays high till next cycle
    
    
    
    
    DelayUS 4
      
    
    ''''''''''''''''''''''''''''''''''''''''
     
    
    
    
    
    
    SDO = COMMANDB.7
     
    
    SCK = 1    'clock 1
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.6
     
    
    SCK = 1    'clock 2
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.5
     
    
    SCK = 1    'clock 3
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.4
     
    
    SCK = 1    'clock 4
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.3
     
    
    SCK = 1    'clock 5
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.2
     
    
    SCK = 1    'clock 6
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
    SDO = COMMANDB.1
     
    
    SCK = 1    'clock 7
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 0
     
    DelayUS 1
      
    
     
     
    
    SDO = COMMANDB.0
     
    
    SCK = 1    'clock 8
    
    
    
    
    DelayUS 1
     
    
    SCK = 0
     
    
    SDO = 1 'stays high till next cycle
    
    
    
    
    DelayUS 4
      
    
    CS = 1
     
    DelayMS 1
      
    Next  INTLOOP
      
    
     
     
    
     
     
    
     
     
    
     
     
    
    
    
    Return
      
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
     
     
    
    
    
    
    I have tried bit shifting the answer to the right as in proximity = proximity >> 1 this does bring the answer to approx. right value but the reading is jumpy because I think we have lost one of the bits and the software bit bash is some how getting bits 14-0 instead of 15 - 0 meaning we loose a bit of resolution

    Any thoughts sorry for very long post

    I have attached all the actual 4 channel oscilloscope shots of the hardware vs bitbashed spi code in action running on the PIC
    Attached Images Attached Images

  9. #9
    Member matty's Avatar
    Join Date
    Dec 2003
    Posts
    111
    Thumbs Up
    Received: 6
    Given: 3
    Total Downloaded
    228.03 MB

    0 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    sorry missed a picture of software spi on scope
    see attached
    Attached Images Attached Images

  10. #10
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    214
    Thumbs Up
    Received: 27
    Given: 0
    Total Downloaded
    76.31 MB

    1 Not allowed!

    Default Re: DSPIC33EP512MU810 How to use Hardware SPI can SPI_24.inc be used for 33EP512MU810

    You have to read the data before the clock pulse, not after it.

    You might try using the Shout/Shin commands. That would be a lot easier than what you're doing now.
    Take a look at the Shiftin_Shiftout_Demo.bas in the Samples24 folder for examples.

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Hardware SPI - LSB first
    By towlerg in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 1st August 2016, 17:14
  2. Hardware SPI
    By Maxim in forum Proton 24
    Replies: 9
    Last Post: 19th March 2015, 01:34
  3. Hardware SPI
    By CPW1992 in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 28th June 2008, 05:24
  4. SPI hardware with 2 PICS
    By nigelstephens in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 9th March 2008, 21:10
  5. SPI Software / Hardware
    By dmTulsa in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 27th October 2006, 21:50

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