NRF5 UART problem


Primini
 

Hi everyone!

I am developing a firmware responsible to communicate with a sfm10R2 Wisol modem through a serial interface. The wisol shield is coupled in my nRF52832 nordic board. I am trying to get SigfoxID and PAC number from the modem using AT$I=id command, but there is something strange in some responses from modem: sometimes the response did not come with \r\n, for example, AT$I=10 and AT$I=11, which are the commands to get SigfoxID and PAC number respectively:

AT$I=10\r\n or AT$I=10\0\n

Response = A B C D E F F F F F F F ... (the first 6 digits are correct)

AT$I=11\r\n or AT$I=11\0\n

Response = 1 2 3 4 5 6 6 6 6 6 6 6 6 ... (again, the first 6 digits are correct)

Every time a response has more than 6 digits I could read just only the first 6. I could check this using all ids from AT$I=id and sending an invalid command (in this case the response is: E R R O R : : : : : : : : : : : : : ... (repeated ":" and there is no \r\n or \n or \n))

But executing some tests commands (short responses) I can get the correct response, for example:

AT\r\n or AT\0\n

Response = O K \r \n (it seems ok to me) 
AT$SL=AABBCCDDEEFFAABBCCDDEEFF\r\n or AT$SL=AABBCCDDEEFFAABBCCDDEEFF\0\n

Response = O K \r \n (it seems ok to me)

I am working on the serial configuration according to vendor requirements:
baud rate: 9600
data bits: 8
stop bits: 1
parity: none
flow control: false

I am not using interrupt driven and I am just writing and reading from UART_0 using simple commands: uart_poll_out and uart_poll_in, following there is the code I am using to test this application:

#include <zephyr.h>
#include <logging/sys_log.h>
#include <uart.h>

#define BUF_MAXSIZE 20

static void run_command(const char *command) {
  struct device *uart_dev = device_get_binding(CONFIG_UART_NRF5_NAME);

  int i;
  unsigned char sent_char;
  for (i = 0; i < strlen(command); i++) {
    sent_char = uart_poll_out(uart_dev, command[i]);

    if (sent_char != command[i]) {
      printk("expect send %c, actual sent %c\n", command[i], sent_char);
    } else {
      printk("sent char = %c\n", sent_char);
    }
  }
  sent_char = uart_poll_out(uart_dev, '\0');
  printk("sent char = %c\n", sent_char);
  sent_char = uart_poll_out(uart_dev, '\n');
  printk("sent char = %c\n", sent_char);

  unsigned char recv_char;

  int counter = 0;
  int counterMax = 10;
  while (uart_poll_in(uart_dev, &recv_char) == -1 && counter <= counterMax) {
    counter++;
    k_sleep(1000);
    printk("waiting for new message[%02d/%02d]...\n", counter, counterMax);
  }

  printk("%c ", recv_char);

  counter = 0;
  int x = 0;
  while (counter < BUF_MAXSIZE && x == 0) {
    int x = uart_poll_in(uart_dev, &recv_char);
    printk("%c ", recv_char);
    counter++;
  }
}

void main(void)
{
  run_command("AT$I=10");
  run_command("AT$I=11");

  while (true) {
    k_sleep(1000);
  }
}

my prj.conf:

CONFIG_UART_NRF5=y
CONFIG_UART_NRF5_GPIO_RX_PIN=11
CONFIG_UART_NRF5_GPIO_TX_PIN=12
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_NRF5_FLOW_CONTROL=n

CONFIG_HAS_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

Regards,

T. Primini


Chettimada, Vinayak Kariappa
 

Hi Tiago,

 

I see you do not use h/w flow control or interrupt driven Rx. There is only 6 bytes FIFO in UART peripheral hence, if your implementation does not poll in fast, you will loose bytes.

Optimise your implementation or interrupt driven rx or h/w flowcontrol (last one being the safest option).

 

Regards,

Vinayak

 

