Problem with tm1637_delay_us()
Hi,
Thanks for the library, it works great ! However, I had a little problem with the function "tm1637_delay_us()". Firstly, the instructions "__nop();" were not recognized by the compiler. I've tried with asm("nop"); instead. I could flash the program but unfortunately it didn't worked. I've tried to use a hardware timer to create the delay and it worked !
If someone, is facing the same issue, here is the way to achieve it :
- Configure the hardware timer in CubeMX. You must change the prescaler in order to create a 1 MHz timer (to achieve a us clock period). In my case, I've used a F401RE Nucleo Board with a 84 MHz clock so I set the prescaler value to 84-1.
- In the CubeMX project manager , tick "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" so that you can use timer stuff in "tm1637.c" file.
- In "tm1637.c", add :
#include "tim.h"
and change :
void tm1637_delay_us(uint8_t delay)
{
while (delay > 0)
{
delay--;
__nop();__nop();__nop();__nop();
}
}
by
void tm1637_delay_us(uint8_t delay)
{
HAL_TIM_Base_Start(&htim4);
__HAL_TIM_SET_COUNTER(&htim4,0); // set the counter value a 0
while (__HAL_TIM_GET_COUNTER(&htim4) < delay); // wait for the counter to reach the us input in the parameter
HAL_TIM_Base_Stop(&htim4);
}
Adapt the previous code with the timer you are using (in my case, I was using TIMER 4)
Hello. I have tried with keil and it works "__nop()". and yes, hardware timer is better.
how to get nop recognized by stm32cube ide ? without any modification ?
@asking23 i think in upper case __NOP()
I Had the same issue. __nop() couldn't get recognized by stm32cube ide. So I changed to capital Letters __NOP().It compiled successfully But the Segments didn't light up. The reason was I had configured my clock to 72 Mhz and __NOP() is working based on clock frequency. I changed it to 8 Mhz .... Worked Perfectly. Thank you for such a clean and beautiful Library.
@Mrezapbs thanks for your response