I understand that if you want to use spi in ccs, you have to first setup the spi by this line of code : setup_spi( SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16), now I understand the SPI_MASTER parameter, what I do not understand is the SPI_H_TO_L parameter, oh and also for the third parameter if you want to use the full oscillator frequency what should you write?
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Sun Apr 24, 2011 11:48 am
It's much easier if you use SPI modes instead of CCS's constants.
The following define statements allow you to select any SPI mode.
You need to look at the timing diagram for your SPI slave device and
decide what mode it uses. The two things to look for are:
1. The idle state of SCLK (high or low). Look at the sides of the timing
diagram to see the idle state, before and after the SPI transaction.
2. The clock edge of SCLK (rising or falling) that is used to sample the
SPI data. Look at the edge of SCLK that occurs in the middle of a data
bit. Notice if it's rising or falling. Here is another quick reference to
help you decide what mode the slave is using:
http://www.totalphase.com/support/kb/10045/#modes
You also need to select an i/o pin on your SPI Master PIC for the
Chip Select signal. Example:
Code:
#define SPI_CS PIN_C2
There is no option to use the direct PIC oscillator frequency for SCLK.
The smallest divisor is 4. So if you have a 40 MHz oscillator, you can
get a 10 MHz SCLK.
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