娇小w搡bbbb搡bbb,《第一次の人妻》,中国成熟妇女毛茸茸,边啃奶头边躁狠狠躁视频免费观看

如何采用STM32配置SPI實(shí)現(xiàn)同步通信

發(fā)布者:Enchanted2021最新更新時間:2024-04-11 來源: elecfans關(guān)鍵字:STM32  同步通信 手機(jī)看文章 掃描二維碼
隨時隨地手機(jī)看文章

SPI是一種高速的,全雙工,同步的通信總線,原理和使用簡單,占用引腳資源少,是一種常用的通信方式。


STM32通常有2~3個SPI接口

如何采用STM32配置SPI實(shí)現(xiàn)同步通信

根據(jù)STM32手冊的使用方法:

1. Enable peripheral clock

2. Enable SCK, MOSI, MISO and NSS GPIO clocks

3. Peripherals alternate function:

? Connect the pin to the desired peripherals‘ Alternate Function (AF)

? Call GPIO_Init() function.

4. Program the Polarity, Phase, First Data, Baud Rate Prescaler, Slave Management,Peripheral Mode and CRC Polynomial values using the SPI_Init() function in SPI mode.

5. Configure the FIFO threshold using SPI_RxFIFOThresholdConfig() to select at which hreshold the RXNE event is generated.

6. Enable the NVIC and the corresponding interrupt using the function SPI_I2S_ITConfig() if you need to use interrupt mode.

7. When using the DMA mode

? Configure the DMA using DMA_Init() function.

? Active the needed channel Request using SPI_I2S_DMACmd() function.

8. Enable the SPI using the SPI_Cmd() function 。

9. Enable the DMA using the DMA_Cmd() function when using DMA mode.

10. To use the CRC Hardware calculation feature refer to the Peripheral CRC hardware Calculation subsection.

基于STM32F3discovery開發(fā)板,STM32F303VC

使用SPI1,從機(jī)連接的是L3GD20陀螺儀,引腳連接:

SPI1_MOSI——PA7

SPI1_SCK——PA5

SPI1_MISO——PA6

NSS——PE3

代碼

void SPI_GPIO_Config(void)

{

//將SPI1_MOSI—PA7,SPI1_SCK—PA5,SPI1_MISO—PA6引腳配置為對應(yīng)復(fù)用功能

//NSS—PE3為從機(jī)片選引腳,配置為推挽輸出

}

void SPI_Config(void)

{

SPI_InitTypeDef SPI_InitStructure;

SPI_InitStructure.SPI_Direction =SPI_Direction_2Lines_FullDuplex;

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //結(jié)合從機(jī)選擇

SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //結(jié)合從機(jī)選擇

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_I2S_DeInit(SPI1);

SPI_Init(SPI1, &SPI_InitStructure);

SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);

SPI_Cmd(SPI1,ENABLE);

}

然后就可以用SPI接口進(jìn)行收發(fā)數(shù)據(jù),具體收發(fā)方式要根據(jù)從機(jī)設(shè)備決定

需要的時候可以配置中斷,DMA等功能

發(fā)送或接收數(shù)據(jù)前,先將相應(yīng)從機(jī)的片選信號置零

SPI是兩個設(shè)備移位寄存器的數(shù)據(jù)交換,接收數(shù)據(jù)前先向從機(jī)發(fā)送虛擬字節(jié),收到的數(shù)據(jù)就是所要讀取的數(shù)據(jù)


關(guān)鍵字:STM32  同步通信 引用地址:如何采用STM32配置SPI實(shí)現(xiàn)同步通信

上一篇:STM32單片機(jī)的EXIT中斷解析
下一篇:如何用STM32配置一個EXTIx中斷線的I/O口

小廣播
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機(jī)文章

 
EEWorld訂閱號

 
EEWorld服務(wù)號

 
汽車開發(fā)圈

 
機(jī)器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號 京ICP備10001474號-1 電信業(yè)務(wù)審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
主站蜘蛛池模板: 同仁县| 治多县| 博野县| 毕节市| 思南县| 襄汾县| 松溪县| 夹江县| 海门市| 胶州市| 铜山县| 平顶山市| 彰化县| 历史| 河津市| 呼伦贝尔市| 卫辉市| 赤壁市| 蓬溪县| 柘城县| 崇仁县| 安达市| 新津县| 罗江县| 通山县| 襄汾县| 砚山县| 桂平市| 开封市| 通河县| 武夷山市| 五大连池市| 临漳县| 潞西市| 夹江县| 双辽市| 互助| 八宿县| 绍兴市| 察雅县| 奉贤区|