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


Gustavo FN
 

Thank you Rodrigo, I'll work on the code you shared with me and I'll let you know the results.


On Fri, Nov 30, 2018 at 3:29 PM Rodrigo Peixoto <rodrigopex@...> wrote:
The code is:

#include <device.h>
#include <misc/printk.h>
#include <uart.h>
#include <zephyr.h>
#define SYS_LOG_DOMAIN "UART_DRIVER"
#include <logging/sys_log.h>
static void (*__uart_callback)(u8_t) = 0;
void ay_uart_driver_set_callback(void (*callback)(u8_t))
{
__uart_callback = callback;
}
static void uart_fifo_callback(struct device *dev)
{
u8_t recvData;
/* Verify uart_irq_update() */
if (!uart_irq_update(dev)) {
SYS_LOG_ERR("retval should always be 1");
return;
}
/* Verify uart_irq_rx_ready() */
if (uart_irq_rx_ready(dev)) {
/* Verify uart_fifo_read() */
uart_fifo_read(dev, &recvData, 1);
if (__uart_callback) {
__uart_callback(recvData);
}
}
}
u8_t ay_uart_driver_open()
{
struct device *uart_dev = device_get_binding("UART_0");
if (!uart_dev) {
SYS_LOG_ERR("Problem to load uart device");
return 1;
}
/* Verify uart_irq_callback_set() */
uart_irq_callback_set(uart_dev, uart_fifo_callback);
/* Enable Tx/Rx interrupt before using fifo */
/* Verify uart_irq_rx_enable() */
uart_irq_rx_enable(uart_dev);
SYS_LOG_INF("UART device loaded...[OK]");
return 0;
}
void ay_uart_driver_write(u8_t data)
{
<you blocking write code >
}
On Fri, 30 Nov 2018 at 20:12 Rodrigo Peixoto <rodrigopex@...> wrote:
I am not at home. I’ll take a look if I can share that with you.

De nada.
Abraço,
Rodrigo  

On Fri, 30 Nov 2018 at 19:58 Gustavo F N <gustavofn@...> wrote:
No, I haven't. 

Can you share a piece of code of how to do this?

Obrigado Rodrigo!

On Fri, Nov 30, 2018 at 2:57 PM Rodrigo Peixoto <rodrigopex@...> wrote:
I am always using a blocking way to write and a non-blocking way to read. Have you tried?
On Fri, 30 Nov 2018 at 19:50 Gustavo F N <gustavofn@...> wrote:
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
--
Rodrigo Peixoto
Co-founder and Technical guru

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

.
--
Gustavo
--
Rodrigo Peixoto
Co-founder and Technical guru

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

.

--
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.