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

CCS SPI Instructions

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







CCS SPI Instructions
PostPosted: Sat Dec 28, 2002 7:52 pm     Reply with quote

Hi everyone,

I am wondering what kind of assumptions CCS made when they wrote the SPI functions.

I want to use the SPI_READ() function to read the SPI data for the PIC16F877 (as a slave). I am wondering if this function requires RA5 (Chip Select) pin or not. What are the clock and data line idle state? Data timing? I looked at the manual but I couldn't find this information. Where can I find this kind of information?

Regards,
Thomas
___________________________
This message was ported from CCS's old forum
Original Post ID: 10299
R.J.Hamlett
Guest







Re: CCS SPI Instructions
PostPosted: Sun Dec 29, 2002 3:33 am     Reply with quote

:=Hi everyone,
:=
:=I am wondering what kind of assumptions CCS made when they wrote the SPI functions.
:=
:=I want to use the SPI_READ() function to read the SPI data for the PIC16F877 (as a slave). I am wondering if this function requires RA5 (Chip Select) pin or not. What are the clock and data line idle state? Data timing? I looked at the manual but I couldn't find this information. Where can I find this kind of information?
:=
:=Regards,
:=Thomas
Primarily in the MicroChip data sheet, and in the include file for the chip (this latter source is vital...).
If you look at the first source, you will find details of the timing, and that the signal polarities are programmable (both the levels used, and the edges used). Also the ability to use the SS line is similarly configurable. With this knowledge, if you then look at the include file, you will see:

////////////////////////////////////////////////////////////////// SPI
// SPI Functions: SETUP_SPI, SPI_WRITE, SPI_READ, SPI_DATA_IN
// Constants used in SETUP_SSP() are:
#define SPI_MASTER 0x20
#define SPI_SLAVE 0x24
#define SPI_L_TO_H 0
#define SPI_H_TO_L 0x10
#define SPI_CLK_DIV_4 0
#define SPI_CLK_DIV_16 1
#define SPI_CLK_DIV_64 2
#define SPI_CLK_T2 3
#define SPI_SS_DISABLED 1

#define SPI_SAMPLE_AT_END 0x8000
#define SPI_XMIT_L_TO_H 0x4000

With the seventh and eighth lines setting CKE, the thirteenth line, disabling slave select, and the sixteenth line controlling CKP. The data sheet then shows how these affect the signals used (page 70).

Generally throughout the use of the CCS compiler, the primary source of data about the chip peripherals is allways the MicroChip data sheet, and it then becomes a matter of identifying which functions and settings, access these features.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10305
Charlie U
Guest







Re: CCS SPI Instructions
PostPosted: Sun Dec 29, 2002 7:41 am     Reply with quote

:=Hi everyone,
:=
:=I am wondering what kind of assumptions CCS made when they wrote the SPI functions.
:=
:=I want to use the SPI_READ() function to read the SPI data for the PIC16F877 (as a slave). I am wondering if this function requires RA5 (Chip Select) pin or not. What are the clock and data line idle state? Data timing? I looked at the manual but I couldn't find this information. Where can I find this kind of information?
:=
:=Regards,
:=Thomas

Check the link below for info on setting up the SPI.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10311
Thomas
Guest







Re: CCS SPI Instructions
PostPosted: Sun Dec 29, 2002 1:04 pm     Reply with quote

Thank you everyone for your help! I still have a small problem. I wrote a simple SPI slave code as below. Somehow, the interrupt happens every two transmitions from the master. Did I do something wrong?

void InitSPI()
{
setup_spi(SPI_SLAVE | SPI_L_TO_H);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
}

#INT_SSP
SPI_ISR()
{
spiBuf3 = spiBuf2;
spiBuf2 = spiBuf1;
spiBuf1 = spi_read(0x55);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10314
R.J.Hamlett
Guest







Re: CCS SPI Instructions
PostPosted: Sun Dec 29, 2002 3:28 pm     Reply with quote

:=Thank you everyone for your help! I still have a small problem. I wrote a simple SPI slave code as below. Somehow, the interrupt happens every two transmitions from the master. Did I do something wrong?
:=
:=void InitSPI()
:={
:= setup_spi(SPI_SLAVE | SPI_L_TO_H);
:= enable_interrupts(INT_SSP);
:= enable_interrupts(GLOBAL);
:=}
:=
:=#INT_SSP
:=SPI_ISR()
:={
:= spiBuf3 = spiBuf2;
:= spiBuf2 = spiBuf1;
:= spiBuf1 = spi_read(0x55);
:=}
I suspect the problem is in the use of the SPI_READ function. This waits till the byte is clocked out (if called with a value), so could lead to odd behaviour, if used inside an interrupt (this is a common problem with all the CCS I/O functions).
Try coding as:

#byte SPIBUF=0x13

SPI_ISR()
{
spiBuf3 = spiBuf2;
spiBuf2 = spiBuf1;
spiBuf1 = SPIBUF;
SPIBUF=0x55;
}

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10317
Thomas
Guest







Re: CCS SPI Instructions
PostPosted: Mon Dec 30, 2002 3:06 am     Reply with quote

Thank you R.J.! You just solved my problem!

Best regards,
thomas
___________________________
This message was ported from CCS's old forum
Original Post ID: 10320
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