View previous topic :: View next topic |
Author |
Message |
bhaskarreddy
Joined: 15 Apr 2004 Posts: 1
|
spi_read() |
Posted: Thu Apr 15, 2004 11:18 pm |
|
|
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() |
Posted: Fri Apr 16, 2004 5:05 am |
|
|
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? |
Posted: Tue Apr 20, 2004 3:56 pm |
|
|
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: 1935 Location: Norman, OK
|
PIC to PIC I2C |
Posted: Tue Apr 20, 2004 4:51 pm |
|
|
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
|
|
Posted: Wed Apr 21, 2004 6:57 am |
|
|
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
|
|
|
|