Re: Example of how use UART to communicate with a LTE modem #uart #stm32

Gustavo FN

Thank you Stefan, I'll take a look.

I'll share here the simple code I'm doing but so far it is not working. The pins PA9 and PA10 of my STM32 are connected to an adapter to serial port (TX->RX, RX->TX and same ground, also I powed the adapter at 3.3V STM32 pin), a serial port cable and then connected to the modem LTE serial port (I'll double check if the adapter is working well to).

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <uart.h>

static int myuart_send(struct device *uart, char * szStr) {
    size_t i;
    unsigned char temp;
    for (i = 0; i < strlen(szStr); i++) {
        temp = szStr[i];
        temp = uart_poll_out(uart, temp);

#define myuart_UART "UART_1"

void main(void) {
    struct device * uart;

    // uart setup
    uart = device_get_binding(myuart_UART);
    if (!uart) {
        printk("Cannot find myuart uart(%s)!\n", myuart_UART);

    printk("Sending AT to UART");
    printk("Sleeping 500ms");
    printk("Infinite Loop to read the response from uart1");
    while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);

What I'm missing? This code should send the command "AT" to the modem and the loop should expect to print the "OK" back.

Thanks everyone,

On Fri, Nov 30, 2018 at 6:58 AM Paul Sokolovsky <paul.sokolovsky@...> wrote:
Hello Stefan,

On Fri, 30 Nov 2018 10:20:19 +0000
"Stefan Jaritz" <stefan@...> wrote:


> Keep in mind when you are on the master branch that the API is
> changing from time to time. p.e. 2 days ago the uart_poll_out
> function changed and broke my demo project. :D

Can you elaborate on this? uart_poll_out() is one of the most stable
functions one can imagine, and we're making commitment to not touch it
with the upcoming refactors of UART APIs (which are required otherwise
to both make it more general and easier to use).

> Regards!
> Stefan


Best Regards,
Paul | Open source software for ARM SoCs
Follow Linaro:!/linaroorg -


Join to automatically receive all group messages.