From: zephyr-devel-bounces@... [mailto:zephyr-devel-bounces@...] On Behalf Of Tiago Primini
Sent: Wednesday, December 20, 2017 12:10 AM
To: zephyr-devel@...
Subject: [Zephyr-devel] NRF5 UART problem

 

Hi everyone!

 

I am developing a firmware responsible to communicate with a sfm10R2 Wisol modem through a serial interface. The wisol shield is coupled in my nRF52832 nordic board. I am trying to get SigfoxID and PAC number from the modem using AT$I=id command, but there is something strange in some responses from modem: sometimes the response did not come with \r\n, for example, AT$I=10 and AT$I=11, which are the commands to get SigfoxID and PAC number respectively:

AT$I=10\r\n or AT$I=10\0\n

Response = A B C D E F F F F F F F ... (the first 6 digits are correct)

AT$I=11\r\n or AT$I=11\0\n

Response = 1 2 3 4 5 6 6 6 6 6 6 6 6 ... (again, the first 6 digits are correct)

Every time a response has more than 6 digits I could read just only the first 6. I could check this using all ids from AT$I=id and sending an invalid command (in this case the response is: E R R O R : : : : : : : : : : : : : ... (repeated ":" and there is no \r\n or \n or \n))

But executing some tests commands (short responses) I can get the correct response, for example:

AT\r\n or AT\0\n

Response = O K \r \n (it seems ok to me) 
AT$SL=AABBCCDDEEFFAABBCCDDEEFF\r\n or AT$SL=AABBCCDDEEFFAABBCCDDEEFF\0\n

Response = O K \r \n (it seems ok to me)

 

I am working on the serial configuration according to vendor requirements:

baud rate: 9600
data bits: 8
stop bits: 1
parity: none
flow control: false


I am not using interrupt driven and I am just writing and reading from UART_0 using simple commands: uart_poll_out and uart_poll_in, following there is the code I am using to test this application:


#include <zephyr.h>
#include <logging/sys_log.h>
#include <uart.h>

#define BUF_MAXSIZE 20

static void run_command(const char *command) {
  struct device *uart_dev = device_get_binding(CONFIG_UART_NRF5_NAME);

  int i;
  unsigned char sent_char;
  for (i = 0; i < strlen(command); i++) {
    sent_char = uart_poll_out(uart_dev, command[i]);

    if (sent_char != command[i]) {
      printk("expect send %c, actual sent %c\n", command[i], sent_char);
    } else {
      printk("sent char = %c\n", sent_char);
    }
  }
  sent_char = uart_poll_out(uart_dev, '\0');
  printk("sent char = %c\n", sent_char);
  sent_char = uart_poll_out(uart_dev, '\n');
  printk("sent char = %c\n", sent_char);

  unsigned char recv_char;

  int counter = 0;
  int counterMax = 10;
  while (uart_poll_in(uart_dev, &recv_char) == -1 && counter <= counterMax) {
    counter++;
    k_sleep(1000);
    printk("waiting for new message[%02d/%02d]...\n", counter, counterMax);
  }

  printk("%c ", recv_char);

  counter = 0;
  int x = 0;
  while (counter < BUF_MAXSIZE && x == 0) {
    int x = uart_poll_in(uart_dev, &recv_char);
    printk("%c ", recv_char);
    counter++;
  }
}

void main(void)
{
  run_command("AT$I=10");
  run_command("AT$I=11");

  while (true) {
    k_sleep(1000);
  }

}

 

my prj.conf:


CONFIG_UART_NRF5=y
CONFIG_UART_NRF5_GPIO_RX_PIN=11
CONFIG_UART_NRF5_GPIO_TX_PIN=12
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_NRF5_FLOW_CONTROL=n

CONFIG_HAS_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

 

Regards,

 

T. Primini


Puzdrowski, Andrzej
 

Hi Tiaga

 

