Stm32 SPI bus

Source: Internet
Author: User

About SPI in Data Manual

2.3.18 serial peripheral interface (SPI)
Up to two spis are able to communicate up to 18 Mbits/s in slave and master modes in fullduplexand simplex communication modes. the 3-bit prescaler gives 8 master modefrequencies and the frame is retriable to 8 bits or 16 bits. the hardware crcgeneration/Verification
Supports basic SD card/MMC modes.
Both spis can be served by the DMA Controller

========================================================== ====================

A simple example of SPI Configuration

/* Spi1 configuration ------------------------------------------------------*/
Spi_initstructure.spi_direction = spi_direction_2lines_fullduplex;
Spi_initstructure.spi_mode = spi_mode_master;
Spi_initstructure.spi_datasize = spi_datasize_16b;
Spi_initstructure.spi_cpol = spi_cpol_low;
Spi_initstructure.spi_cpha = spi_cpha_2edge;
Spi_initstructure.spi_nss = spi_nss_soft;
Spi_initstructure.spi_baudrateprescaler = spi_baudrateprescaler_8;
Spi_initstructure.spi_firstbit = spi_firstbit_msb;
Spi_initstructure.spi_crcpolynomial = 7;
Spi_init (spi1, & spi_initstructure );

/* Enable spi1 CRC calculation */
Spi_calculatecrc (spi1, enable );

/* Enable spi1 */
Spi_cmd (spi1, enable );

Sending Function

/* Wait For spi1 TX buffer empty */
While (spi_i2s_getflagstatus (spi1, spi_i2s_flag_txe) = reset );
/* Send spi1 data */
Spi_i2s_senddata (spi1, spigot buffer_tx [txidx ++]);

Receiving Function

/* Wait For spi1 Data Partition tion */
While (spi_i2s_getflagstatus (spi1, spi_i2s_flag_rxne) = reset );
/* Read spi1 received data */
Spi1_buffer_rx [rxidx ++] = spi_i2s_receivedata (spi1 );

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.