日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

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

CMSIS Driver 都有著相似的 API 函數(shù)和相似的調用方法,它是在 ST HAL 庫的基礎上又進一步的封裝,使用和配置起來都要比 ST HAL 庫要方便和簡單許多,并且還是跨平臺的,非常有學習和使用的價值。今天學習 SPI API 的使用,詳細介紹見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

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

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

關鍵字: Linux x86 ARM

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

關鍵字: Linux x86 ARM

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

關鍵字: ARM 神經(jīng)圖形技術 GPU AI ML

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

關鍵字: ARM META

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

關鍵字: AI ARM

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

關鍵字: RISC-V CPU AI CUDA ARM 推理
關閉