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

spi_read()

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



Joined: 15 Apr 2004
Posts: 1

View user's profile Send private message Send e-mail

spi_read()
PostPosted: Thu Apr 15, 2004 11:18 pm     Reply with quote

hello,
how spi_read() function in ccs pic compiler behaves,
writes first and reads next or, reads first and writes next
_________________
Bhaskar Reddy N
INDIA
Ttelmah
Guest







Re: spi_read()
PostPosted: Fri Apr 16, 2004 5:05 am     Reply with quote

bhaskarreddy wrote:
hello,
how spi_read() function in ccs pic compiler behaves,
writes first and reads next or, reads first and writes next

With SPI, read and write are _simultaneous_. The 'write' byte is transferred to the buffer register on the chip, then 8 clock pulses are sent, clocking this byte 'out' on the DOUT line. Then the buffer register is read to return the byte that was clocked in on the DIN line at the same time.
Generally, I do not 'like' the CCS implementation of the SSP function, prefering to clock the data when I want, and read the status of the chip myself. The macros I use (on a 18Fxx2), are:
#byte SSPBUF = 0xFC9
#byte SSPCON = 0xFC6
#byte SSPSTAT = 0xFC7
#bit BF = SSPSTAT.0
#DEFINE READ_SSP() (SSPBUF)
#DEFINE WAIT_FOR_SSP() while(!BF)
#DEFINE WRITE_SSP(x) SSPBUF=(x)
#DEFINE CLEAR_WCOL() SSPCON=SSPCON & 0x3F

These 'seperate' the functions, allowing you to see where the transfers take place. So to emulate the behaviour of the 'SPI_READ(n)' call, you would use:

//put the byte into the output buffer - starts the transfer
WRITE_SSP(n);
//wait for the transfer to complete
WAIT_FOR_SSP();
//Read the returned byte
val=READ_SSP();

These are much more convenient for an interrupt driven SSP system.

Best Wishes
birdasaur_for_life
Guest







Could this method work for PIC TO PIC?
PostPosted: Tue Apr 20, 2004 3:56 pm     Reply with quote

I was wondering how well this would work for performing SPI communication between two PICs.

Have you specifically tried that? I would like to cease using the CCS functions as I too encounter a lot of problems.

If you have tried it then please let me know so I don't waste too much time trying to get it to work.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PIC to PIC I2C
PostPosted: Tue Apr 20, 2004 4:51 pm     Reply with quote

This question has been asked dozens of times here and the answer is YES it will work. Search the board for I2C and you will find a lot of info...and code!
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 6:57 am     Reply with quote

Well... technically we're talking about PIC to PIC SPI communication, not I2C, and I have personally done a lot of searching and code posting myself for PIC to PIC SPI communication. (Check Birdasaur)

I was merely asking if Ttelmah's code had been used specifically for PIC to PIC SPI communication. (As opposed to non PIC devices)
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Wed Apr 21, 2004 7:18 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=2676&highlight=spiwrite

I have had very good results using SPI. I also use a CRC on packets.
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