Shop OBEX P1 Docs P2 Docs Learn Events
SPI + Digital potentiometer question — Parallax Forums

SPI + Digital potentiometer question

Phillysteak527Phillysteak527 Posts: 5
edited 2012-08-17 06:37 in Propeller 1
Hello all,

I have searched for any help on this topic but haven't had any success. I am trying to control a digital potentiometer via the propeller using a 3 wire SPI protocol. There is an object in OBEX designed to control a similar device (MCP41xxx.spin) and I was trying to adapt it to work with the MCP4161, my issue is more of a basic SPI issue. I'm reading off of the CS and SDI pins of the device with an oscilloscope and cannot get my program to send any serial data. Below is the code snippet for the potentiometer setting, and the transmit segment of the MCP41xxx object. I am just calling the "setpot" from my main program with no response.

Any assistance is greatly appreciated.
PUB setpot(pot, value) | packet
  if pot < POT_0 or pot > POT_BOTH or value < 0 or value > 255
    return 1
  else
    packet.byte[0] := CMD_WRITE | pot
    packet.byte[1] := value
    write(16, packet)          
PRI write(Bits,Data) | temp                             ' Send DATA MSB first
  outa[CS] := 0                                         ' clear CS 
  temp := 1 << ( Bits - 1 )
  repeat Bits
    outa[SI] := (Data & temp)/temp                      ' Set bit value
    outa[SCK] := 1                                      ' Clock bit
    outa[SCK] := 0                                      ' Clock bit
    temp := temp / 2
    outa[SI] := 0
  outa[CS] := 1                                         ' set CS to 1      

Thanks in advance

Comments

  • JonnyMacJonnyMac Posts: 9,194
    edited 2012-08-15 13:02
    This is a simpler way (I think) to output data MSBFIRST.
    pub write(bits, data)
    
      outa[CS] := 0                                         ' select device
    
      data <<= (32 - bits)                                  ' move MSB to bit31
      repeat bits
        outa[SI]  := (data <-= 1)                           ' rotate MSB to bit0 for output
        outa[SCK] := 1                                      ' clock the bit
        outa[SCK] := 0
    
      outa[CS] := 1                                         ' deselect
    
  • Mark_TMark_T Posts: 1,981
    edited 2012-08-15 20:28
    You have set DIRA ?
  • Phillysteak527Phillysteak527 Posts: 5
    edited 2012-08-16 07:15
    Thanks for your reply JonnyMac, I tried to use the code you provided but I am still not getting any data output. It runs through the repeat cycle only once before exiting so there must be some issue with the data I am attempting to feed it. Is the syntax I am using to construct the "packet" element correct?

    @Mark_T - DIRA?

    EDIT: I have a USB scope decoding the SPI interface and so far I am not getting anything. The CS pin gets pulled low right before it loops and should be sending data, however I don't get any data output on the SDO line and the CS pin stays low. To me this would indicate that it is not finishing the loop and getting stuck, should I be formatting my data differently? I'll keep playing with it in the meantime.
  • Phillysteak527Phillysteak527 Posts: 5
    edited 2012-08-17 06:37
    I'm getting some rather unusual signals from the prop, I tried capturing the waveform with the digital potentiometer attached and again after I removed it from the breadboard; However the waveform is unchanged. I ordered a logic analyzer, it's been a long overdue purchase and I'm sure it will ease my frustrations a bit, has anyone had issues with propeller pins not cycling properly? See attached waveform graphic; CS [Red] cycles properly (5v to Gnd), but i'm only reading <1v off of the SCK [Blue] and data line [Green].

    P.s.- I am running a board of education
    Non-ground2.jpg
    1024 x 576 - 85K
Sign In or Register to comment.