Chat freely about anything...

User avatar
By zinahe
#7483 Hi,

My very first post here. So please be gentle. After successfully compiling and flashing my very first c program that blinks a LED tied to GPIO2; I wanted to try out sending some text over the UART using os_printf(). The output image is built using esp-open-sdk and esspressif 0.9.3 SDK. The program compiles without errors, and I was able to flash the image on to the esp8266. I can see from the blue led that there is definitely stuff coming out of the UART; which is a good sign. But all I see on the serial terminal is just unreadable garbage. I have tried 9600, 115200 and a bunch of other baud rates. Any help is appreciated. It's kind of annoying when such a simple program turns out to be a major pain in the you-know-what.

Thanks

Code: Select all. . . header files . . .

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1

os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void loop(os_event_t *events);

//Main code function
static void ICACHE_FLASH_ATTR
loop(os_event_t *events)
{
    os_printf("Hello\n\r");
    os_delay_us(10000);
    system_os_post(user_procTaskPrio, 0, 0 );
}

//Init function
void ICACHE_FLASH_ATTR
user_init()
{
    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
    system_os_post(user_procTaskPrio, 0, 0 );
}
User avatar
By kadamski
#7611 To be honest you did not show the most imporant part of the code - the one that initializes UART. In AT example it's stored inside of driver directory:
https://github.com/espressif/esp8266_at ... /at/driver

It's quite long and messy but basically it does three things:
0. Configure pins as UART pins. Each pin on esp8266 can be configured to do different things (each pin can have up to 5 functions IIRC), For example GPIO1 can be UART0 TX or SPICS1 or general GPIO.
1. Configure UART registers (uart_config() functions). This tells hardware what UART configuration you want to use (i.e. baud rate, parity, bits).
2. Creates and registers a callback function that will write one character to the UART. This function is then used by os_printf() to actually write any output. Look at os_install_putc1().

Note that the uart driver from at demo app configures both UARTs (0 and 1) for both reading and writing, which is much more than you actually need. Also note that os_printf() is used by internal functions of the "OS" for displaying some debug information (like about connecting to wifi, getting DHCP IP etc).
User avatar
By amatron
#7616
zinahe wrote:Hi,

My very first post here. So please be gentle. After successfully compiling and flashing my very first c program that blinks a LED tied to GPIO2; I wanted to try out sending some text over the UART using os_printf(). The output image is built using esp-open-sdk and esspressif 0.9.3 SDK. The program compiles without errors, and I was able to flash the image on to the esp8266. I can see from the blue led that there is definitely stuff coming out of the UART; which is a good sign. But all I see on the serial terminal is just unreadable garbage. I have tried 9600, 115200 and a bunch of other baud rates. Any help is appreciated. It's kind of annoying when such a simple program turns out to be a major pain in the you-know-what.

Thanks



For solution this problem, in your terminal program set standart for ESP8266 baud rate - 74880.
User avatar
By zinahe
#7635 @kadamski

Thank you for taking your time to post such a detailed answer. I'm very grateful.

To be honest, except for the include directives I kind of commented out in my last posting; that was the only piece of code I was trying to compile/build. With os_printf being provided as part of the SDK/RTOS; it made no sense to me that the function relies on a user initializing the UART(s) before it can be called. Not to mention, that I could clearly see some UART activity whenever the function is called. Doesn't that mean the underlying peripheral is in some sort of working order ?

Anyway, I'll work on your recommendation and report back my findings.

Thanks