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

HW SPI

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



Joined: 01 Feb 2011
Posts: 32
Location: 53

View user's profile Send private message AIM Address

HW SPI
PostPosted: Wed Sep 14, 2011 10:05 am     Reply with quote

Hi, - I'm new to the CCS compiler and programming in C, but not new to programming PICs.

I'm trying to drive an HCMS-2963 display using the SPI interface.

I'm using a 16f876a chip and pins are configured correctly for hardware SPI implementation.

I've read the manual and #use spi seems to be quite simple (unless I'm missing the point).

My understanding is that once I have set the following line:
Code:

#use spi (FORCE_HW, BITS=8, STREAM=SPI_STREAM)

All i need to do is:
Code:

spi_xfer(data);

To send out my data.

Am I correct in saying that #use spi handles all of the configuration or do I need set the appropriate registers.

If anybody could point me in the direction of some code examples that would be really helpful.

Any assistance would be appreciated. Thx








PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 14, 2011 12:16 pm     Reply with quote

Whether or not #use spi() works, or also, what specific parameters are
required, is highly dependent upon your compiler version. Please post
your version.
jmaudley



Joined: 01 Feb 2011
Posts: 32
Location: 53

View user's profile Send private message AIM Address

PostPosted: Thu Sep 15, 2011 1:20 am     Reply with quote

I'm using the PCWH compiler

IDE 4.107
PCB 4.107
PCM 4.107
PCH 4.107
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 15, 2011 3:07 pm     Reply with quote

I think it would be much easier to use the setup_spi() method of
configuring the hardware SPI module. Example:
Code:

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)

//========================
void main()
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
.
.
.


Then, to write an 8-bit value to the slave, you can use:
Code:

spi_write(data);


Here are some examples of spi driver code:
http://www.ccsinfo.com/forum/viewtopic.php?t=44786&start=1
http://www.ccsinfo.com/forum/viewtopic.php?t=37687&start=11
http://www.ccsinfo.com/forum/viewtopic.php?t=45258&start=3
http://www.ccsinfo.com/forum/viewtopic.php?t=41008&start=5
http://www.ccsinfo.com/forum/viewtopic.php?t=40443&start=1
jmaudley



Joined: 01 Feb 2011
Posts: 32
Location: 53

View user's profile Send private message AIM Address

PostPosted: Fri Sep 16, 2011 1:38 am     Reply with quote

Thanks for the advice.

I'll give that a try.
jmaudley



Joined: 01 Feb 2011
Posts: 32
Location: 53

View user's profile Send private message AIM Address

PostPosted: Fri Sep 16, 2011 7:57 am     Reply with quote

Very Happy

Got it working (my first C project).

Good to know I'm not on my own.

PCM programmer - thx for taking the time to help.
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