اطلاعیه

Collapse
No announcement yet.

مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

    سلام دوستان
    من بعد کلی سرچ هنوز نتونستم موفق به راه اندازی RTC میکرو بشم هدر برد stm32f103x8t6 از فروشگاه خریداری کرد اما نمیتونم RTC شو با کتابخانه CMSIS راه بندازم اگه کسی از دوستان میتونه راهنمایی کنه ممنون میشم.

    #2
    پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

    کسی سورسی مثالی نداره؟نمیدونم هرکاری میکنم نمیشه!!!!

    دیدگاه


      #3
      پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

      سلام، اینو برای stm32f103ret6 استفاده کردم امیدوارم بدردتون بخوره.

      دیدگاه


        #4
        پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

        سلام با تشکر از کمک شما من الان یه پروژه ساختم برای هدر برد stm32f103c8t6 و برنامه شمارو عینا نوشتم جالبه که متن in the name of god و ... رو lcd نمایش داده میشه اما وقتی پاک میشه دیگه هیچی رو lcd نمیاد ,و بعد از چند ثانیه حدودا 20ثانیه ، led روی هدر برد مربوط به پایه PC13 شروع به چشمک زدن میکنه جالبه که من وقتی برنامه شمارو نگاه کردم دیدم که یه IF گذاشتین که درصورت 1 شدن وارد قسمت نمایش مقادیر ساعت وتاریخ روی LCD میشه اما نمیدونم چرا برای من این اتفاق نمیفته؟!!!!!!

        دلیل: ادغام دو پست برای جلوگیری از اسپم

        یه اتفاق خیلی جالب تر الان بعد گذشت حدود ده دقیقه از کارکرد مدار تازه مقدار ساعت تاریخ خودبخود رو lcd نمایش داده شدمشکل کار انکار از این تابع ( void RTC_IRQHandler (void هستش که خیلی با تاخیر زیاد فعال میشه!!! مشکل از کجاست؟

        دیدگاه


          #5
          پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

          وقت بخیر

          احتمالا سیستم و مقدار کلاک شما با برنامه ارائه شده متفاوت هست !! منبع کلاک و برنامه رو چک کنید !!

          دیدگاه


            #6
            پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

            سلام با تشکر از پاسخ شما من کل برنامه تا جایی که تونستم چک کردم اما متوجه نشدم اشکال از کجاست!

            دلیل: ادغام دو پست برای جلوگیری از اسپم

            نوشته اصلی توسط taktrashe نمایش پست ها
            وقت بخیر

            احتمالا سیستم و مقدار کلاک شما با برنامه ارائه شده متفاوت هست !! منبع کلاک و برنامه رو چک کنید !!
            این برنامه ای هستش که من نوشتم اگه زحمتی نیست شماهم یه نگاهی بندازید ببینید متوجه اشکال میشید ممنونم
            مقدار کلاک اصلی رو 72 مگ تنظیم شده !

            #include "stm32f10x_gpio.h"
            #include "stm32f10x_rcc.h"
            #include "stm32f10x_rtc.h"
            #include "stm32f10x_pwr.h"
            #include "stm32f10x_bkp.h"
            #include <stdio.h>
            #include "misc.h"
            #include "lcd.h"


            #define RTCClockOutput_Enable /* RTC Clock/64 is output on tamper pin(PC.13) */
            #define JULIAN_DATE_BASE 2440588

            __IO uint8_t ActiveDisplay = 0;
            typedef struct{
            uint8_t RTC_Hours;
            uint8_t RTC_Minutes;
            uint8_t RTC_Seconds;
            uint8_t RTC_Day;
            uint8_t RTC_Wday;
            uint8_t RTC_Month;
            uint16_t RTC_Year;
            } RTC_DateTimeTypeDef;

            void _delay_ms(uint16_t ms);
            void RCC_Configuration(void);
            void NVIC_Configuration(void);
            void GPIO_Configuration(void);
            void RTC_Configuration(void);
            uint32_t Time_Regulate(void);
            void Time_Adjust(void);
            void Time_Display(void);
            void RTC_GetDateTime(uint32_t RTC_Counter, RTC_DateTimeTypeDef* RTC_DateTimeStruct);
            uint32_t RTC_GetRTC_Counter(RTC_DateTimeTypeDef* RTC_DateTimeStruct);

            /************************************************** *************************************************/
            void RTC_IRQHandler(void){
            if (RTC_GetITStatus(RTC_IT_SEC) != RESET){
            /* Clear the RTC Second interrupt */
            RTC_ClearITPendingBit(RTC_IT_SEC);
            /* Enable time update */
            ActiveDisplay = 1;
            }
            }


            int main(){
            uint32_t RTC_Counter = 0;
            char st[16];
            RTC_DateTimeTypeDef RTC_DateTime;

            RCC_Configuration();
            /* NVIC configuration */
            NVIC_Configuration();
            /* Configure the GPIOs */
            GPIO_Configuration();

            //initializtion char lcd 16*2
            lcd_init();
            lcd_gotoxy(0,1);
            lcd_puts("inThe nameOf god");
            lcd_gotoxy(0,2);
            lcd_puts(" Hi my friends. ");
            _delay_ms(1500);
            lcd_clear();

            /* RTC Configuration */
            RTC_Configuration();

            RTC_DateTime.RTC_Day = 9;
            RTC_DateTime.RTC_Month = 11;
            RTC_DateTime.RTC_Year = 2017;
            RTC_DateTime.RTC_Hours = 22;
            RTC_DateTime.RTC_Minutes = 43;
            RTC_DateTime.RTC_Seconds = 30;
            _delay_ms(10);
            RTC_SetCounter(RTC_GetRTC_Counter(&RTC_DateTime));

            while(1){
            if(ActiveDisplay == 1){
            RTC_Counter = RTC_GetCounter();
            RTC_GetDateTime(RTC_Counter, &RTC_DateTime);

            sprintf(st, "Clock: %02u:%02u:%02u", RTC_DateTime.RTC_Hours, RTC_DateTime.RTC_Minutes, RTC_DateTime.RTC_Seconds);
            lcd_gotoxy(0,1);
            lcd_puts(st);

            sprintf(st, "Date: %04u.%02u.%02u", RTC_DateTime.RTC_Year, RTC_DateTime.RTC_Month, RTC_DateTime.RTC_Day);
            lcd_gotoxy(0,2);
            lcd_puts(st);

            ActiveDisplay = 0;
            }
            }
            }


            /************************************************** *************************************************/
            void _delay_ms(uint16_t ms){
            uint32_t j=0;
            j = ms * 14400;
            while(j--);
            }

            /************************************************** *************************************************/
            void RCC_Configuration(void){
            ErrorStatus HSEStartUpStatus;
            RCC_DeInit(); // RCC system reset(for debug purpose)
            RCC_HSEConfig(RCC_HSE_ON); // Enable HSE
            HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready
            if(HSEStartUpStatus == SUCCESS){
            RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK
            RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK
            RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2
            RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHz
            RCC_PLLCmd(ENABLE); // Enable PLL
            while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // Wait till PLL is ready
            RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock source
            while(RCC_GetSYSCLKSource() != 0x08); // Wait till PLL is used as system clock source
            }
            }

            /************************************************** *************************************************/
            void NVIC_Configuration(void){
            NVIC_InitTypeDef NVIC_InitStructure;

            /* Configure one bit for preemption priority */
            NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

            /* Enable the RTC Interrupt */
            NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriori ty = 1;
            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
            NVIC_Init(&NVIC_InitStructure);
            }

            /************************************************** *************************************************/
            void GPIO_Configuration(void){
            GPIO_InitTypeDef GPIO_InitStructure;

            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Triger pin
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_Init(GPIOA, &GPIO_InitStructure);
            }

            /************************************************** *************************************************/
            void RTC_Configuration(void){
            /* Enable PWR and BKP clocks */
            RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);

            /* Allow access to BKP Domain */
            PWR_BackupAccessCmd(ENABLE);

            /* Reset Backup Domain */
            BKP_DeInit();

            /* Enable LSE */
            RCC_LSEConfig(RCC_LSE_ON);
            /* Wait till LSE is ready */
            while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);

            /* Select LSE as RTC Clock Source */
            RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

            /* Set RTC prescaler: set RTC period to 1sec */
            RTC_SetPrescaler(32767); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */

            /* Enable RTC Clock */
            RCC_RTCCLKCmd(ENABLE);

            /* Wait for RTC registers synchronization */
            RTC_WaitForSynchro();

            /* Wait until last write operation on RTC registers has finished */
            RTC_WaitForLastTask();

            /* Enable the RTC Second */
            RTC_ITConfig(RTC_IT_SEC, ENABLE);

            /* Wait until last write operation on RTC registers has finished */
            RTC_WaitForLastTask();

            #ifdef RTCClockOutput_Enable
            /* Disable the Tamper Pin */
            /* To output RTCCLK/64 on Tamper pin, the tamper functionality must be disabled */
            BKP_TamperPinCmd(DISABLE);
            /* Enable RTC Clock Output on Tamper Pin */
            BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock );
            #endif
            }

            /************************************************** *************************************************/
            void RTC_GetDateTime(uint32_t RTC_Counter, RTC_DateTimeTypeDef* RTC_DateTimeStruct) {
            unsigned long time;
            unsigned long t1, a, b, c, d, e, m;
            int year = 0;
            int mon = 0;
            int wday = 0;
            int mday = 0;
            int hour = 0;
            int min = 0;
            int sec = 0;
            uint64_t jd = 0;
            uint64_t jdn = 0;

            jd = ((RTC_Counter+43200)/(86400>>1)) + (2440587<<1) + 1;
            jdn = jd>>1;

            time = RTC_Counter;
            t1 = time/60;
            sec = time - t1*60;

            time = t1;
            t1 = time/60;
            min = time - t1*60;

            time = t1;
            t1 = time/24;
            hour = time - t1*24;

            wday = jdn%7;

            a = jdn + 32044;
            b = (4*a+3)/146097;
            c = a - (146097*b)/4;
            d = (4*c+3)/1461;
            e = c - (1461*d)/4;
            m = (5*e+2)/153;
            mday = e - (153*m+2)/5 + 1;
            mon = m + 3 - 12*(m/10);
            year = 100*b + d - 4800 + (m/10);

            RTC_DateTimeStruct->RTC_Year = year;
            RTC_DateTimeStruct->RTC_Month = mon;
            RTC_DateTimeStruct->RTC_Day = mday;
            RTC_DateTimeStruct->RTC_Hours = hour;
            RTC_DateTimeStruct->RTC_Minutes = min;
            RTC_DateTimeStruct->RTC_Seconds = sec;
            RTC_DateTimeStruct->RTC_Wday = wday;
            }

            /************************************************** *************************************************/
            uint32_t RTC_GetRTC_Counter(RTC_DateTimeTypeDef* RTC_DateTimeStruct) {
            uint8_t a;
            uint16_t y;
            uint8_t m;
            uint32_t JDN;

            a = (14-RTC_DateTimeStruct->RTC_Month)/12;
            y = RTC_DateTimeStruct->RTC_Year+4800-a;
            m = RTC_DateTimeStruct->RTC_Month+(12*a)-3;

            JDN = RTC_DateTimeStruct->RTC_Day;
            JDN += (153*m+2)/5;
            JDN += 365*y;
            JDN += y/4;
            JDN += -y/100;
            JDN += y/400;
            JDN = JDN -32045;
            JDN = JDN - JULIAN_DATE_BASE;
            JDN *= 86400;
            JDN += (RTC_DateTimeStruct->RTC_Hours*3600);
            JDN += (RTC_DateTimeStruct->RTC_Minutes*60);
            JDN += (RTC_DateTimeStruct->RTC_Seconds);

            return JDN;
            }

            /************************************************** *************************************************/
            #ifdef USE_FULL_ASSERT
            /**
            * @brief Reports the name of the source file and the source line number
            * where the assert_param error has occurred.
            * [MENTION=17545]para[/MENTION]m file: pointer to the source file name
            * [MENTION=17545]para[/MENTION]m line: assert_param error line source number
            * @retval None
            */
            void assert_failed(uint8_t* file, uint32_t line){
            /* User can add his own implementation to report the file name and line number,
            ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

            /* Infinite loop */
            while (1);
            }
            #endif
            جدیدترین ویرایش توسط bhdisp; ۲۲:۵۴ ۱۳۹۶/۰۹/۰۱.

            دیدگاه


              #7
              پاسخ : مشکل در راه اندازی RTC داخلی میکرو stm32f103c8؟؟؟؟

              سلام دوستان مشکل حل شد مدار بخاطر خرابی کریستال ساعت کار نمیکرد
              خدا انشالله این چینو ...

              دیدگاه

              لطفا صبر کنید...
              X