2019-05-07 07:21 AM
/*
SPC5 RLA - Copyright (C) 2015 STMicroelectronics
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* Inclusion of the main header files of all the imported components in the
order specified in the application wizard. The file is generated
automatically.*/
#include "components.h"
#include "pit_lld_cfg.h"
uint8_t timer_flag = 0;
/* Callback function for PIT Channel 1 */
void cb_pit_ch1(void){
timer_flag = 1;
}
/*
* Application entry point.
*/
int main(void) {
/* Initialization of all the imported components in the order specified in
the application wizard. The function is generated automatically.*/
componentsInit();
/* Enable Interrupts */
irqIsrEnable();
/* Start PIT driver */
pit_lld_start(&PITD, pit_config);
/* Enable PIT Channels */
/* Channel 0 already enabled and used by system */
pit_lld_channel_start(&PITD, 1U);
/* Application main loop.*/
for ( ; ; ) {
if(timer_flag == 1)
{
pal_lld_togglepad(PORT_C, PC_LED7);
timer_flag = 0;
}
}
}
In the above autogenerated code, I'm setting timer_flag in timer callback and checking against to toggle an LED (line 52). But the code fails to pass the if condition i.e ( 1 == 1). I couldn't even debug why it's happening that way.
Kindly help me if there is any mistake in the code
Solved! Go to Solution.
2019-05-07 08:59 AM
2019-05-07 08:59 AM
Make timer_flag volatile:
volatile uint8_t timer_flag = 0;
2019-05-08 12:15 AM
Thank you so much, it works now.. Could you please explain what's happening while not declaring it as volatile?
2019-05-08 12:21 AM
There are plenty of good C language tutorials around.
2019-05-08 01:06 AM