I think you can take good enough Interrupt driven serial adapter form mcuboot repository here:

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/serial_adapter.c

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/include/serial_adapter/serial_adapter.h

 

Regards,

Andrzej

 

From: zephyr-devel-bounces@... [mailto:zephyr-devel-bounces@...] On Behalf Of Chettimada, Vinayak Kariappa
Sent: Wednesday, December 20, 2017 6:46 AM
To: Tiago Primini <primini@...>; zephyr-devel@...
Subject: Re: [Zephyr-devel] NRF5 UART problem

 

Hi Tiago,

 

I see you do not use h/w flow control or interrupt driven Rx. There is only 6 bytes FIFO in UART peripheral hence, if your implementation does not poll in fast, you will loose bytes.

Optimise your implementation or interrupt driven rx or h/w flowcontrol (last one being the safest option).

 

Regards,

Vinayak

 

From: zephyr-devel-bounces@... [mailto:zephyr-devel-bounces@...] On Behalf Of Tiago Primini
Sent: Wednesday, December 20, 2017 12:10 AM
To: zephyr-devel@...
Subject: [Zephyr-devel] NRF5 UART problem

 

Hi everyone!

 

I am developing a firmware responsible to communicate with a sfm10R2 Wisol modem through a serial interface. The wisol shield is coupled in my nRF52832 nordic board. I am trying to get SigfoxID and PAC number from the modem using AT$I=id command, but there is something strange in some responses from modem: sometimes the response did not come with \r\n, for example, AT$I=10 and AT$I=11, which are the commands to get SigfoxID and PAC number respectively:

AT$I=10\r\n or AT$I=10\0\n

Response = A B C D E F F F F F F F ... (the first 6 digits are correct)

AT$I=11\r\n or AT$I=11\0\n

Response = 1 2 3 4 5 6 6 6 6 6 6 6 6 ... (again, the first 6 digits are correct)

Every time a response has more than 6 digits I could read just only the first 6. I could check this using all ids from AT$I=id and sending an invalid command (in this case the response is: E R R O R : : : : : : : : : : : : : ... (repeated ":" and there is no \r\n or \n or \n))

But executing some tests commands (short responses) I can get the correct response, for example:

AT\r\n or AT\0\n

Response = O K \r \n (it seems ok to me) 
AT$SL=AABBCCDDEEFFAABBCCDDEEFF\r\n or AT$SL=AABBCCDDEEFFAABBCCDDEEFF\0\n

Response = O K \r \n (it seems ok to me)

 

I am working on the serial configuration according to vendor requirements:

baud rate: 9600
data bits: 8
stop bits: 1
parity: none
flow control: false


I am not using interrupt driven and I am just writing and reading from UART_0 using simple commands: uart_poll_out and uart_poll_in, following there is the code I am using to test this application:


#include <zephyr.h>
#include <logging/sys_log.h>
#include <uart.h>

#define BUF_MAXSIZE 20

static void run_command(const char *command) {
  struct device *uart_dev = device_get_binding(CONFIG_UART_NRF5_NAME);

  int i;
  unsigned char sent_char;
  for (i = 0; i < strlen(command); i++) {
    sent_char = uart_poll_out(uart_dev, command[i]);

    if (sent_char != command[i]) {
      printk("expect send %c, actual sent %c\n", command[i], sent_char);
    } else {
      printk("sent char = %c\n", sent_char);
    }
  }
  sent_char = uart_poll_out(uart_dev, '\0');
  printk("sent char = %c\n", sent_char);
  sent_char = uart_poll_out(uart_dev, '\n');
  printk("sent char = %c\n", sent_char);

  unsigned char recv_char;

  int counter = 0;
  int counterMax = 10;
  while (uart_poll_in(uart_dev, &recv_char) == -1 && counter <= counterMax) {
    counter++;
    k_sleep(1000);
    printk("waiting for new message[%02d/%02d]...\n", counter, counterMax);
  }

  printk("%c ", recv_char);

  counter = 0;
  int x = 0;
  while (counter < BUF_MAXSIZE && x == 0) {
    int x = uart_poll_in(uart_dev, &recv_char);
    printk("%c ", recv_char);
    counter++;
  }
}

