<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/31045/nrf52832-uart-send-multiple-bytes</link><description>Hi all, 
 I am trying to send a command to the sensor so that the sensor will response with sending something back for acknowledgement, via UART. 
 Let say, I want to send a command &amp;quot;SEND&amp;quot; to sensor, and the sensor will send its data back. However, I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Mar 2018 07:24:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/31045/nrf52832-uart-send-multiple-bytes" /><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122940?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 07:24:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b896694-bce3-4e7c-99d6-ab40d2b70cbc</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;What sensor are you using? Have you tried with&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const char * send_cmd = &amp;quot;SEND\n&amp;quot;;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also check you have the right UART configuration (baudrate, flow control, parity). The best would be to use a logic analyser to see what happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122928?ContentTypeID=1</link><pubDate>Tue, 06 Mar 2018 05:30:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:415ed046-d5f5-498e-beff-c1a75ee50734</guid><dc:creator>JacksonLau</dc:creator><description>&lt;p&gt;May I ask why I can get correct response from sensor when I input command &amp;quot;SEND&amp;quot; on PuTTY but no response by using sendAction()?&lt;/p&gt;
&lt;p&gt;If I connect UART to nothing, the command is correctly shown on PuTTY. It means the sendAction() has no problem.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void) {
    ...
    while (true)
    {
    	sendAction();
		nrf_delay_ms(500);
		app_uart_flush();
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But when I connect the uart serial communication betweem nrf and sensor, there is no response unless I input command by keyboard, and then the console shows temperature value.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122771?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 09:27:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ea2f10d-22a2-42eb-a7ea-d2dbb9a0da0b</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;No you shouldn&amp;#39;t worry about it.&lt;/p&gt;
&lt;p&gt;You can modify my first exemple to transmit &amp;quot;SEND&amp;quot; in sendAction(), and modify the handler to process the 2 bytes response with a counter or somthing like that. I think you&amp;#39;ll be fine with the default fifo buffer size.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const char * send_cmd = &amp;quot;SEND&amp;quot;;
char rsp[2];
uint8_t cmdIndex = 0;
...
void sendAction()
{
    uint8_t i;
    for(i = 0; i &amp;lt; sizeof(send_cmd); i++)
    {
        while (app_uart_put(send_cmd[i]) != NRF_SUCCESS);
    }
}
void uart_handle(app_uart_evt_t * p_event)
{
    ...
    else if (p_event-&amp;gt;evt_type == APP_UART_DATA_READY)
    {
        
        while (app_uart_get(&amp;amp;cr) != NRF_SUCCESS);
        rsp[cmdIndex++] =  cr;
 
        if(cmdIndex == 2)
        {
            printf(&amp;quot;Sensor Value : 0x%02X%02x\r\n&amp;quot;, rsp[0],rsp[1]);
            
            cmdIndex = 0;
        }
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122764?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 09:04:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b363d785-398d-4998-a94a-9c87f255cc74</guid><dc:creator>jakub</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can check CLI example. I think it is what you need.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122757?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 08:56:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45eac319-195c-429b-9897-78df66128018</guid><dc:creator>JacksonLau</dc:creator><description>&lt;p&gt;To make it simple, let say I just want to send command &amp;quot;SEND&amp;quot; to sensor, no matter from PC PuTTY or hard code in nrf MCU. When sensor receive any signal &amp;quot;SEND&amp;quot;, it will response back with its temperature value which is stored in 2 bytes.&lt;/p&gt;
&lt;p&gt;I think I shouldn&amp;#39;t&amp;nbsp;worry about&amp;nbsp;anything in&amp;nbsp;&lt;span&gt;app_uart_fifo.c, only modify the application handler provided in APP_UART_FIFO_INIT. But I am not sure if I need to change the&amp;nbsp;FIFO&amp;nbsp;buffer size for tx/rx in my case.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122748?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 08:30:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52a6e92d-b5e2-449d-abc4-42cd198a6fde</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The uart_event_handler in app_uart_fifo.c basically passes the event to your application handler you provided in the&amp;nbsp;APP_UART_FIFO_INIT.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you be more specific with the data you supposed to send/receive to/from the sensor?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122725?ContentTypeID=1</link><pubDate>Mon, 05 Mar 2018 03:33:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29dfd1e9-ea9a-4676-a536-7f94f20c1daa</guid><dc:creator>JacksonLau</dc:creator><description>&lt;p&gt;Thanks for the reply. I want to&amp;nbsp;clarify about the usage of&amp;nbsp;app_uart_put/app_uart_get. From the app_uart.h, the app_uart_put() is described to put a byte on the UART on TX buffer for transmission, I guess it means send data/command from nrf52 to sensor in my case.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;May I ask what is the difference between&amp;nbsp;the uart handler from app_uart_evt_t&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void uart_handle(app_uart_evt_t * p_event)

{
...
else if (p_event-&amp;gt;evt_type == APP_UART_DATA_READY)
{...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and nrf_drv_uart_event_t&amp;nbsp;from&amp;nbsp;app_uart_fifo.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
{
    app_uart_evt_t app_uart_event;
    uint32_t err_code;

    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_UART_EVT_RX_DONE:
        ...&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 UART send multiple bytes</title><link>https://devzone.nordicsemi.com/thread/122556?ContentTypeID=1</link><pubDate>Fri, 02 Mar 2018 08:22:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:609dbf7b-1caa-42d2-a6c1-14f9f4b1a2bb</guid><dc:creator>Bastien Reynard</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would use app_uart_get() whenever a&amp;nbsp;APP_UART_DATA_READY event arrives and check&amp;nbsp;if it&amp;#39;s a &amp;#39;\n&amp;#39; character. When that&amp;#39;s the case, just loop app_uart_put with all your response bytes.&lt;/p&gt;
&lt;p&gt;If I understand correctly, you want to do something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;string.h&amp;quot;  ///&amp;lt; strcmp()
...
uint8_t cr;
char cmd[MAX_CMD_LEN];
uint8_t cmdIndex = 0;
...
void sendAction()
{
    uint8_t i;
    for(i = 0; i &amp;lt; SENSOR_VALUE_LEN; i++)
    {
        while (app_uart_put(sensorValue[i]) != NRF_SUCCESS);
    }
}
...
void uart_handle(app_uart_evt_t * p_event)
{
    ...
    else if (p_event-&amp;gt;evt_type == APP_UART_DATA_READY)
    {
        
        while (app_uart_get(&amp;amp;cr) != NRF_SUCCESS);
        cmd[cmdIndex++] =  cr;
        cmd[cmdIndex] = 0;
 
        if(cr == &amp;#39;\n&amp;#39;)
        {
            printf(&amp;quot;RX end! Command is : %s\r\n&amp;quot;, cmd);
            if(strcmp(cmd, &amp;quot;SEND\n&amp;quot;) == 0)
            {
                sendAction();
            }
            else if(strcmp(cmd, &amp;quot;STATUS\n&amp;quot;) == 0)
            {
                
            }
            cmdIndex = 0;
        }
    }
}
...
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>