tried to do it through the idf function, but it didn't work properly, so I switched to registers.
I managed to start the timer itself, but now I stopped at 2 problems:
https://anonymfile.com/eRBZO/photo-2023 ... -49-25.jpg
Problem number 1, I set the timer to reset after 4,000,000 years, but for some reason this does not happen ...
https://anonymfile.com/59WLW/photo-2023 ... -49-30.jpg
Problem number 2 is more important, I still don't know where to add the handler interrupt
Code: Select all
#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g(U8G2_R0, U8X8_PIN_NONE, 6, 7);
#define TIMER0_BASE_ADDR 0x6001F000
volatile uint32_t TIMG_T0LO_REG, TIMG_T0HI_REG;
uint64_t TIMG_T0_REG;
void IRAM_ATTR timer_group0_isr() {
}
void setup() {
u8g.begin();
u8g.enableUTF8Print();
u8g.setFont(u8g2_font_unifont_t_cyrillic);
u8g.setFontDirection(0);
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 13) = 1; // Configure the prescaler 40MHz
*(volatile uint32_t *) TIMER0_BASE_ADDR |= (1 << 30); // Count up
*(volatile uint32_t *) TIMER0_BASE_ADDR |= (1 << 29); // AUTORELOAD EN
/* reload value */
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0018) = 4000000; // TIMG_T0_LOAD 32 bit
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x001C) = 0; // TIMG_T0LOADHI_REG 22 bit
/* alarm value */
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0010) = 30000; // TIMG_T0ALARMLO_REG 32 bit
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0014) = 0; // TIMG_T0ALARMHI_REG 22 bit
*(volatile uint32_t *) TIMER0_BASE_ADDR |= (1 << 10); // Alarm enable
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0070) |= (1 << 0); // enable TIMG_T0_INT_ENA interrupt
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0078) |= (1 << 0); // masked TIMG_T0_INT interrupt
// *(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x007C) |= (0 << 0); // Clear the interrupt
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0020) = 1; // Timer 0 time-base counter reload.
*(volatile uint32_t *) TIMER0_BASE_ADDR |= (1 << 31); // Enable Timer 0
}
void loop() {
u8g.clearBuffer();
*(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x000C) |= (1 << 30); // UPDATE
TIMG_T0LO_REG = *(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0004); // ticks LO_REG
TIMG_T0HI_REG = *(volatile uint32_t *)(TIMER0_BASE_ADDR + 0x0008); // ticks HI_REG
TIMG_T0_REG = (uint64_t)TIMG_T0HI_REG << 32 | TIMG_T0LO_REG; // 32 + 22 = 54 bit
u8g.setCursor(35, 20);
u8g.print(TIMG_T0_REG);
u8g.sendBuffer();
delay(1000);
}