Здравствуйте, Сделал большой код в основном .ino, теперь хочу всё вынести в разные файлы, но не могу понять как вынести управлением времени (библиотека STM32RTC.h)
Этот код компилируется без ошибок Код (C++): #include <Arduino.h> #include <STM32RTC.h> STM32RTC& rtc = STM32RTC::getInstance(); void setup(){ } void loop(){ } void setTimeRTC() { const byte seconds = 0; const byte minutes = 25; const byte hours = 10; rtc.setTime(hours, minutes, seconds); } void setDateRTC() { const byte weekDay = 1; const byte day = 20; const byte month = 8; const byte year = 23; rtc.setDate(weekDay, day, month, year); } void rtc_init() { //rtc.setClockSource(STM32RTC::LSE_CLOCK); rtc.begin(); // initialize RTC 24H format } А вот этот не компилируется: Код (C++): #include <Arduino.h> #include "clock.h" void setup(){ } void loop(){ } clock.cpp: Код (C++): #include "clock.h" /* Get the rtc object */ //STM32RTC& rtc = STM32RTC::getInstance(); void setTimeRTC() { const byte seconds = 0; const byte minutes = 25; const byte hours = 10; rtc.setTime(hours, minutes, seconds); } void setDateRTC() { const byte weekDay = 1; const byte day = 20; const byte month = 8; const byte year = 23; rtc.setDate(weekDay, day, month, year); } void rtc_init() { //rtc.setClockSource(STM32RTC::LSE_CLOCK); rtc.begin(); // initialize RTC 24H format } clock.h: Код (C++): #ifndef __clocks_H #define __clocks_H #include <Arduino.h> #include <STM32RTC.h> void setTimeRTC(); void setDateRTC(); void checkdate (); void rtc_init(); ///* Get the rtc object */ STM32RTC& rtc = STM32RTC::getInstance(); #endif Компилятор: Код (Text): In file included from C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:44, from C:\Users\Dell\Documents\Arduino\test_rtc_lib/clock.h:5, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_time.h:23, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:38, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/Arduino.h:36, from C:\Users\Dell\Documents\Arduino\test_rtc_lib\test_rtc_lib.ino:1: C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:6: error: variable or field 'RTC_SetClockSource' declared void 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:25: error: 'sourceClock_t' was not declared in this scope 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:176:36: error: 'sourceClock_t' has not been declared 176 | bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:101:21: error: '::LSI_CLOCK' has not been declared 101 | LSI_CLOCK = ::LSI_CLOCK, | ^~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:102:21: error: '::LSE_CLOCK' has not been declared; did you mean 'LSI_CLOCK'? 102 | LSE_CLOCK = ::LSE_CLOCK, | ^~~~~~~~~ | LSI_CLOCK C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:103:21: error: '::HSE_CLOCK' has not been declared; did you mean 'LSE_CLOCK'? 103 | HSE_CLOCK = ::HSE_CLOCK | ^~~~~~~~~ | LSE_CLOCK In file included from C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:44, from C:\Users\Dell\Documents\Arduino\test_rtc_lib\clock.h:5, from C:\Users\Dell\Documents\Arduino\test_rtc_lib\clock.cpp:1: C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:6: error: variable or field 'RTC_SetClockSource' declared void 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:25: error: 'sourceClock_t' was not declared in this scope 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:176:36: error: 'sourceClock_t' has not been declared 176 | bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:101:21: error: '::LSI_CLOCK' has not been declared 101 | LSI_CLOCK = ::LSI_CLOCK, | ^~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:102:21: error: '::LSE_CLOCK' has not been declared; did you mean 'LSI_CLOCK'? 102 | LSE_CLOCK = ::LSE_CLOCK, | ^~~~~~~~~ | LSI_CLOCK C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:103:21: error: '::HSE_CLOCK' has not been declared; did you mean 'LSE_CLOCK'? 103 | HSE_CLOCK = ::HSE_CLOCK | ^~~~~~~~~ | LSE_CLOCK exit status 1 Ошибка компиляции для платы Generic STM32F1 series.
Код (C++): #ifndef __clocks_H #define __clocks_H #include <Arduino.h> #include <STM32RTC.h> ///* Get the rtc object */ STM32RTC& rtc = STM32RTC::getInstance(); void setTimeRTC1() { const byte seconds = 0; const byte minutes = 25; const byte hours = 10; rtc.setTime(hours, minutes, seconds); } void setDateRTC1() { const byte weekDay = 1; const byte day = 20; const byte month = 8; const byte year = 23; rtc.setDate(weekDay, day, month, year); } void rtc_init1() { rtc.setClockSource(STM32RTC::LSE_CLOCK); rtc.begin(); // initialize RTC 24H format } #endif ошибка: Код (Text): In file included from C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:44, from C:\Users\Dell\Documents\Arduino\test_rtc_lib/clock.h:5, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring_time.h:23, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/wiring.h:38, from C:\Users\Dell\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.6.0\cores\arduino/Arduino.h:36, from C:\Users\Dell\Documents\Arduino\test_rtc_lib\test_rtc_lib.ino:1: C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:6: error: variable or field 'RTC_SetClockSource' declared void 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:167:25: error: 'sourceClock_t' was not declared in this scope 167 | void RTC_SetClockSource(sourceClock_t source); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/rtc.h:176:36: error: 'sourceClock_t' has not been declared 176 | bool RTC_init(hourFormat_t format, sourceClock_t source, bool reset); | ^~~~~~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:101:21: error: '::LSI_CLOCK' has not been declared 101 | LSI_CLOCK = ::LSI_CLOCK, | ^~~~~~~~~ C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:102:21: error: '::LSE_CLOCK' has not been declared; did you mean 'LSI_CLOCK'? 102 | LSE_CLOCK = ::LSE_CLOCK, | ^~~~~~~~~ | LSI_CLOCK C:\Users\Dell\Documents\Arduino\libraries\STM32RTC\src/STM32RTC.h:103:21: error: '::HSE_CLOCK' has not been declared; did you mean 'LSE_CLOCK'? 103 | HSE_CLOCK = ::HSE_CLOCK | ^~~~~~~~~ | LSE_CLOCK exit status 1 Ошибка компиляции для платы Generic STM32F1 series. Почему компилятор жалуется, что не определены: sourceClock_t, ::LSI_CLOCK, HSE_CLOCK и чем ошибочен RTC_SetClockSource
Компилируется без ошибок, но если подключаю пустой clock.h, то ошибки возвращаются. Но как, там же ни намёка на rtc уже нет Код (C++): //#include <Arduino.h> //#include "clock.h" #include <STM32RTC.h> STM32RTC& rtc = STM32RTC::getInstance(); void setup(){ //rtc.setClockSource(STM32RTC::LSE_CLOCK); rtc.begin(); // initialize RTC 24H format } void loop(){ }
Попробуйте везде убрать #include <Arduino.h> и в setup() добавьте функцию rtc_init1(). И защиту от редекларации #ifndef __clocks_H тоже уберите.