你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
STM32L476
举报
生成的代码没有初始化 State,导致HAL_SPI_MspInit函数没有被调用啊。。。。。
BUG这么多么
具体问题就是使用NUCLEO-L476RG 板子 SPI有问题。
SPI1 回环测试,把MOSI---MISO 短接 然后发数据,每次都报超时错误。
仿真去看是 SPI_FLAG_TXE 这个没有set.
void spi_send(const uint8_t pData, uint16_t Size) { //HAL_StatusTypeDef ret = HAL_SPI_Transmit_DMA(&hspi1,pData,Size); uint16_t a = (uint16_t*)pData; LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6); //HAL_StatusTypeDef ret = HAL_SPI_TransmitReceive(&hspi1,pData,rx,Size,1000); HAL_StatusTypeDef ret = HAL_SPI_Transmit(&hspi1,pData,Size,1000); LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); printf("HAL_SPI_Transmit [%d] err=%d\n",a,ret); }
STM32L4x6 - 意法半导体STMicroelectronics
STM32L476RG - 带FPU的超低功耗Arm Cortex-M4 MCU(工作频率80 MHz),配有1 MB Flash存储器、LCD、USB OTG、DFSDM - 意法半导体STMicroelectronics
点击文件那里,可以看到用户手册,参考手册
七颗咖啡豆${PWD} 发表于 2024-12-25 15:28 ![image.png](data/attachment/forum/202412/25/152713z5cl9jl5t95c5zzc.png?imageMogr2/auto-orient/s ...
[md]STM32CubeMX是有一些BUG的,之前用STM32L151 生成定时器ETR的功能,结果复用功能没有开启起来
分享一下最终版本 三种方式都可成功发送
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file spi.c * @brief This file provides code for the configuration * of the SPI instances. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "spi.h" /* USER CODE BEGIN 0 */ #include "string.h" /* USER CODE END 0 */ SPI_HandleTypeDef hspi1; DMA_HandleTypeDef hdma_spi1_rx; DMA_HandleTypeDef hdma_spi1_tx; /* SPI1 init function */ void MX_SPI1_Init(void) { /* USER CODE BEGIN SPI1_Init 0 */ /* USER CODE END SPI1_Init 0 */ /* USER CODE BEGIN SPI1_Init 1 */ memset(&hspi1,0,sizeof(hspi1)); /* USER CODE END SPI1_Init 1 */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_8BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi1.Init.TIMode = SPI_TIMODE_DISABLE; hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi1.Init.CRCPolynomial = 7; hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; if (HAL_SPI_Init(&hspi1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SPI1_Init 2 */ /* USER CODE END SPI1_Init 2 */ } void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 */ /* USER CODE END SPI1_MspInit 0 */ /* SPI1 clock enable */ __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* SPI1 DMA Init */ /* SPI1_RX Init */ hdma_spi1_rx.Instance = DMA1_Channel2; hdma_spi1_rx.Init.Request = DMA_REQUEST_1; hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_spi1_rx.Init.Mode = DMA_NORMAL; hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmarx,hdma_spi1_rx); /* SPI1_TX Init */ hdma_spi1_tx.Instance = DMA1_Channel3; hdma_spi1_tx.Init.Request = DMA_REQUEST_1; hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_spi1_tx.Init.Mode = DMA_NORMAL; hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmatx,hdma_spi1_tx); /* SPI1 interrupt Init */ HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspInit 1 */ /* USER CODE END SPI1_MspInit 1 */ } } void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) { if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspDeInit 0 */ /* USER CODE END SPI1_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI1_CLK_DISABLE(); /**SPI1 GPIO Configuration PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); /* SPI1 DMA DeInit */ HAL_DMA_DeInit(spiHandle->hdmarx); HAL_DMA_DeInit(spiHandle->hdmatx); /* SPI1 interrupt Deinit */ HAL_NVIC_DisableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspDeInit 1 */ /* USER CODE END SPI1_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ //发送完毕拉高CS void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) { /* Prevent unused argument(s) compilation warning */ UNUSED(hspi); LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); /* NOTE : This function should not be modified, when the callback is needed, the HAL_SPI_TxCpltCallback should be implemented in the user file */ } uint8_t rx[4096]; /* 中断或者DMA方式发送 */ void spi_send(const uint8_t *pData, uint16_t Size) { //uint16_t a = *(uint16_t*)pData; LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6); HAL_StatusTypeDef ret = HAL_SPI_Transmit_DMA(&hspi1,pData,Size); //HAL_StatusTypeDef ret = HAL_SPI_Transmit_IT(&hspi1,pData,Size); //LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); //printf("HAL_SPI_Transmit [%d] err=%d\n",a,ret); } /* 阻塞式发送 */ void spi_send2(const uint8_t *pData, uint16_t Size) { //uint16_t a = *(uint16_t*)pData; LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6); //HAL_StatusTypeDef ret = HAL_SPI_Transmit_DMA(&hspi1,pData,Size); HAL_StatusTypeDef ret = HAL_SPI_Transmit(&hspi1,pData,Size,1000); //HAL_StatusTypeDef ret = HAL_SPI_Transmit_IT(&hspi1,pData,Size); LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); //printf("HAL_SPI_Transmit [%d] err=%d\n",a,ret); } /* USER CODE END 1 */
怎么将HAL库转为LL库。
为什么STM32L496RG第一次烧写程序后需要重新上下电才能正常执行程序?
ble hid
RTC小时时间大于24小时
STM32L476VGT6是否可以驱动340X240彩屏
求教,STM32 LCD驱动段码屏,SEG1-SEG8,可以不连续配置吗?
DMA发送函数只能被调用一次
STM32L431进入STOP1模式后ADC产生多余功耗
STM32L431在去掉注释memcpy后会不断重启
生成的代码没有初始化 State,导致HAL_SPI_MspInit函数没有被调用啊。。。。。
BUG这么多么
具体问题就是使用NUCLEO-L476RG 板子 SPI有问题。
SPI1 回环测试,把MOSI---MISO 短接 然后发数据,每次都报超时错误。
仿真去看是 SPI_FLAG_TXE 这个没有set.
void spi_send(const uint8_t pData, uint16_t Size) { //HAL_StatusTypeDef ret = HAL_SPI_Transmit_DMA(&hspi1,pData,Size); uint16_t a = (uint16_t*)pData; LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_6); //HAL_StatusTypeDef ret = HAL_SPI_TransmitReceive(&hspi1,pData,rx,Size,1000); HAL_StatusTypeDef ret = HAL_SPI_Transmit(&hspi1,pData,Size,1000); LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_6); printf("HAL_SPI_Transmit [%d] err=%d\n",a,ret); }
STM32L4x6 - 意法半导体STMicroelectronics
STM32L476RG - 带FPU的超低功耗Arm Cortex-M4 MCU(工作频率80 MHz),配有1 MB Flash存储器、LCD、USB OTG、DFSDM - 意法半导体STMicroelectronics
点击文件那里,可以看到用户手册,参考手册
[md]STM32CubeMX是有一些BUG的,之前用STM32L151 生成定时器ETR的功能,结果复用功能没有开启起来
分享一下最终版本 三种方式都可成功发送