void main(void)
{
  run_command("AT$I=10");
  run_command("AT$I=11");

  while (true) {
    k_sleep(1000);
  }

}

 

my prj.conf:


CONFIG_UART_NRF5=y
CONFIG_UART_NRF5_GPIO_RX_PIN=11
CONFIG_UART_NRF5_GPIO_TX_PIN=12
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_NRF5_FLOW_CONTROL=n

CONFIG_HAS_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

 

Regards,

 

T. Primini


Primini
 

I do not know why but interrupt driven is not working for me, neither hardware flow control, because of this I implemented simple poll in/out. I do not know if the reason is because I have to change the default tx/rx pin configuration because of my wisol shield (the shield does not have CTS/RTS pins). See the boards below:



Inline image 1

Inline image 2

Regards, Tiago.

On Wed, Dec 20, 2017 at 8:37 AM, Puzdrowski, Andrzej <Andrzej.Puzdrowski@...> wrote:

Hi Tiaga

 

I think you can take good enough Interrupt driven serial adapter form mcuboot repository here:

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/serial_adapter.c

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/include/serial_adapter/serial_adapter.h

 

Regards,

Andrzej

 

From: zephyr-devel-bounces@lists.zephyrproject.org [mailto:zephyr-devel-bounces@lists.zephyrproject.org] On Behalf Of Chettimada, Vinayak Kariappa
Sent: Wednesday, December 20, 2017 6:46 AM
To: Tiago Primini <primini@...>; zephyr-devel@lists.zephyrproject.org
Subject: Re: [Zephyr-devel] NRF5 UART problem

 

Hi Tiago,

 

I see you do not use h/w flow control or interrupt driven Rx. There is only 6 bytes FIFO in UART peripheral hence, if your implementation does not poll in fast, you will loose bytes.

Optimise your implementation or interrupt driven rx or h/w flowcontrol (last one being the safest option).

 

Regards,

Vinayak

 

From: zephyr-devel-bounces@lists.zephyrproject.org [mailto:zephyr-devel-bounces@lists.zephyrproject.org] On Behalf Of Tiago Primini
Sent: Wednesday, December 20, 2017 12:10 AM
To: zephyr-devel@lists.zephyrproject.org
Subject: [Zephyr-devel] NRF5 UART problem

 

Hi everyone!

 

I am developing a firmware responsible to communicate with a sfm10R2 Wisol modem through a serial interface. The wisol shield is coupled in my nRF52832 nordic board. I am trying to get SigfoxID and PAC number from the modem using AT$I=id command, but there is something strange in some responses from modem: sometimes the response did not come with \r\n, for example, AT$I=10 and AT$I=11, which are the commands to get SigfoxID and PAC number respectively:

AT$I=10\r\n or AT$I=10\0\n

Response = A B C D E F F F F F F F ... (the first 6 digits are correct)

AT$I=11\r\n or AT$I=11\0\n

Response = 1 2 3 4 5 6 6 6 6 6 6 6 6 ... (again, the first 6 digits are correct)

Every time a response has more than 6 digits I could read just only the first 6. I could check this using all ids from AT$I=id and sending an invalid command (in this case the response is: E R R O R : : : : : : : : : : : : : ... (repeated ":" and there is no \r\n or \n or \n))

But executing some tests commands (short responses) I can get the correct response, for example:

AT\r\n or AT\0\n

Response = O K \r \n (it seems ok to me) 
AT$SL=AABBCCDDEEFFAABBCCDDEEFF\r\n or AT$SL=AABBCCDDEEFFAABBCCDDEEFF\0\n

Response = O K \r \n (it seems ok to me)

 

I am working on the serial configuration according to vendor requirements:

