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

how to pass the structure value over ble

hi , 

I am working on the nRF52832 , I am trying to store the values in structure and then passing over BLE . I am getting this error after print statement  unknown function of 0x00000A60 

J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (36864 bytes)
J-Link: Flash download: Total time needed: 0.858s (Prepare: 0.111s, Compare: 0.013s, Erase: 0.034s, Program: 0.638s, Verify: 0.001s, Restore: 0.060s)
Download successful
Stopped by vector catch

   nrf_delay_ms(10000);
    // Enter main loop.
for(;;)
    {
int x_val=0;
char data[100];
char a[100];


   for(int i=0;i<=100;i++)
{
    s.accel[i]=x_val;
   // x_val++;
   sprintf(data,"%d",s.accel[i]);
    length= strcat(a,data);
}
printf("%s",a);
ble_nus_data_send(&m_nus,a,&length,m_conn_handle);

    nrf_delay_ms(10000);

  idle_state_handle();
    }
}

Parents
  • Hi 

    I see a couple of issues here.

    First off none of the buffers are initialized to anything, which means that when you run strcat(a, data) for the first time you don't know if the a array is zero terminated anywhere. 
    If it is not zero terminated the strcat function will iterate through memory indefinitely until it encounters a zero, which could take it outside the boundaries of the array. 

    To fix this it should be enough to initialize a[100] like this: 

    char a[100] = {0};

    Another issue is that you convert 100 int values to strings, and try to store them all in a buffer that is only 100 characters long. Depending on the size of the integers they could easily occupy more than one character each, which means the buffers won't be large enough (only the values 0-9 will fit in a single character after converting to a string). 

    I am pretty sure the problem is that you start writing outside the boundaries of the arrays, which means you can corrupt other variables in memory, and even try to access memory outside the legal memory range. 

    Best regards
    Torbjørn

Reply
  • Hi 

    I see a couple of issues here.

    First off none of the buffers are initialized to anything, which means that when you run strcat(a, data) for the first time you don't know if the a array is zero terminated anywhere. 
    If it is not zero terminated the strcat function will iterate through memory indefinitely until it encounters a zero, which could take it outside the boundaries of the array. 

    To fix this it should be enough to initialize a[100] like this: 

    char a[100] = {0};

    Another issue is that you convert 100 int values to strings, and try to store them all in a buffer that is only 100 characters long. Depending on the size of the integers they could easily occupy more than one character each, which means the buffers won't be large enough (only the values 0-9 will fit in a single character after converting to a string). 

    I am pretty sure the problem is that you start writing outside the boundaries of the arrays, which means you can corrupt other variables in memory, and even try to access memory outside the legal memory range. 

    Best regards
    Torbjørn

Children
No Data
Related