Serial monitoring and writing

Deouss
Posts: 89
Joined: Tue Mar 20, 2018 11:36 am

Serial monitoring and writing

Postby Deouss » Wed May 16, 2018 2:18 pm

It is just a simple question related to serial monitor as in Arduino

Is this code equivalent to serial.write()/print() ?
https://github.com/espressif/esp-idf/bl ... ple_main.c

Also I am looking for examples with more than one timer interrupts - maybe someone can direct me.
Thanks

ESP_Angus
Posts: 894
Joined: Sun May 08, 2016 4:11 am

Re: Serial monitoring and writing

Postby ESP_Angus » Thu May 17, 2018 1:59 am

The UART driver (as linked) gives you very fine-grained control over the uart.

If you only need simple serial printing, you can call standard libc printf(). Will print stdout to UART0 by default.

If you want more powerful serial logging (with adjustable log levels, etc) then you can use the built-in logging framework:
http://esp-idf.readthedocs.io/en/latest ... m/log.html

ESP_Angus
Posts: 894
Joined: Sun May 08, 2016 4:11 am

Re: Serial monitoring and writing

Postby ESP_Angus » Thu May 17, 2018 2:03 am

Deouss wrote:Also I am looking for examples with more than one timer interrupts - maybe someone can direct me.


The "timer_group" example in examples/peripherals/timer_group sets up two timers in a single timer group and queries the triggering timer in the ISR.

For more generic high precision timer requirements, try the esp timer framework:
http://esp-idf.readthedocs.io/en/latest ... timer.html

Unfortunately there's no example in ESP-IDF for esp_timer right now.

Deouss
Posts: 89
Joined: Tue Mar 20, 2018 11:36 am

Re: Serial monitoring and writing

Postby Deouss » Thu May 17, 2018 12:39 pm

ESP_Angus wrote:
Deouss wrote:Also I am looking for examples with more than one timer interrupts - maybe someone can direct me.


The "timer_group" example in examples/peripherals/timer_group sets up two timers in a single timer group and queries the triggering timer in the ISR.

For more generic high precision timer requirements, try the esp timer framework:
http://esp-idf.readthedocs.io/en/latest ... timer.html

Unfortunately there's no example in ESP-IDF for esp_timer right now.


Very interesting. I see it is done with communicating between interrupt and task thread with queues.
I wonder if I could just initialize pure timer interrupt and do stuff on that level completely skipping task and queue which consume memory. Timer should do the job periodically after timer_start(TIMER_GROUP_0, timer_idx)
Of course xTasking is much nicer codewise.
I will do some tests with high res timer and wonder what max frequencies we can achieve on ISR currently.

Deouss
Posts: 89
Joined: Tue Mar 20, 2018 11:36 am

Re: Serial monitoring and writing

Postby Deouss » Thu May 17, 2018 3:07 pm

I wrote a simple example that does blink every 1s
It uses esp_timer()

;)

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_timer.h"
#include "sdkconfig.h"

#define BLINK_GPIO 2 // devkit is 2 beetle is 0 - other boards may have a different pin

esp_timer_create_args_t create_args;
esp_timer_handle_t timer_handle;

int b = 0;
void timer_expired(void *p)
{
b = (~b)&1;
gpio_set_level(BLINK_GPIO,b);
}

void app_main()
{
gpio_pad_select_gpio(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);

create_args.callback = timer_expired;
create_args.dispatch_method = ESP_TIMER_TASK;
create_args.name = "esp_timer";

esp_timer_create(&create_args, &timer_handle);

esp_timer_start_periodic(timer_handle, 1000000);

}

Deouss
Posts: 89
Joined: Tue Mar 20, 2018 11:36 am

Re: Serial monitoring and writing

Postby Deouss » Fri May 18, 2018 12:47 am

After testing esp_timer() - I found out that maximum frequency is 10 kHz sharp even after changing period to 1 us.
Is it maximum you can achieve with this timer? Do I have to set up something in menuconfig maybe?
Also could be the GPIO setup slowing down the access. Not sure.
What about other timers - can I have faster speeds?

Small update: using hardware timer group I achieved 1.1MHz timer interrupt which is quite satisfying compared to 10kHz )
I really wonder if we can get higher clocks like SPI e.g. 40MHz or above.

Who is online

Users browsing this forum: Vader_Mester, WiFive and 2 guests