baud rate: 9600
data bits: 8
stop bits: 1
parity: none
flow control: false


I am not using interrupt driven and I am just writing and reading from UART_0 using simple commands: uart_poll_out and uart_poll_in, following there is the code I am using to test this application:


#include <zephyr.h>
#include <logging/sys_log.h>
#include <uart.h>

#define BUF_MAXSIZE 20

static void run_command(const char *command) {
  struct device *uart_dev = device_get_binding(CONFIG_UART_NRF5_NAME);

  int i;
  unsigned char sent_char;
  for (i = 0; i < strlen(command); i++) {
    sent_char = uart_poll_out(uart_dev, command[i]);

    if (sent_char != command[i]) {
      printk("expect send %c, actual sent %c\n", command[i], sent_char);
    } else {
      printk("sent char = %c\n", sent_char);
    }
  }
  sent_char = uart_poll_out(uart_dev, '\0');
  printk("sent char = %c\n", sent_char);
  sent_char = uart_poll_out(uart_dev, '\n');
  printk("sent char = %c\n", sent_char);

  unsigned char recv_char;

  int counter = 0;
  int counterMax = 10;
  while (uart_poll_in(uart_dev, &recv_char) == -1 && counter <= counterMax) {
    counter++;
    k_sleep(1000);
    printk("waiting for new message[%02d/%02d]...\n", counter, counterMax);
  }

  printk("%c ", recv_char);

  counter = 0;
  int x = 0;
  while (counter < BUF_MAXSIZE && x == 0) {
    int x = uart_poll_in(uart_dev, &recv_char);
    printk("%c ", recv_char);
    counter++;
  }
}

void main(void)
{
  run_command("AT$I=10");
  run_command("AT$I=11");

  while (true) {
    k_sleep(1000);
  }

}

 

my prj.conf:


CONFIG_UART_NRF5=y
CONFIG_UART_NRF5_GPIO_RX_PIN=11
CONFIG_UART_NRF5_GPIO_TX_PIN=12
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_NRF5_FLOW_CONTROL=n

CONFIG_HAS_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

 

Regards,

 

T. Primini



Primini
 

Sorry guys, my mistake. Interrupt driven works like a charm.

Thanks a lot, have a nice week.

Tiago.

On Wed, Dec 20, 2017 at 3:48 PM, Tiago Primini <primini@...> wrote:
I do not know why but interrupt driven is not working for me, neither hardware flow control, because of this I implemented simple poll in/out. I do not know if the reason is because I have to change the default tx/rx pin configuration because of my wisol shield (the shield does not have CTS/RTS pins). See the boards below:



Inline image 1

Inline image 2

Regards, Tiago.

On Wed, Dec 20, 2017 at 8:37 AM, Puzdrowski, Andrzej <Andrzej.Puzdrowski@nordicsemi.no> wrote:

Hi Tiaga

 

I think you can take good enough Interrupt driven serial adapter form mcuboot repository here:

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/serial_adapter.c

https://github.com/runtimeco/mcuboot/blob/master/boot/zephyr/include/serial_adapter/serial_adapter.h

 

Regards,

Andrzej

 

From: zephyr-devel-bounces@...hyrproject.org [mailto:zephyr-devel-bounces@lists.zephyrproject.org] On Behalf Of Chettimada, Vinayak Kariappa
Sent: Wednesday, December 20, 2017 6:46 AM
To: Tiago Primini <primini@...>; zephyr-devel@...ct.org
Subject: Re: [Zephyr-devel] NRF5 UART problem

 

Hi Tiago,

 

I see you do not use h/w flow control or interrupt driven Rx. There is only 6 bytes FIFO in UART peripheral hence, if your implementation does not poll in fast, you will loose bytes.

Optimise your implementation or interrupt driven rx or h/w flowcontrol (last one being the safest option).

 

Regards,

Vinayak

 

