Lecture 9: Embedded System Peripherals

This course will explain in more details the principles of embedded programming, peripheral programming, an interrupt handling.

Slides

It is (temporarily) available through sildes here

Exercice: use of timers

Read the doc...

Have 10 minutes looking at chapter 19 (p498) of esp32_datasheet_en.pdf: the chapter dedicated to timers.

  1. How many timers do we have ?
  2. Where are presented the registers configuring timee 0 (group 0)?
  3. More difficult: Where are defined the macros to access these register in IDF suite?

Run a timer simple app

go in the example/blink-timer directory of the course github, run the example and look at the code.

  1. Identify the timer ISR
  2. Identify the timer initialisation
  3. change the blink rythm is some way
  4. Print the address and the value of TIMG_T0CONFIG_REG(0)

Raw Programming of timer register

Here again, the API proposed by IDF is quite complex. In embedded programming, simple is beautiful, we can program all the timer register directly.

  1. Comment the line that starts the timer: timer_start(TIMER_GROUP_0, 0);, does it work now ?
  2. Replace this command by a direct activation of the timer: setting the bit TIMG_T0_EN in register TIMG_T0CONFIG_REG(0) (See documentation page 501: register TIMGn_TxCONFIG_REG). <--

    int config_reg=read_reg(TIMG_T0CONFIG_REG(0));
        config_reg |= 1<<31 ;  
        printf("config_reg 0x%x\n", config_reg);
        write_reg(TIMG_T0CONFIG_REG(0),config_reg);
    

    -->