Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with tm1637_delay_us() #1

Open
cypamigon opened this issue Aug 4, 2023 · 5 comments
Open

Problem with tm1637_delay_us() #1

cypamigon opened this issue Aug 4, 2023 · 5 comments

Comments

@cypamigon
Copy link

cypamigon commented Aug 4, 2023

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)

@nimaltd
Copy link
Owner

nimaltd commented Aug 6, 2023

Hello. I have tried with keil and it works "__nop()". and yes, hardware timer is better.

@asking23
Copy link

asking23 commented Feb 7, 2024

how to get nop recognized by stm32cube ide ? without any modification ?

@nimaltd
Copy link
Owner

nimaltd commented Feb 7, 2024

@asking23 i think in upper case __NOP()

@Mrezapbs
Copy link

Mrezapbs commented May 23, 2024

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.

@nimaltd
Copy link
Owner

nimaltd commented May 23, 2024

@Mrezapbs thanks for your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants