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 CCS Technical Support

Own version of SPI_WRITE

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



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

Own version of SPI_WRITE
PostPosted: Wed Aug 30, 2006 7:58 am     Reply with quote

Hello

I am having a real issue finding a bug with spi_write(). I was wondering if anyone had any simple code to replicate spi_write but in ccs-c?

thanks
Ttelmah
Guest







PostPosted: Wed Aug 30, 2006 8:26 am     Reply with quote

I did a little SPI library for my own use a while ago.
Code:

#if define (__PCH__)
  #byte   SSPBUF = 0xFC9
  #byte   SSPCON = 0xFC6
  #byte   I2CBUF = 0xFC8
  #byte   SSPSTAT = 0xFC7
#else
  #byte   SSPBUF = 0x13
  #byte   SSPCON = 0x14
  #byte   I2CBUF = 0x93
  #byte   SSPSTAT = 0x94
#endif

/* Now the SSP handler code. Using my own, since the supplied routines test the wrong way round for my needs */
#DEFINE   READ_SSP()     (SSPBUF)
#DEFINE   WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
#DEFINE   WRITE_SSP(x)   SSPBUF=(x)
#DEFINE   CLEAR_WCOL()   SSPCON=SSPCON & 0x3F


A emulation of the spi_write function, would be:

WRITE_SSP(value);
WAIT_FOR_SSP();

However I wanted the two operations to be seperate, since I can then write a character, let the hardware 'get on' with doing the transfer, and only test that a transfer has completed when I next need to write, with:

WAIT_FOR_SSP(); //Test last transfer has completed
value=READ_SSP(); //retrieve last transfer if required
WRITE_SSP(new_value); //and start the next transfer.

Best Wishes
theteaman



Joined: 04 Aug 2006
Posts: 98

View user's profile Send private message

PostPosted: Wed Aug 30, 2006 8:35 am     Reply with quote

Thank you very much ttelmah! I will use these macros and hopefully it all works!! Smile (I was sure I saw this code of yours somewhere else on the forum but i couldnt remember how i found it witht the 'search' function).
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