This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART behaviour changed automatically, numbers sent over RX Characteristic are not received the same on other side.

Hello,

In Nov 2020 I wrote a program for nRF52805 and it was working exactly as I expected it to.

Here is a small section of the code.

static void nus_data_handler(ble_nus_evt_t * p_evt)       /**<Added LATER  START*/
{

    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
        NRF_LOG_DEBUG("Received data from BLE NUS.");
        NRF_LOG_HEXDUMP_INFO(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);

        if((memcmp(p_evt->params.rx_data.p_data,"dfu", p_evt->params.rx_data.length) == 0))
        {
        enter_dfu_mode();
		    }

        if((memcmp(p_evt->params.rx_data.p_data,"name", p_evt->params.rx_data.length) == 0))
        {
        nflag = 1;
		    }


        if((memcmp(p_evt->params.rx_data.p_data,"tx0", p_evt->params.rx_data.length) == 0))
        {
        
	TX_POWER_LEVEL = (0);
            }
        if((memcmp(p_evt->params.rx_data.p_data,"tx4", p_evt->params.rx_data.length) == 0))
        {
        TX_POWER_LEVEL = (+4);
        cflag = 1;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"txm20", p_evt->params.rx_data.length) == 0))
        {
        TX_POWER_LEVEL = (-20);
        cflag = 1;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"txm12", p_evt->params.rx_data.length) == 0))
        {
        TX_POWER_LEVEL = (-12);
        cflag = 1;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"txm8", p_evt->params.rx_data.length) == 0))
        {
        TX_POWER_LEVEL = (-8);
        cflag = 1;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"txm4", p_evt->params.rx_data.length) == 0))
        {
        TX_POWER_LEVEL = (-4);
        cflag = 1;
		    }


        if((memcmp(p_evt->params.rx_data.p_data,"int100", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 160;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int300", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 480;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int500", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 800;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int800", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 1280;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int1000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL= 1600;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int1500", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 2400;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int2000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL= 3200;
        }
        if((memcmp(p_evt->params.rx_data.p_data,"int3000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 4800;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int4000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 6000;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int5000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 8000;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int6000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 9600;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int7000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 11200;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int8000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 12800;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int9000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 14400;
		    }
        if((memcmp(p_evt->params.rx_data.p_data,"int10000", p_evt->params.rx_data.length) == 0))
        {
        cflag = 1;
        APP_ADV_INTERVAL = 16000;
		    }
    }
}                                  

Basically, I just need to be able to change TX POWER, ADV Interval, and the name of the bt device.

Don't mind the horrible logic with a lot of "if" statements. Slight smile

The thing is that everything was working exactly as I planned. I checked the code with nRF52DK and then I uploaded the code to a couple of hand-soldered PCBs as well and in both cases, it was working great. I was able to change ADV Interval, TX Power, and the name without any problem.

And then I ordered 50pcs prototype PCBs with that code.

The PCB factory was able to program the PCB successfully and they were even able to change the interval to 3sec for me by sending the command of "int3000" to the device using nRF Connect app via a phone. (Early Jan 2021)

Everything changed when I received those PCBs. When I wanted to change the interval to 1sec I sent the command "int1000" over but instead of setting it to 1sec the device was set to 10sec instead.

I tried again with different values but it was not working.

I also reuploaded the same firmware back to nrf52dk and now that board is behaving that way as well.  

So far I have learned this

1. When I send int1000 over it changes to 10sec instead of 1sec. Because there is a condition for int10000 as well

2. When I send int500 over it changes to 5sec instead of 500ms like I have put the condition in.

3. Same with int300 changes to 3 sec instead of 300ms.

4. Writing int15 changes it to 1.5sec because there is only one condition for the 15 lines.

So something has happened that puts an extra or two zeroes when we send over those values.

How to solve this issue.

Parents Reply Children
Related