SPI operation of the am335x application layer

Source: Internet
Author: User

The SPI interface has four different data transmission timings, depending on the combination of the two bits of Cpol and CPHL. The four timings are shown in Figure 1,
The relationship between time series and Cpol and CPHL can also be seen.


Figure 1

The Cpol is used to determine the level at which the SCK clock signal is idle, cpol=0, the idle level is low, cpol=1,

The idle level is high. Cpha is used to determine the sampling time, cpha=0, the first clock in each cycle along the sample,

Cpha=1, the second clock in each cycle is sampled along.

By the above we can configure the SPI mode more than the timing of the actual device.

Find the definition of SPI mode in the header file as follows:

    1. #define SPI_CPHA 0x01 /* Clock phase */
    2. #define SPI_CPOL 0x02 /* Clock polarity */
    3.      #define Spi_mode_0 |0* */
    4. #define Spi_mode_1 (0| Spi_cpha)
    5. #define Spi_mode_2 (Spi_cpol|)
    6. #define Spi_mode_3 (Spi_cpol| Spi_cpha)
    7. It is easy to analyze the configuration of the SPI four mode, the subsequent rate, the number of bytes is well configured.
    8. int spi0mode = spi_mode_2; Configuration mode
    9. IOCTL (Spi0handle, Spi_ioc_wr_mode, &spi0mode);
    10. IOCTL (Spi0handle, Spi_ioc_rd_mode, &spi0mode);

    11. struct Spi_ioc_transfer sspi0tr;
    12. Sspi0tr.speed_hz = 6000000; Configuration Rate 6M
      1. IOCTL (Spi0handle, Spi_ioc_wr_max_speed_hz, &sspi0tr.speed_hz);
      2. IOCTL (Spi0handle, Spi_ioc_rd_max_speed_hz, &sspi0tr.speed_hz);
    13. Sspi0tr.bits_per_word = 16; Number of configuration bytes
    14. Sspi0tr.len = 2;
      1.    ioctl (Spi0handle, Spi_ioc_wr_bits_per_word, &sspi0tr.bits _per_word);
      2.    ioctl (Spi0handle, Spi_ioc_rd_bits_per_word, &sspi0tr.bits_per_word);
      3. After the

      is configured, it is read-write, and read and write, there are two parameters to note: 1,tx_buf,rx_buf These two parameters determine the SPI read-write, if read-only or write-only case, =null the other unused parameter. 2,spi_ioc_message (n) where n determines the number of SPI operations, if you want to read and write several times the SPI changes N is the

Am335x The application layer's SPI operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.