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

I need I2C or SPI examples

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







I need I2C or SPI examples
PostPosted: Wed Feb 05, 2003 9:13 am     Reply with quote

I'm trying for some days make a comunication between two pics's, but it don't work. I need same simple example about I2C or/and SPI, that implement a comunication between a PIC 16f873 and 18f452. My compiler version is 3.082

Sorry about the poor english.

Antonio
___________________________
This message was ported from CCS's old forum
Original Post ID: 11301
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: I need I2C or SPI examples
PostPosted: Wed Feb 05, 2003 4:44 pm     Reply with quote

<font face="Courier New" size=-1>:=I'm trying for some days make a comunication between two pics's, but it don't work. I need same simple example about I2C or/and SPI, that implement a comunication between a PIC 16f873 and 18f452. My compiler version is 3.082
:=
:=Sorry about the poor english.
:=
:=Antonio

You can use the SS pin to keep the chips in sync

Wire a master pin to slave SS
Wire the master SCK (out) to slave SCK (in)
Wire the master SDI (in) to slave SDO (out)
Wire the master SDO (out) to slave SDI (in)

On the master

initialize port
setup_spi( spi_master | spi_l_to_h | spi_clk_div_16 );

Set Slave select pin low
output_low(PIN_A0);

Send byte Y /recieve byte X
X1 = spi_read(Y1);
X2 = spi_read(Y2);

Set slave select high
output_high(PIN_A0);

Two bytes were sent two recieved

On the slave

initialize port
setup_spi( spi_slave | spi_l_to_h );

Wait for SS to go low
while ( input(PIN_A5) );

Send byte X /recieve byte Y
Y1 = spi_read(X1);
Y2 = spi_read(X2);

wait for SS to go high
while ( !input(PIN_A5) );

Two bytes were sent two recieved

</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 11320
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