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 about SPI

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



Joined: 21 Nov 2012
Posts: 3

View user's profile Send private message

Help about SPI
PostPosted: Wed Nov 21, 2012 11:12 pm     Reply with quote

I'm learning the SPI with the pic18f4520.
In datasheet it was set as:
Code:

SCL PIN_C3
SDO PIN_C4
SDI PIN_C5

I want know how to set it to other PINs.
I try to write the program as follows:
Code:

#include<18f4520.h>....
....
#use SPI(master,DI=PIN_C1,DO=PIN_C0,CKK=PIN_C2)
....
void main()
{
....
setup_spi(spi_master | spi_L_TO_H | SPI_CLK_DIV_16|SPI_SS_DESABLE )
....
}

But it seems useless, it still output in the PIN_C4.

Forgive my poor English.
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 22, 2012 12:20 am     Reply with quote

CCS have two different ways of accessing the SPI bus. I would pick one or the other and not mix them (unless I *really* knew what I was doing).

The first is the setup_spi, spi_read and spi_write functions. These all access the *hardware* SPI device. Hardware SPI has a limited number of pins you can use. Usually you have no choice at all which pin to use - you must use the hardware pins allocated to SPI.

The second method is #use spi with the spi_xfer function. This allows you to define a software SPI bus on just about any pins you like. You can also use the hardware support too.

Since you want to use pins that aren't assigned to the SPI hardware, you must use a software SPI, and that means you must use "#use SPI" and spi_xfer.

A third option is to "bit bang", where you use output_high, output_low and output_float to control the SPI bus signals manually. I've had to do that recently when I goofed my PCB design and swapped the data in and out connections on an SPI device. That's what prototypes are for!
_________________
Andrew
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