你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【请教】对数组赋值导致代码运行异常

[复制链接]
Leeru 提问时间:2017-12-20 09:19 /
本帖最后由 Inc_brza 于 2017-12-20 09:30 编辑

請教一下!
我使用STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\SysTick範例程式
並在主程式MAIN下宣告了
  1. uint32_t Input_f32[2048];
  2. uint32_t Output_f32 [1024];
  3. for (i =0 ; i<2048 ; i++)
  4. {
  5.     Input_f32=0;
  6. }
复制代码

原本
   
  1. /* Toggle LED3 and LED6 */
  2.     STM_EVAL_LEDToggle(LED3);
  3.     STM_EVAL_LEDToggle(LED6);

  4.     /* Insert 50 ms delay */
  5.     Delay(50);

  6.     /* Toggle LED4 and LED5 */
  7.     STM_EVAL_LEDToggle(LED4);
  8.     STM_EVAL_LEDToggle(LED5);

  9.     /* Insert 100 ms delay */
  10.     Delay(100);
复制代码


會閃爍的LED3,4,5,6變得完全不閃爍了呢?
這是什麼原因造成的呢?

收藏 评论12 发布时间:2017-12-20 09:19

举报

12个回答
Inc_brza 回答时间:2017-12-20 09:27:27
本帖最后由 Inc_brza 于 2017-12-20 09:32 编辑

发帖子前请先想清楚自己的问题他是啥,想好标题再发帖
代码最好以截图提供,说明你操作了啥导致啥问题!编码格式注意一下,
别给大家造成眼球污染!帮楼主编辑了一下帖子,楼主请把数组操作屏蔽掉看看是否问题解决!
如果真是数组操作导致的问题,请看一下数组的大小以及数组在哪里定义的。
注意一下栈大小(startup文件可以设置)是否过小!
最好已截图的方式贴出你的操作代码。
Leeru 回答时间:2017-12-20 09:55:06
版主謝謝您了~
不好意思!我來自台灣~
我看不懂您寫的意思
因為說法不同
不過如果我把
宣告變數拿掉後
執行就是正常的了
請問我要注意startup_stm32f4xx.s的哪個部份呢
謝謝版主這麼熱心的回答
Inc_brza 回答时间:2017-12-20 09:58:50
本帖最后由 Inc_brza 于 2017-12-20 10:00 编辑
Leeru 发表于 2017-12-20 09:55
版主謝謝您了~
不好意思!我來自台灣~
我看不懂您寫的意思

额,我也不知道你们对名词的说法,不过大概就是这么个意思,
建议你先把main函数截图放上来另外,我先猜测你的数组是在main函数里声明定义的,你把他拿出来
作为全局变量看看是否还有异常,如果异常解决,那问题点就知道是什么了
Leeru 回答时间:2017-12-20 10:10:43
本帖最后由 Leeru 于 2017-12-20 10:32 编辑

