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

help me on my first program with SPI

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

help me on my first program with SPI
PostPosted: Wed Oct 07, 2009 4:02 pm     Reply with quote

Hi

I like start my study on SPI communication, but I don’t understand some questions.
For example,
Is possible I transmit a string between two PICs?
Someone can explain me how I can make this “simple” example.
On PIC master I have two switches connected on PIN_C0 and PIN_C1, and on slave PIC I have one led on PIN_B7. I like if I press PIN_C0 led turn-on, if I press PIN_C1 led turn-off.
But I like witch when I press PIN_C0 write slave PIC an string “ON” if a press PIN_C1 write on slave PIC a string “OFF”, and after read by slave it make operation.

If is possible help me make this little program for I can start used this protocol…

PS: I used PIC18F252

Best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 4:20 pm     Reply with quote

See these threads for sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=39145
http://www.ccsinfo.com/forum/viewtopic.php?t=26888
They show how to send and receive bytes between two PICs,
with one PIC as the SPI master and the other PIC as the SPI slave.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 6:34 pm     Reply with quote

Hi

thanks PCM Programmer, in your 1ª link in slave PIC, if I choose on Master charter 'A' (read ADC) it wait for adc result from slave PIC, correct? but where slave PIC stay write to master?

I don't understand this.... slave PIC don't need some like spi_write()?

best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 7:15 pm     Reply with quote

The slave is writing directly to the SPI buffer register. Example:
Code:
 SSPBUF = adc_result;
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Oct 08, 2009 5:32 am     Reply with quote

Hi

In "#byte SSPBUF = 0x13"? How I know register on 18F252?

But master go there read? Slave don't need send information to master?

best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 08, 2009 12:57 pm     Reply with quote

Quote:
How I know register on 18F252?

Download the 18F252 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39564c.pdf
Find the SSPBUF address in this section:
Quote:
TABLE 4-1: SPECIAL FUNCTION REGISTER MAP



Quote:
Slave don't need send information to master?

It does. The slave puts the data into SSPBUF. Then the master
reads the data from the slave with this line:
Code:
 result = spi_read(0);     
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