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


Gustavo FN
 

Hi Rodrigo,

Yes the pins are okay. I can confirm the STM32 is sending a testing message (I connected the sending UART to my computer and read the input).

Looks like the code to read the response is not working, the following part:

while (1) {
unsigned char recvChar;
while (uart_poll_in(uart, &recvChar) < 0)
printk("%c", recvChar);
}

On Fri, Nov 30, 2018 at 2:45 PM Rodrigo Peixoto <rodrigopex@...> wrote:
Gustavo,

Are you sure the pins are setup ok? You can try to use a ftdi connector to be sure.

Do you have an dts overlay?

Best regards,
Rodrigo
On Fri, 30 Nov 2018 at 12:59 Gustavo FN <gustavofn@...> wrote:
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);
        return;
    }

    printk("Sending AT to UART");
    myuart_send(uart,"AT\r");
    printk("Sleeping 500ms");
    k_sleep(500);
    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

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog



--
Gustavo

--
Rodrigo Peixoto
Co-founder and Technical guru

+55 (82) 98144-8585
http://ayna.tech | Skype: rodrigopex

.
--
Gustavo

Join users@lists.zephyrproject.org to automatically receive all group messages.