Spi configuration for fez panda and AD5206 digital pot

Yes, I agree. You have to try and see what works.

im not sure that is right, my first attempt was using that idea sending 0x00 (which is 00000000) as the address and 0xFF (which is 11111111) as the potentiometer value (see my earlier post). that didnt have any effect on the potentiometers resistance.

i had thought this was because it was expecting the 11 bits with the first 3 being the address and the next 5 being the first 5 of the value (from the data sheet) making 8 bits on the first byte. the next byte would contain the last 3 bits of the value (and i thought i would need to add trailing zeros to fill the byte).

now it seems like you guys are going the other ways saying that i just need to send 2 bytes, one with the address and one with the value. but that didnt work.

what in the datasheet would make you think that it was this:
00000AAA, VVVVVVVV (as address, value) 0x00, 0xFF

and not this:
AAAVVVVV, VVV00000 (as address, value) 0x1F, 0xE0

where “A” is an address bit, and “V” is a value bit, “0”'s are leading or training zeros to shore up the bytes. the data sheet is a little over my head, so i cant tell whats its expecting.

does that make any sense?

Try this:


        static byte[] data = new byte[2];
        void digitalPotWrite(byte address, byte value)
        {            
            //  send in the address and value via SPI:
            data[0] = address;
            data[1] = value;

            _spi.Write(data);
        }

I always control CS manually…


static byte[] data = new byte[2];
        void digitalPotWrite(byte address, byte value)
        {            
            //  send in the address and value via SPI:
            
            data[0] = address;
            data[1] = value;
            CS_pin = 0
            _spi.Write(data);
            CS_pin = 1;
        }

I use the same pin but change it in the SPI config… I don’t know why but when I’m debugging it helps me.

There is also a chance that this device needs 11, not 16, or 8 bits if this be the case there is already a SPI bit banging software routine on wiki… This device isn’t speed dependant and the software class is quite fast.

Cheers Ian

I based my snippet on the following arduino example. They send two bytes without packing it into 11 bits, so this should work.

SPI implementation will take care of the CS pin, so you don’t need to set it explicitly.

thanks IanR and architect, so im guessing i dont actually need the WriteRead() in this case? can you link me to where the bit-banging routine is on the wiki?

Just a side note… PR pin isn’t being held low by any chance?

I make quite a few mistakes and keeping it in reset is one of my favorites.

I’ll have to back through the forum to find the link ( If I remember, Gus put it in a competition )

Cheers Ian

Just checked!!!

Architect, I see what you mean with the search function,Hard work

It hasn’t been done yet… Sorry

cheers Ian

PR pin?

UPDATE: im an idiot, i had the commented out config below, i have since replaced it with the uncommented section and now it works:

        
//static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)Cpu.Pin.GPIO_Pin10, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di10, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);

i am also including a little test program for anyone else who wants to try this AD5206 digital potentiometer that shows the necessary config and code for cycling through the possible values of setting the potentiometer at different resistance values (i maxed it at 55 instead of 255 because going above makes to current to the LED to low for it to shine).

as you can see the guys in the forum were right, no bit shifting necessary. i am simply passing one byte for the address (0x00-0x05), one for the value (0x00-0xFF). simple.


public class Program
    {
        static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.Di10, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
        static SPI SPI1;
        static byte[] tx_data = new byte[2];
        static int delay = 50;

        public static void Main()
        {
            // initialize onboard LED
            bool onboardLEDState = false;
            OutputPort onboardLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, onboardLEDState);

            SPI1 = new SPI(config);

            byte potAddress = 0x00;//digipot address (pot 1)
            byte potValue = 0x00;//value to put pot (255 max)

            //int potentiometerMax = 255;
            int potentiometerMax = 55;

            while (true)
            {
                potValue = 0x00; // reset to 0

                while (potValue <= potentiometerMax)// increment to 255
                {
                    SendAddressValueBytes(potAddress, potValue);
                    potValue++;
                    Thread.Sleep(delay);// delay so that you can see LED changing
                }

                //toggle LED state
                onboardLEDState = !onboardLEDState;
                onboardLED.Write(onboardLEDState);
            }


        }

        private static void SendAddressValueBytes(byte potAddress, byte potValue)
        {
            tx_data[0] = potAddress;//digipot address (0x00 = pot1 through 0x05 = pot6)
            tx_data[1] = potValue;//value to put pot (0x00 = 0 through 0xFF = 255)

            //Debug.Print(tx_data[0].ToString());
            Debug.Print(tx_data[1].ToString());
            SPI1.Write(tx_data);
        }

    }

if you want to see the code in action, i took a small video of what it does:

thanks again everyone who contributed to me understanding what SPI was trying to do and how the AD5206 might need to see the incoming data

I am glad it worked for you. You can wrap it up into a driver class and post it on Fezzer.

architect, i posted the drivers and my example here on Fezzer.com:
[url]http://www.fezzer.com/project/268/ad5206-digital-potentiometer/[/url]

i did however say “Your access level doesn’t earn experience.” any ideas why not? is it because its my first post on fezzer?

That is a bug on fezzer. It is getting fixed soon

is it points here or on fezzer? do i get points on here for posting on fezzer? btw fezzer is pretty awesome those who havent looked, if you are trying to get a new accessory working, http://www.fezzer.com is a great place to start. GHI should link to these code snippets from each one of their accessory pages. bluetooth is my next hurdle, but look what i found: [url]http://www.fezzer.com/project/249/bluetooth-interface/[/url], awesome (esp since i just bought that part) !

fezzer is owned by GHI and not it is being integrated with this website…this is why you may may see some problems