ST意法半导体
直播中

风来吴山

8年用户 1432经验值
擅长:电源/新能源
私信 关注
[问答]

temp=10行被取消注释面包板LED不亮可能是什么问题?

我正在使用 NUCLEO-L476RG 开发板,我正在学习为 STM32 系列编写 GPIO 驱动程序我正在实现一个简单的逻辑,我需要在按下按钮时打开 LED。
我有一个奇怪的问题: 当 temp=10 行被注释时,面包板 LED 亮起,当 temp=10 行被取消注释时它不会亮起。
可能是什么问题?
更改线路位置后问题没有解决
与面包板的连接如下图所示,我没有在我的代码中配置任何时钟源,这意味着它将采用默认时钟(4MHz 的 MSI)进行操作。我使用 Mini USB 为它供电
  • #include
  • #include "stm32l476xx.h"
  • #include "stm32l476xx_gpoi_driver.h"
  • #if !defined(__SOFT_FP__) && defined(__ARM_FP)
  •   #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use."
  • #endif
  • #define delay() {;}
  • //#define delay() for(uint32_t i=0; i<=50000; i++);
  • int main(void)
  • {
  •         GPIO_Handle_t NucleoUserLED,NucleoUserPB,BreadBoardLED,BreadBoardPB;
  •         volatile uint8_t inputVal,BBinpVal;
  •         uint32_t temp;
  •         //User green led in the nucleo board connected to PA5
  •         NucleoUserLED.pGPIO                                                         = GPIOA;
  •         NucleoUserLED.GPIO_Pin_Cfg.GPIO_PinNumber                 = GPIO_PIN_5;
  •         NucleoUserLED.GPIO_Pin_Cfg.GPIO_PinMode                   = GPIO_MODE_OP;
  •         NucleoUserLED.GPIO_Pin_Cfg.GPIO_PinPuPdControl  = GPIO_IP_NO_PUPD;
  •         NucleoUserLED.GPIO_Pin_Cfg.GPIO_PinOpType                 = GPIO_OP_TYPE_PP;
  •         //User blue button in the nucleo connected to PC13
  •         NucleoUserPB.pGPIO                                                                 = GPIOC;
  •         NucleoUserPB.GPIO_Pin_Cfg.GPIO_PinNumber                 = GPIO_PIN_13;
  •         NucleoUserPB.GPIO_Pin_Cfg.GPIO_PinMode                   = GPIO_MODE_IP;
  •         NucleoUserPB.GPIO_Pin_Cfg.GPIO_PinPuPdControl         = GPIO_IP_NO_PUPD;
  •         //User led in the bread board connected to PC8
  •         BreadBoardLED.pGPIO                                                         = GPIOC;
  •         BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinNumber                 = GPIO_PIN_8;
  •         BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinMode                   = GPIO_MODE_OP;
  •         BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinPuPdControl  = GPIO_IP_NO_PUPD;
  •         BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinOpType                 = GPIO_OP_TYPE_PP;
  •         //User DPDT connected in the breadboard connected to PC6
  •         BreadBoardPB.pGPIO                                                                 = GPIOC;
  •         BreadBoardPB.GPIO_Pin_Cfg.GPIO_PinNumber                 = GPIO_PIN_6;
  •         BreadBoardPB.GPIO_Pin_Cfg.GPIO_PinMode                   = GPIO_MODE_IP;
  •         BreadBoardPB.GPIO_Pin_Cfg.GPIO_PinPuPdControl         = GPIO_IP_PU;
  •         GPIO_PeriClkCtrl(GPIOA, ENABLE);
  •         GPIO_PeriClkCtrl(GPIOC, ENABLE);
  •         GPIO_Init(&NucleoUserLED);
  •         GPIO_Init(&NucleoUserPB);
  •         GPIO_Init(&BreadBoardLED);
  •         GPIO_Init(&BreadBoardPB);
  •         while(1)
  •         {
  •                 /*****************************************************************
  •                  *           Controlling the IO present in the nucleo board                         *
  •                  *****************************************************************/
  •                 inputVal = GPIO_ReadInputPin(NucleoUserPB.pGPIO, NucleoUserPB.GPIO_Pin_Cfg.GPIO_PinNumber);
  •                 BBinpVal = GPIO_ReadInputPin(BreadBoardPB.pGPIO, BreadBoardPB.GPIO_Pin_Cfg.GPIO_PinNumber);
  •                 if(inputVal == 0)
  •                 {
  •                         GPIO_ToggleOutputPin(NucleoUserLED.pGPIO, NucleoUserLED.GPIO_Pin_Cfg.GPIO_PinNumber);
  •                 }
  •                 /*****************************************************************
  •                  *           Controlling the IO present in the bread board                         *
  •                  *****************************************************************/
  •                 temp = 10;
  •                 if (BBinpVal == 0 )
  •                 {
  •                         GPIO_WriteOutputPin(BreadBoardLED.pGPIO, BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinNumber, 1);
  •                 }
  •                 else
  •                 {
  •                         GPIO_WriteOutputPin(BreadBoardLED.pGPIO, BreadBoardLED.GPIO_Pin_Cfg.GPIO_PinNumber, 0);
  •                 }
  •         }
  •         return 0;
  • }

回帖(1)

凌云志

2022-12-14 13:59:57
你有调试器吗?
Nucleo LED 是否一直闪烁?
如果将 temp 设为全局,即在 main() 之外定义它,会发生什么情况?
举报

更多回帖

发帖
×
20
完善资料,
赚取积分