CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

SPI Interface

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
balamagesh
Guest







SPI Interface
PostPosted: Wed Feb 12, 2003 3:14 am     Reply with quote

I am using 16F73 with digital pot(MCP41050) and trying to control digital pot through SPI interface. The below is code used by me. Can anybody help me with modified sample code to make it work. pin RC3 -> SCK , pin RC4 -> SI , pin RB0 -> CS.

The code is as follows:

setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16);
output_high(PIN_B0);
spi_write(3);
spi_write(0x00);
output_low(PIN_B0);

Thanks in Advance
Balamgesh
___________________________
This message was ported from CCS's old forum
Original Post ID: 11585
dave.t
Guest







Re: SPI Interface
PostPosted: Wed Feb 12, 2003 3:29 am     Reply with quote

:=I am using 16F73 with digital pot(MCP41050) and trying to control digital pot through SPI interface. The below is code used by me. Can anybody help me with modified sample code to make it work. pin RC3 -> SCK , pin RC4 -> SI , pin RB0 -> CS.
:=
:=The code is as follows:
:=
:= setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16);
:= output_high(PIN_B0);
:= spi_write(3);
:= spi_write(0x00);
:= output_low(PIN_B0);
:=
:=Thanks in Advance
:=Balamgesh


Here is some code I have recently used and works fine-

void digi_pot(char data);

void digi_pot()

{

char count,command,pot_data;

pot_data=data;
command=digi_command; // 0x11

#asm
bcf clock // make sure clock is low
movlw 0x08 // load
movwf count // first 8 bit count
bcf chip_select // select chip

cmlp:bcf serial_out // data line low
rlf command,f // move command out to carry msb first
btfsc carry
bsf serial_out // data out high
nop // allow data
nop // to settle
bsf clock // clock high
nop // wait
nop // wait
bcf clock // clock low
nop
decfsz count,f // all bits clocked out?
goto cmlp
// yes!
movlw 0x08 // load
movwf count // second 8 bit count

dblp:bcf serial_out
rlf pot_data,f // pot value
btfsc carry
bsf serial_out // data output high
nop // allow data
nop // to settle
bsf clock // clock high
nop // wait
nop // wait
bcf clock // clock low
nop
decfsz count,f // all bits clocked out?
goto dblp
bsf chip_select // yes! all sixteen bits clocked out
// chip select is now taken high to latch data and update pot!
#endasm

}

Regards
Dave T.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11586
R.J.Hamlett
Guest







Re: SPI Interface
PostPosted: Wed Feb 12, 2003 4:20 am     Reply with quote

:=I am using 16F73 with digital pot(MCP41050) and trying to control digital pot through SPI interface. The below is code used by me. Can anybody help me with modified sample code to make it work. pin RC3 -> SCK , pin RC4 -> SI , pin RB0 -> CS.
:=
:=The code is as follows:
:=
:= setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16);
:= output_high(PIN_B0);
:= spi_write(3);
The command format for the chip, is that the first byte contains the command data, in the form:
xxccxxpp (in binary)
You are sending a command (cc bits) of '00', which is a 'no action' command. To address both potentiometers, needs a first byte of:
xx01xx11
So try:
spi_write(0x13);

:= spi_write(0x00);
Presumably you are trying to set the pots to zero?. If so this is OK.

:= output_low(PIN_B0);
:=
:=Thanks in Advance
:=Balamgesh

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 11587
Bruce R. Knox
Guest







Re: SPI Interface
PostPosted: Wed Feb 12, 2003 9:43 am     Reply with quote

:=I am using 16F73 with digital pot(MCP41050) and trying to control digital pot through SPI interface. The below is code used by me. Can anybody help me with modified sample code to make it work. pin RC3 -> SCK , pin RC4 -> SI , pin RB0 -> CS.
:=
:=The code is as follows:
:=
:= setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16);
:= output_high(PIN_B0);
:= spi_write(3);
:= spi_write(0x00);
:= output_low(PIN_B0);
:=
:=Thanks in Advance
:=Balamgesh

The chip select is active LOW - so use output_low(PIN_B0) to select it and output_high(PIN_B0) to de-select it. Also,
make sure you set B0 high when you initialize the i/o port at the beginning of your program.

As someone else said - the first byte you send should be 0x13 to set both pots (0x11 for Pot 0 || 0x12 for Pot 1).

Then it should work.

Bruce
___________________________
This message was ported from CCS's old forum
Original Post ID: 11599
Balamagesh
Guest







Re: SPI Interface
PostPosted: Tue Feb 25, 2003 4:33 am     Reply with quote

:=:=I am using 16F73 with digital pot(MCP41050) and trying to control digital pot through SPI interface. The below is code used by me. Can anybody help me with modified sample code to make it work. pin RC3 -> SCK , pin RC4 -> SI , pin RB0 -> CS.
:=:=
:=:=The code is as follows:
:=:=
:=:= setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_16);
:=:= output_high(PIN_B0);
:=:= spi_write(3);
:=The command format for the chip, is that the first byte contains the command data, in the form:
:=xxccxxpp (in binary)
:=You are sending a command (cc bits) of '00', which is a 'no action' command. To address both potentiometers, needs a first byte of:
:=xx01xx11
:=So try:
:=spi_write(0x13);
:=
:=:= spi_write(0x00);
:=Presumably you are trying to set the pots to zero?. If so this is OK.
:=
:=:= output_low(PIN_B0);
:=:=
:=:=Thanks in Advance
:=:=Balamgesh
:=
:=Best Wishes

Thanks .The below code didnt work for me. should there be any delay in between (or) the data should be spi_write(0x13ff).
Pls help me in this

setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
output_low(PIN_B0);
spi_write(0x13);
spi_write(0xff); //setting pot to high
output_high(PIN_B0);

Thanks
Bala
___________________________
This message was ported from CCS's old forum
Original Post ID: 12076
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group