|
|
View previous topic :: View next topic |
Author |
Message |
Thomas Guest
|
CCS SPI Instructions |
Posted: Sat Dec 28, 2002 7:52 pm |
|
|
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 |
Posted: Sun Dec 29, 2002 3:33 am |
|
|
:=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 |
Posted: Sun Dec 29, 2002 7:41 am |
|
|
:=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 |
Posted: Sun Dec 29, 2002 1:04 pm |
|
|
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 |
Posted: Sun Dec 29, 2002 3:28 pm |
|
|
:=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 |
Posted: Mon Dec 30, 2002 3:06 am |
|
|
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 |
|
|
|
|
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
|