PDA

View Full Version : MCP41XXX SPI Write



johnmiller
- 1st December 2008, 22:00
Hi.
I cannot write a new value to a mcp41010 SPI Digital Potentiometer. What I'm trying to do is


WriteSPI:
CS = 0 ' Enable serial EEPROM
Shiftout SI, SCK, MSBFIRST, [$06] ' Send write enable command
CS = 1 ' Disable to execute command
CS = 0 ' Enable
Shiftout SI, SCK, MSBFIRST, [$02, 0, 0, UpdPotVal] ' Send address and data
CS = 1 ' Disable

RETURN


UpdPotVal goes from 0 to 255

Can somebody please tell me what I am doing wrong. Here is a C code that does the same thing in case somebody knows how to make use of it!



#define CS PIN_B4
#define SCLK PIN_B2
#define SI PIN_B1

set_pot (int data) {
BYTE i;
BYTE cmd[2];

cmd[0] = data;
cmd[1] = 0x11;

output_low(SCLK);
output_low(CS);

for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));

output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}

shutdown_pot () {
BYTE i;
BYTE cmd[2];

cmd[0] = 0;
cmd[1] = 0x21;

output_low(SCLK);
output_low(CS);

for(i=1;i<=16;++i) {
output_bit(SI, shift_left(cmd,2,0));

output_high(SCLK);
output_low(SCLK);
}
output_high(CS);
}


Regards

johnmiller
- 1st December 2008, 22:32
Ok. I found my problem. If anybody needs this...



WriteSPI:
GOSUB GetPotVal
CS = 0 ' Enable
Shiftout SI, SCK, MSBFIRST, [$11, UpdPotVal]
CS = 1 ' Disable


Thanks to me :)

achilles03
- 27th January 2009, 16:34
I know this thread is a little old, but I'm having a similar problem writing to a MCP41010. I've breadboarded it, and I know the PIC (16F628A) is working because the LED works as it should (I always put that in to make sure the chip's actually operating and running the program).

Here's the datasheet for the MCP41010:
http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf

Here's the relevant code:
-----------------------------------------------------
cmcon=7
define osc 8

res var byte
command var byte

SI var porta.4 'SI
CLK var porta.3 'CLK
CS var porta.2 'CS
LED var porta.1 'LED

high porta.2
command=19
high LED
pause 1000
low LED
pause 1000
high LED

repeatit:
res=256
low CS
shiftout SI,CLK,1,[%00010011\8,res\8]
HIGH CS
pause 5000
res=128
low CS
shiftout SI,CLK,1,[command,res]
HIGH CS
pause 5000
goto repeatit

end
-----------------------------------------------------

I've tried entering the command like both as binary and a variable to see if that has any effect, but the chip consistently reads 4.7kOhm.

Any advice or help is appreciated!

Dave

Darrel Taylor
- 27th January 2009, 19:42
Do you have a pull-up resistor on PORTA.4?

It has an "Open collector" output, and can't go HIGH by itself.
<br>

achilles03
- 27th January 2009, 19:53
Do you have a pull-up resistor on PORTA.4?

It has an "Open collector" output, and can't go HIGH by itself.
<br>

Garsh, I think that's it. I knew there was something about one of the pins I was forgetting. I'll try that tonight and see what happens.

So long as I use the CMCON=7 command, is porta.4 the only tricky pin I need to worry about? I also set the configuration byte to disable everything.

Thanks!
Dave