View previous topic :: View next topic |
Author |
Message |
waqas_shafique
Joined: 06 Feb 2011 Posts: 8 Location: Pakistan
|
setup_spi() help |
Posted: Wed Feb 09, 2011 4:32 am |
|
|
In SPI two parameters are needed to be specified i.e. clock phase and polarity. IN CCS C's function setup_spi() only one parameter is there to set i.e. SPI_L_TO_H or SPI_H_TO_L . I want to know is this setting for polarity or phase and how to set the second parameter. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Feb 09, 2011 6:22 am |
|
|
First, read the chip's data sheet.
Note that the four options are controlled by the four possibilities from two bits CKE, and CKP.
Then read the manual.
Then look at the the actual constants available in the processor's include file. Note that there are more than in the manual.
SPI_XMIT_L_TO_H => Sets the CKE bit - Data is transmitted on the low to high, when the clock idles high. On high to low, when the clock idles low.
SPI_X_TO_X, sets the CKP bit. L_TO_H - clock idles low. H_TO_L clock idles high.
So all four options are here.
Then save yourself a lot of grief, (much better.....). Use the standard defines published here, that give the pairs of these 'Mode' numbers corresponding to the pretty standard SPI modes.
Best Wishes |
|
|
waqas_shafique
Joined: 06 Feb 2011 Posts: 8 Location: Pakistan
|
|
Posted: Wed Feb 09, 2011 7:02 am |
|
|
good explanation thanks....
one more question,what if i want clock idle low and data transmit on low to high??? as there is no SPI_XMIT_H_TO_L |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Feb 09, 2011 9:46 am |
|
|
H_TO_L, is the opposite of L_TO_H. It is what you get, if you _don't_ select the L_TO_H option.
As I said though pull the SPI mode defines off here. Much safer and easier than using the defines on their own.
Best Wishes |
|
|
|