www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀] CMSIS Driver 都有著相似的 API 函數(shù)和相似的調(diào)用方法,它是在 ST HAL 庫的基礎(chǔ)上又進(jìn)一步的封裝,使用和配置起來都要比 ST HAL 庫要方便和簡單許多,并且還是跨平臺的,非常有學(xué)習(xí)和使用的價值。今天學(xué)

CMSIS Driver 都有著相似的 API 函數(shù)和相似的調(diào)用方法,它是在 ST HAL 庫的基礎(chǔ)上又進(jìn)一步的封裝,使用和配置起來都要比 ST HAL 庫要方便和簡單許多,并且還是跨平臺的,非常有學(xué)習(xí)和使用的價值。今天學(xué)習(xí) SPI API 的使用,詳細(xì)介紹見CMSIS Driver SPI API

SPI 發(fā)送與接收

/**

******************************************************************************

* @file main.c

* @author XinLi

* @version v1.0

* @date 20-March-2018

* @brief Main program body.

******************************************************************************

* @attention

*

*

Copyright © 2018 XinLi

*

* This program is free software: you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation, either version 3 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program. If not, see .

*

******************************************************************************

*/

/* Header includes -----------------------------------------------------------*/

#include "stm32f4xx.h"

#include "Driver_SPI.h"

#include

/* Macro definitions ---------------------------------------------------------*/

/* Type definitions ----------------------------------------------------------*/

/* Variable declarations -----------------------------------------------------*/

extern ARM_DRIVER_SPI Driver_SPI1;

/* Variable definitions ------------------------------------------------------*/

static uint8_t txBuffer[5] = {0xAB};

static uint8_t rxBuffer[5] = {0};

static uint8_t dataBuffer[5] = {0};

/* Function declarations -----------------------------------------------------*/

static void SPI1_Callback(uint32_t event);

static void SPI1_CS_Init(void);

static void SPI1_CS_Low(void);

static void SPI1_CS_High(void);

static void SystemClock_Config(void);

/* Function definitions ------------------------------------------------------*/

/**

* @brief Main program.

* @param None.

* @return None.

*/

int main(void)

{

/* STM32F4xx HAL library initialization:

- Configure the Flash prefetch, instruction and Data caches

- Configure the Systick to generate an interrupt each 1 msec

- Set NVIC Group Priority to 4

- Global MSP (MCU Support Package) initialization

*/

HAL_Init();

/* Configure the system clock to 168 MHz */

SystemClock_Config();

SPI1_CS_Init();

Driver_SPI1.Initialize(SPI1_Callback);

Driver_SPI1.PowerControl(ARM_POWER_FULL);

Driver_SPI1.Control(ARM_SPI_MODE_MASTER |

ARM_SPI_CPOL0_CPHA0 |

ARM_SPI_MSB_LSB |

ARM_SPI_SS_MASTER_UNUSED |

ARM_SPI_DATA_BITS(8), 10000000);

SPI1_CS_Low();

Driver_SPI1.Transfer(txBuffer, rxBuffer, sizeof(txBuffer));

for(;;)

{

}

}

/**

* @brief SPI1 callback function.

* @param event: SPI events notification mask.

* @return None.

*/

static void SPI1_Callback(uint32_t event)

{

if(event & ARM_SPI_EVENT_TRANSFER_COMPLETE)

{

SPI1_CS_High();

memcpy(dataBuffer, rxBuffer, sizeof(rxBuffer));

}

}

/**

* @brief SPI1 CS pin initialize.

* @param None.

* @return None.

*/

static void SPI1_CS_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct = {0};

/* GPIO Ports Clock Enable */

__HAL_RCC_GPIOB_CLK_ENABLE();

/* Configure GPIO pin : PtPin */

GPIO_InitStruct.Pin = GPIO_PIN_14;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/* Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);

}

/**

* @brief SPI1 CS pin level pull low.

* @param None.

* @return None.

*/

static void SPI1_CS_Low(void)

{

/* Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);

}

/**

* @brief SPI1 CS pin level pull high.

* @param None.

* @return None.

*/

static void SPI1_CS_High(void)

{

/* Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);

}

/**

* @brief System Clock Configuration

* The system Clock is configured as follow :

* System Clock source = PLL (HSE)

* SYSCLK(Hz) = 168000000

* HCLK(Hz) = 168000000

* AHB Prescaler = 1

* APB1 Prescaler = 4

* APB2 Prescaler = 2

* HSE Frequency(Hz) = 8000000

* PLL_M = 8

* PLL_N = 336

* PLL_P = 2

* PLL_Q = 7

* VDD(V) = 3.3

* Main regulator output voltage = Scale1 mode

* Flash Latency(WS) = 5

* @param None

* @retval None

*/

static void SystemClock_Config(void)

{

RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitTypeDef RCC_OscInitStruct;

/* Enable Power Control clock */

__HAL_RCC_PWR_CLK_ENABLE();

/* The voltage scaling allows optimizing the power consumption when the device is

clocked below the maximum system frequency, to update the voltage scaling value

regarding system frequency refer to product datasheet. */

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

/* Enable HSE Oscillator and activate PLL with HSE as source */

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 8;

RCC_OscInitStruct.PLL.PLLN = 336;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 7;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

/* Select PLL as system clock

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

ARM系統(tǒng)幾乎都采用Linux的操作系統(tǒng),而且?guī)缀跛械挠布到y(tǒng)都要單獨構(gòu)建自己的系統(tǒng),與其他系統(tǒng)不能兼容,這也導(dǎo)致其應(yīng)用軟件不能方便移植,這一點一直嚴(yán)重制約了ARM系統(tǒng)的發(fā)展和應(yīng)用。GOOGLE開發(fā)了開放式的Andro...

關(guān)鍵字: Linux x86 ARM

隨著計算需求的多樣化,尤其是隨著移動設(shè)備、嵌入式系統(tǒng)和云計算的興起,ARM 和 x86 架構(gòu)之間的爭論變得更加突出。ARM(高級 RISC 機器)和 x86 代表兩種不同類型的處理器架構(gòu),每種架構(gòu)都針對不同的工作負(fù)載和用...

關(guān)鍵字: Linux x86 ARM

從畫質(zhì)優(yōu)化 (NSS) 到幀率提升 (NFRU) 和光線追蹤(NSSD),Arm 計劃覆蓋移動端圖形處理的多個維度,推動邊緣 AI 圖形革命。而未來通過持續(xù)的技術(shù)迭代,Arm也將保持在移動計算領(lǐng)域的技術(shù)領(lǐng)先,滿足手游、A...

關(guān)鍵字: ARM 神經(jīng)圖形技術(shù) GPU AI ML

7月31日消息,據(jù)媒體報道,芯片架構(gòu)提供商Arm Holdings首席執(zhí)行官Rene Haas宣布,公司正加大投入開發(fā)自有芯片產(chǎn)品,此舉標(biāo)志著其從傳統(tǒng)IP授權(quán)模式向提供實體芯片的戰(zhàn)略重大轉(zhuǎn)變。

關(guān)鍵字: ARM META

7月28日消息,2025年,中國AI硬件市場規(guī)模將首次突破萬億元大關(guān)。

關(guān)鍵字: AI ARM

受生成式 AI 驅(qū)動, RISC-V 芯片市場快速發(fā)展。預(yù)計到2030年,RISC-V SoC出貨量將達(dá)到1618.1億顆,營收將達(dá)到927億美元。其中,用于AI加速器的RISC-V SoC出貨量將達(dá)到41億顆,營收將達(dá)...

關(guān)鍵字: RISC-V CPU AI CUDA ARM 推理
關(guān)閉