Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 9 months ago.
Is there an anybody that manage HAL_Delay for microsecond
Hi everyone , I wanna use DS18B20 but I need microsecond function or method to HAL_Delay in Hal Library..Save me please
1 Answer
6 years, 9 months ago.
Which Hal Library? Considering your previous question I am assuming an STM Hal library. Then you are better of asking STM (maybe they also have forums). This is intended for mbed related questions.
I tried some ways like these but keil compiler didn't allow to compile asm codes and I got different style in C using a website codes below.Now my new problem is HAL_GPIO_WritePin is working reverse but everything seems ok.
/*void delayUS_ASM(uint32_t value) { SysTick->VAL = 8 * value; uint32_t temp = SysTick->VAL; while(temp) { temp = SysTick->VAL; } }*/ /*void delayUS_ASM(uint32_t delay_us) { uint32_t nb_loop; nb_loop = (((SystemCoreClock / 1000000)/4)*delay_us)+1; /* uS (divide by 4 because each loop take about 4 cycles including nop +1 is here to avoid delay of 0 */ /*asm volatile ( "1: " "\n\t" " nop " "\n\t" " subs.w %0, %0, #1 " "\n\t" " bne 1b " "\n\t" : "=r" (nb_loop) : "0"(nb_loop) : "r3" ); }*/
and in C
static inline void delay_us(volatile uint16_t micros) { micros *= (SystemCoreClock / 1000000) / 5;
while (micros);
}