SysTick功能总结

xiaoxiao2021-02-28  6

一、初始化SysTick

按1ms来设置systick,也可以除以1000000。按1us来设置 SysTick_Config(SystemCoreClock / 1000); //SysTick开启系统tick定时器并初始化其中断,1ms

二、systick的函数

// cycles per microsecond static volatile uint32_t usTicks = 0; // current uptime for 1kHz systick timer. will rollover after 49 days. hopefully we won't care. volatile uint32_t sysTickUptime = 0; // SysTick void SysTick_Handler(void) {     sysTickUptime++; } //delay ms void DelayMs(uint16_t nms) {     uint32_t t0=micros();     while(micros() - t0 < nms * 1000); } // Return system uptime in microseconds (rollover in 70minutes) //返回 us uint32_t micros(void) {     register uint32_t ms, cycle_cnt;     do {         ms = sysTickUptime;         cycle_cnt = SysTick->VAL;     } while (ms != sysTickUptime);     return (ms * 1000) + (usTicks * 1000 - cycle_cnt) / usTicks; } // Return system uptime in milliseconds (rollover in 49 days) uint32_t millis(void) {     return sysTickUptime; } systick启动后会进入SysTick_Handler()的中断,

三、少了重要的一部,哭~T.T

开启RCC时钟!!!!! void cycleCounterInit(void) {     RCC_ClocksTypeDef clocks;     RCC_GetClocksFreq(&clocks);     usTicks = clocks.SYSCLK_Frequency / 1000000; } 遇到的错误:我在初始化MPU6050时,写入数据特别慢。明明计时都准的,不知道为什么特别慢。其他还都能顺利运行。 最后发现时RCC的时钟有问题。 <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 阅读(19) | 评论(0) | 转发(0) | 0

上一篇:四轴电池ADC监控学习

下一篇:PWM输出,呼吸灯

相关热门文章 SHTML是什么_SSI有什么用...查看linux中某个端口(port)...卡尔曼滤波的原理说明...shell中字符串操作关于java中的“错误:找不到或... 给主人留下些什么吧!~~ 评论热议
转载请注明原文地址: https://www.6miu.com/read-450302.html

最新回复(0)