View previous topic :: View next topic |
Author |
Message |
sreejith.s.s
Joined: 24 Jun 2011 Posts: 23 Location: INDIA
|
problem in spi |
Posted: Fri Jun 24, 2011 11:42 pm |
|
|
hai,
I have a misunderstanding in SPI_L_TO_H & SPI_XMIT_L_TO_H. I don't know what is the difference between these two. That is, what does the spi_ mean and also what does the spi_xmit_ mean.......... pls anyone help me. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sat Jun 25, 2011 2:15 am |
|
|
1) Use the Mode definitions instead:
Code: |
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
|
Then you can just use the standard 'mode' numbers, and are far less likely to have problems.
2) Data sheet is your friend. These two defines control the CKE, and CKP bits. CKE, controls where the data _transmission_ occurs relative to the clock edge. Then CKP, controls whether the clock sits 'high', and the active edge is the falling edge (SPI_H_TO_L), or whether the clock sits 'low', and the active edge is the rising one (SPI_L_TO_H).
Have a look at the WikiPedia article on SPI:
<http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus>
Then 'CPOL', is the CKP bit (clock polarity), and CKE is the CPHA bit.
Best Wishes |
|
|
sreejith.s.s
Joined: 24 Jun 2011 Posts: 23 Location: INDIA
|
Re: problem in spi |
Posted: Mon Jun 27, 2011 4:37 am |
|
|
Hi
Mr. Ttelmah
It was very helpful to me, thank you very much. But I am still not having a good idea about the difference between the normal SPI_L_to_H
AND SPI_XMIT_L_TO_H and why these two are used in a same mode? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 27, 2011 5:39 am |
|
|
To configure SPI you always have to configure two settings:
1) Clock Polarity: The clock level when inactive
2) Clock Phase: At which clock edge the data is to be clocked in.
Freescale (Motorola) uses the names CPOL and CPHA.
For copyright reasons Microchip uses other names: CKP and CKE.
For unknown reasons CCS decided to use none of the above names and invented SPI_L_TO_H, SPI_H_TO_L and SPI_XMIT_L_TO_H.
Two configuration bits give a total of four combinations, for easier speaking often referred to as the four SPI-modes 0 to 3.
SPI parameter number 1 is easy to understand: Look at the clock level in inactive state, high or low, and that is your setting for CPOL/CKP/SPI_L_TO_H.
SPI parameter number 2 generates confusion because it is implemented in different ways:
- Freescale defines it as 'data is clocked in on the first edge (0) or second edge (1).
- Microchip defines it as 'data is clocked in on the first edge (1) or second edge (0).
- CCS defines it as 'data is clocked in on the positive edge (SPI_XMIT_L_TO_H) or negative edge (default)
In the table below you can see how all names relate to each other: Code: | // SPI Mode | MOTOROLA | MICROCHIP | CCS | Data clocked in at
//----------------------------------------------------------------|-------------------
// | CPOL CPHA| CKP CKE | |
// 0 | 0 0 | 0 1 | SPI_L_TO_H | SPI_XMIT_L_TO_H | low to high edge
// 1 | 0 1 | 0 0 | SPI_L_TO_H | high to low edge
// 2 | 1 0 | 1 1 | SPI_H_TO_L | high to low edge
// 3 | 1 1 | 1 0 | SPI_H_TO_L | SPI_XMIT_L_TO_H | low to high edge
|
Quote: | But I am still not having a good idea about the difference between the normal SPI_L_to_H AND SPI_XMIT_L_TO_H and why these two are used in a same mode? | As explained above for SPI you always have to define two parameters. |
|
|
sreejith.s.s
Joined: 24 Jun 2011 Posts: 23 Location: INDIA
|
Thanks a lot ! |
Posted: Mon Jun 27, 2011 10:19 pm |
|
|
Now its seems to be very clear for me thanks partners ! |
|
|
|