From: zephyr-devel-bounces@...hyrproject.org [mailto:zephyr-devel-bounces@lists.zephyrproject.org] On Behalf Of Tiago Primini
Sent: Wednesday, December 20, 2017 12:10 AM
To: zephyr-devel@...ct.org
Subject: [Zephyr-devel] NRF5 UART problem

 

Hi everyone!

 

I am developing a firmware responsible to communicate with a sfm10R2 Wisol modem through a serial interface. The wisol shield is coupled in my nRF52832 nordic board. I am trying to get SigfoxID and PAC number from the modem using AT$I=id command, but there is something strange in some responses from modem: sometimes the response did not come with \r\n, for example, AT$I=10 and AT$I=11, which are the commands to get SigfoxID and PAC number respectively:

AT$I=10\r\n or AT$I=10\0\n

Response = A B C D E F F F F F F F ... (the first 6 digits are correct)

AT$I=11\r\n or AT$I=11\0\n

Response = 1 2 3 4 5 6 6 6 6 6 6 6 6 ... (again, the first 6 digits are correct)

Every time a response has more than 6 digits I could read just only the first 6. I could check this using all ids from AT$I=id and sending an invalid command (in this case the response is: E R R O R : : : : : : : : : : : : : ... (repeated ":" and there is no \r\n or \n or \n))

But executing some tests commands (short responses) I can get the correct response, for example:

AT\r\n or AT\0\n

Response = O K \r \n (it seems ok to me) 
AT$SL=AABBCCDDEEFFAABBCCDDEEFF\r\n or AT$SL=AABBCCDDEEFFAABBCCDDEEFF\0\n

Response = O K \r \n (it seems ok to me)

 

I am working on the serial configuration according to vendor requirements:

baud rate: 9600
data bits: 8
stop bits: 1
parity: none
flow control: false


I am not using interrupt driven and I am just writing and reading from UART_0 using simple commands: uart_poll_out and uart_poll_in, following there is the code I am using to test this application:


#include <zephyr.h>
#include <logging/sys_log.h>
#include <uart.h>

#define BUF_MAXSIZE 20

static void run_command(const char *command) {
  struct device *uart_dev = device_get_binding(CONFIG_UART_NRF5_NAME);

  int i;
  unsigned char sent_char;
  for (i = 0; i < strlen(command); i++) {
    sent_char = uart_poll_out(uart_dev, command[i]);

    if (sent_char != command[i]) {
      printk("expect send %c, actual sent %c\n", command[i], sent_char);
    } else {
      printk("sent char = %c\n", sent_char);
    }
  }
  sent_char = uart_poll_out(uart_dev, '\0');
  printk("sent char = %c\n", sent_char);
  sent_char = uart_poll_out(uart_dev, '\n');
  printk("sent char = %c\n", sent_char);

  unsigned char recv_char;

  int counter = 0;
  int counterMax = 10;
  while (uart_poll_in(uart_dev, &recv_char) == -1 && counter <= counterMax) {
    counter++;
    k_sleep(1000);
    printk("waiting for new message[%02d/%02d]...\n", counter, counterMax);
  }

  printk("%c ", recv_char);

  counter = 0;
  int x = 0;
  while (counter < BUF_MAXSIZE && x == 0) {
    int x = uart_poll_in(uart_dev, &recv_char);
    printk("%c ", recv_char);
    counter++;
  }
}

void main(void)
{
  run_command("AT$I=10");
  run_command("AT$I=11");

  while (true) {
    k_sleep(1000);
  }

}

 

my prj.conf:


CONFIG_UART_NRF5=y
CONFIG_UART_NRF5_GPIO_RX_PIN=11
CONFIG_UART_NRF5_GPIO_TX_PIN=12
CONFIG_UART_INTERRUPT_DRIVEN=n
CONFIG_UART_NRF5_FLOW_CONTROL=n

CONFIG_HAS_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

 

Regards,

 

T. Primini