版主謝謝您了~
底下是程式碼!
  1. int main(void)
  2. {
  3.   /*!< At this stage the microcontroller clock setting is already configured,
  4.        this is done through SystemInit() function which is called from startup
  5.        file (startup_stm32f4xx.s) before to branch to application main.
  6.        To reconfigure the default setting of SystemInit() function, refer to
  7.         system_stm32f4xx.c file
  8.      */   
  9.              uint16_t i;
  10.         //uint32_t Input_f32[2048];
  11.         //uint32_t Output_f32 [1024];      

  12.         for (i =0 ; i<2048 ; i++)
  13.         {
  14.                     Input_f32[i]=0;
  15.         }
  16. /*
  17.         for (i =0 ; i<1024 ; i++)
  18.         {
  19.                     Output_f32[i]=0;
  20.         }
  21. */
  22.   /* Initialize Leds mounted on STM32F4-Discovery board */
  23.   STM_EVAL_LEDInit(LED4);
  24.   STM_EVAL_LEDInit(LED3);
  25.   STM_EVAL_LEDInit(LED5);
  26.   STM_EVAL_LEDInit(LED6);

  27.   /* Turn on LED4 and LED5 */
  28.   STM_EVAL_LEDOn(LED4);
  29.   STM_EVAL_LEDOn(LED5);
  30.   
  31.   /* Setup SysTick Timer for 1 msec interrupts.
  32.      ------------------------------------------
  33.     1. The SysTick_Config() function is a CMSIS function which configure:
  34.        - The SysTick Reload register with value passed as function parameter.
  35.        - Configure the SysTick IRQ priority to the lowest value (0x0F).
  36.        - Reset the SysTick Counter register.
  37.        - Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
  38.        - Enable the SysTick Interrupt.
  39.        - Start the SysTick Counter.
  40.    
  41.     2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
  42.        SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
  43.        SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
  44.        inside the misc.c file.

  45.     3. You can change the SysTick IRQ priority by calling the
  46.        NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
  47.        call. The NVIC_SetPriority() is defined inside the core_cm4.h file.

  48.     4. To adjust the SysTick time base, use the following formula:
  49.                            
  50.          Reload Value = SysTick Counter Clock (Hz) x  Desired Time base (s)
  51.    
  52.        - Reload Value is the parameter to be passed for SysTick_Config() function
  53.        - Reload Value should not exceed 0xFFFFFF
  54.    */
  55.   if (SysTick_Config(SystemCoreClock / 1000))
  56.   {
  57.     /* Capture error */
  58.     while (1);
  59.   }

  60.   while (1)
  61.   {
  62.     /* Toggle LED3 and LED6 */
  63.     STM_EVAL_LEDToggle(LED3);
  64.     STM_EVAL_LEDToggle(LED6);

  65.     /* Insert 50 ms delay */
  66.     Delay(50);

  67.     /* Toggle LED4 and LED5 */
  68.     STM_EVAL_LEDToggle(LED4);
  69.     STM_EVAL_LEDToggle(LED5);

  70.     /* Insert 100 ms delay */
  71.     Delay(100);
  72.   }
  73. }
复制代码

主要只添加了

             uint16_t i;
        uint32_t Input_f32[2048];
        uint32_t Output_f32 [1024];      

        for (i =0 ; i<2048 ; i++)
        {
                    Input_f32=0;
        }

就會導致while迴圈下LED3,4,5,6都沒動作

謝謝您了版主~

Inc_brza 回答时间:2017-12-20 10:15:43
Leeru 发表于 2017-12-20 10:10
版主謝謝您了~
底下是程式碼!
int main(void)

都说了,程序应该截图,或者使用编辑框上方的代码:<>这个属性输入你的代码,能让
看帖者舒服,你这样乱七八糟的贴代码,谁愿意看?就更别说帮你解决问题了!请自行修改
一下你的帖子内容。
你的变量定义在函数内,属于栈溢出,把你的数组定义放在函数外部即可解决,例如:
  1. uint32_t Input_f32[2048];
  2. uint32_t Output_f32 [1024];   

  3. void main(void)
  4. {
  5.     int i = 0;
  6.     for (i = 0; i < 2048; i ++) {
  7.         Input_f32[i] = 0;
  8.     }
  9.     ...
  10. }
复制代码
Leeru 回答时间:2017-12-20 10:21:52
版主您好~
我這邊有試著把變數當作全域變數並且執行後是正常的
可是當我嘗試把變數宣告成float全域變數後
LED又變成沒動作了
因為這兩個變數我要用做FFT運算使用
所以會宣告這兩個變數為float
請問有什麼方法
可解決的嗎?
Leeru 回答时间:2017-12-20 10:24:01
版主不好意思~
我還不會編輯您提到的代碼編輯
抱歉了~
謝謝您耐心的看完
Inc_brza 回答时间:2017-12-20 10:32:51
请注意:
TIM截图20171220103134.jpg
箭头处鼠标左键,会弹出一个对话框,在对话框里输入你的代码!
如果你连这个都不懂什么意思,只能说你连发帖的能力都没有!
Leeru 回答时间:2017-12-20 10:35:19
Inc_brza 发表于 2017-12-20 10:32
请注意:

箭头处鼠标左键,会弹出一个对话框,在对话框里输入你的代码!

謝謝您版主~我會使用了
下次不會再犯錯了
12下一页

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版