<?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>i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105750/i2c-timer-work-keeps-getting--22-or--128-and-keep-crashing</link><description>Hi, 
 
 I am using i2c to get sensor data. At first the client write a value to the service. In the service on write callback it trigger&amp;#39;s a timer, in the timer, it submit a work. In the work handler, it reads data and then notify the client. 
 
 but</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Nov 2023 14:51:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105750/i2c-timer-work-keeps-getting--22-or--128-and-keep-crashing" /><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456723?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 14:51:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e419ba6-0704-4197-b81d-9839b153ec84</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Good luck! Just get back to me when you have more details to share.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456618?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 09:05:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c2f3ade-8774-4667-a51a-6170b5af8df3</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;Thanks a lot! I will try to find a way to enable logging.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456589?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 07:25:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8976ecd6-2200-4ed1-bb53-7ff313513a69</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
[quote user="kfcube"]Can the code run on the 52840 DK, which doesn&amp;#39;t have the sensor? [/quote]
&lt;p&gt;Do you mean if you get a kit yourself?&lt;/p&gt;
&lt;p&gt;Typically you would wire up a sensor board to your DK somehow so you can run on the DK with all the functionality operational.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In case you send code to me I would probably have to comment out the sensor code, or replace it with some other sensor I have laying around.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As for your disconnect issues, are you doing anything in the disconnect callback that could explain the issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Most Bluetooth callbacks are run in interrupt context, and if you try to run any blocking function calls from an interrupt it could lead to issues.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to debug the crash you should have logging enabled, then you should see a crash report that might give some indication to the cause of the problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456354?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 10:16:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f79e93ac-c857-4143-a30a-18ad0a660c9d</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;Thanks. Can the code run on the 52840 DK, which doesn&amp;#39;t have the sensor? The issue is only after the sensor data retrieve. As I have replied earlier, I have figured out the -22 issue. Now the only issue left is chip crash and auto start after the client disconnect, if we retrieved sensor data. If we don&amp;#39;t get data, the disconnect worked fine.&lt;br /&gt;&lt;br /&gt;If you may please&amp;nbsp;advise some possibilities so I can dig in.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456352?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 10:10:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67a1c92f-988b-4bc5-b953-852c3ad6f685</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The development platform for the nRF52811 is the nRF52840DK, and it is recommended to get one of those so you can debug the application when needed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are board files in the SDK allowing you to build for the nRF52811 on the nRF52840DK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for sharing the code. I can&amp;#39;t spot any issues in the code you shared that would explain the problem, but the code you shared doesn&amp;#39;t show the whole application either. For instance it doesn&amp;#39;t show where you call the fetch_and_display(..) function, which could be relevant to the issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Would you be able to share the entire project so I can try to run it on my end and reproduce the problem?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can make the case private if you don&amp;#39;t want to share your code in a public ticket.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456288?ContentTypeID=1</link><pubDate>Sun, 19 Nov 2023 12:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb7883fd-aff7-4b81-a822-60cc19010625</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;hey I figured the reason of the 1st connect can&amp;#39;t notify issue. Sorry somehow the client didn&amp;#39;t enable notification for the 1st time connect. so its not the chip issue. so the only issue now is why crash after disconnect. if you may know please advise some possibilities for me to dig in. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456280?ContentTypeID=1</link><pubDate>Sun, 19 Nov 2023 02:28:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:339bf447-5727-4e22-a189-fc85c8b0a808</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;no its not fixed. the problem is still there:&amp;nbsp;&lt;span&gt;1st connect, can&amp;#39;t notify, but can disconnect. 2nd and later, can notify, but disconnect crash the chip.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456261?ContentTypeID=1</link><pubDate>Sat, 18 Nov 2023 06:44:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bc02c15-5165-491b-922e-db91e00b64c3</guid><dc:creator>NadiaEira</dc:creator><description>&lt;p&gt;Thank you for your sharing. It&amp;rsquo;s great that the problem is finally fixed.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ffffff;"&gt;&lt;a style="color:#ffffff;" href="https://skibiditoiletgame.co"&gt;skibidi toilet&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456259?ContentTypeID=1</link><pubDate>Sat, 18 Nov 2023 02:05:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af810c9d-92bb-40a4-867a-14e4ba48595f</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;To be more specific, the current issue is: after the 1st connect, the sensor data notify got -22. then the client disconnect, disconnect working fine. the client connect again, the sensor data notify successfully. but when client disconnect again, the chip crashed and auto restart.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;In a summary, 1st connect, can&amp;#39;t notify, but can disconnect. 2nd and later, can notify, but disconnect crash the chip.&lt;/p&gt;
&lt;p&gt;I set the&amp;nbsp;&lt;span&gt;CONFIG_BT_LOG_LEVEL_DBG = y, but no any errors info.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456258?ContentTypeID=1</link><pubDate>Sat, 18 Nov 2023 01:55:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:068a697e-4b88-49aa-a575-66b9660ffa29</guid><dc:creator>kfcube</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I use timer in order to get sensor data periodically, which actually I learned from here:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/87471/zephyr-timer-i2c"&gt;Zephyr Timer + I2C&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the notification does succeed once after the client disconnect once and then connect again.&lt;/p&gt;
&lt;p&gt;I am not be able to debug because the 52811 small&amp;nbsp;RAM. Is there anyway that I can only debug ble part?&lt;/p&gt;
&lt;p&gt;My code is based on the zephyr/samples/sensor/lsm6dso, and the only change I made is send out sensor data calling&amp;nbsp;bt_gatt_notify&lt;/p&gt;
&lt;p&gt;static inline float out_ev(struct sensor_value *val)&lt;br /&gt;{&lt;br /&gt; return (val-&amp;gt;val1 + (float)val-&amp;gt;val2 / 1000000);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;static void float2byte(float value, uint8_t *out_data,int len)&lt;br /&gt;{&lt;br /&gt; uint8_t *pdata = (uint8_t *)&amp;amp;value;&lt;br /&gt; for(int i = 0;i &amp;lt; len;i++) &lt;br /&gt; { &lt;br /&gt; out_data[i] = *pdata++;&lt;br /&gt; } &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;const struct device *const mdev = DEVICE_DT_GET_ONE(st_lsm6dsr);&lt;/p&gt;
&lt;p&gt;static void fetch_and_display(const struct device *dev)&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt; struct sensor_value x, y, z;&lt;br /&gt; &lt;br /&gt; float xyz[3];&lt;br /&gt; uint8_t acc_data[12];&lt;/p&gt;
&lt;p&gt;trig_cnt++;&lt;/p&gt;
&lt;p&gt;/* lsm6dsr accel */&lt;br /&gt; sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &amp;amp;x);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &amp;amp;y);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &amp;amp;z);&lt;/p&gt;
&lt;p&gt;xyz[0] = out_ev(&amp;amp;x);&lt;br /&gt; xyz[1] = out_ev(&amp;amp;y);&lt;br /&gt; xyz[2] = out_ev(&amp;amp;z);&lt;br /&gt; printf(&amp;quot;accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n&amp;quot;,&lt;br /&gt; xyz[0], xyz[1], xyz[2]);&lt;/p&gt;
&lt;p&gt;float2byte(xyz[0],acc_data,4);&lt;br /&gt; float2byte(xyz[1],acc_data+4,4);&lt;br /&gt; float2byte(xyz[2],acc_data+8,4);&lt;/p&gt;
&lt;p&gt;bt_set_sensor_data(acc_data,sizeof(acc_data)/sizeof(acc_data[0]));&lt;/p&gt;
&lt;p&gt;// printf(&amp;quot;accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n&amp;quot;,&lt;br /&gt; // out_ev(&amp;amp;x), out_ev(&amp;amp;y), out_ev(&amp;amp;z));&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; /* lsm6dsr gyro */&lt;br /&gt; sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &amp;amp;x);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &amp;amp;y);&lt;br /&gt; sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &amp;amp;z);&lt;/p&gt;
&lt;p&gt;printf(&amp;quot;gyro x:%f rad/s y:%f rad/s z:%f rad/s\n&amp;quot;,&lt;br /&gt; out_ev(&amp;amp;x), out_ev(&amp;amp;y), out_ev(&amp;amp;z));&lt;/p&gt;
&lt;p&gt;printf(&amp;quot;trig_cnt:%d\n\n&amp;quot;, trig_cnt);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;int bt_set_sensor_data(uint8_t * p_data,uint16_t len)&lt;br /&gt;{&lt;br /&gt; int rc;&lt;br /&gt; // printk(&amp;quot;len: %d\n&amp;quot;,len);&lt;br /&gt; // for(int i=0;i&amp;lt;len;i++){&lt;br /&gt; // printk(&amp;quot;data[%d]=0x%d\n&amp;quot;,i,p_data[i]);&lt;br /&gt; // }&lt;br /&gt; rc = bt_gatt_notify(mconn, &amp;amp;cube_svc.attrs[1], p_data, len);&lt;br /&gt; printk(&amp;quot;rc: %d\n&amp;quot;,rc);&lt;/p&gt;
&lt;p&gt;return rc == -ENOTCONN ? 0 : rc;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: i2c+timer+work keeps getting -22 or -128 and keep crashing</title><link>https://devzone.nordicsemi.com/thread/456155?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 12:40:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9778b600-5cf8-404a-b3bb-d59149e5a863</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Why do you use a timer to trigger the work item, do you need to add a delay to the sensor readout?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is the notification ever successful, or will it always return an error?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried to debug the call to gatt_notify(..) so you can see exactly where in the code the error is returned?&amp;nbsp;&lt;br /&gt;That can usually provide more details than the error code alone.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Would you be able to share the code showing how the sensor is read and the notification sent?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>