UART client does not connect

Created at 2022-09-20 23:01:38

Hi,

I'm using rt-thread on a raspberry pi pico and I have this very basic code just to try to connect to another device (esp8266) over uart with AT commands.

I ran two different codes. The first one to prove that I am able to talk to the device and also read what it says. When I have this code and I send ATrn, the response is "OK".

#include <rtthread.h>
#include <rtdevice.h>
#include "pico/stdlib.h"
#include "at.h"
#include <string>
#include <vector>
#include <string.h>
#include <rthw.h>
#include <at.h>

#define AT_RESPONSE_TIMEOUT_MS  10000
#define UART_BUFFER_SIZE    512

const uint8_t LED_PIN = 25;

#define uartName "uart1"

at_client_t m_client;

bool set = false;
uint64_t buff = 32;

void fast_blink(int n) {
    rt_pin_write(LED_PIN, 0);
    sleep_ms(1000);
    for(int i = 0; i < n; i++) {
        rt_pin_write(LED_PIN, 1);
        sleep_ms(500);
        rt_pin_write(LED_PIN, 0);
        sleep_ms(500);
    }
    sleep_ms(500);
}

void read(void) {
    while (1) {
        if (uart_is_readable(uart1)) {
            int i = 0;
            rt_pin_write(LED_PIN, 1);
            while (uart_is_readable(uart1)) {             
                char ch = uart_getc(uart1);
                if(!(ch !='\n' && ch !='\r')) {
                    rt_pin_write(LED_PIN, 0);
                    break;
                    
                }
            }         
        } 
    }
}

int main(void)
{
    
    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
    sleep_ms(5000);
    fast_blink(1);
    uart_init(uart1, 115200);
    gpio_set_function(8, GPIO_FUNC_UART);
    gpio_set_function(9, GPIO_FUNC_UART);
    uart_puts(uart1, "AT\r\n");
    read();
    return 0;
}

However, when I try to use rt-thread (next code snippet below), the 3rd RT_ASSERT will fail.

#include <rtthread.h>
#include <rtdevice.h>
#include "pico/stdlib.h"
#include "at.h"
#include <string>
#include <vector>
#include <string.h>
#include <rthw.h>
#include <at.h>

#define AT_RESPONSE_TIMEOUT_MS  10000
#define UART_BUFFER_SIZE    512

const uint8_t LED_PIN = 25;

#define uartName "uart1"

at_client_t m_client;

bool set = false;


void fast_blink(int n) {
    rt_pin_write(LED_PIN, 0);
    sleep_ms(1000);
    for(int i = 0; i < n; i++) {
        rt_pin_write(LED_PIN, 1);
        sleep_ms(500);
        rt_pin_write(LED_PIN, 0);
        sleep_ms(500);
    }
    sleep_ms(500);
}


int main(void) {
    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);

    // Init embedded uart object
    int initResult = at_client_init(uartName, UART_BUFFER_SIZE);
    RT_ASSERT(initResult == 0); //pass
    fast_blink(2);

    //  obtain the uart client object
    m_client = at_client_get(uartName);      
    RT_ASSERT(m_client->status == at_status::AT_STATUS_INITIALIZED);    //pass
    fast_blink(3);

    //  transmit basic AT test command (AT\r\n) and wait for response of any device
    bool waked = at_client_obj_wait_connect(m_client, AT_RESPONSE_TIMEOUT_MS) == 0;
    RT_ASSERT(waked == true); //FAIL!!!!
    rt_pin_write(LED_PIN, 1);
        
    
    return 0;
}

What am I missing, why do I not get a pass on the RT_ASSERT since the device is there and in my other code I have confirmed that on ATrn an OK is returned by the ESP8266.

More

Follower
0
Views
43
0 Answer
There is no answer, come and add the answer

Write Your Answer

Log in to publish your answer.,Click here to log in.

Create
Post

Share