<?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>value of uint8_t array suddenly changed and sizeof value is not correct</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94064/value-of-uint8_t-array-suddenly-changed-and-sizeof-value-is-not-correct</link><description>Hi 
 
 I was creating a function to send i2c data trough sensor that I use. But when I double check the communication, there is a part that doesn&amp;#39;t works properly. So as you can see, below is the function : 
 
 
 That code used many times, but when I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Nov 2022 03:28:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94064/value-of-uint8_t-array-suddenly-changed-and-sizeof-value-is-not-correct" /><item><title>RE: value of uint8_t array suddenly changed and sizeof value is not correct</title><link>https://devzone.nordicsemi.com/thread/397041?ContentTypeID=1</link><pubDate>Wed, 23 Nov 2022 03:28:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:760d7242-a7c7-46cd-8c1f-739836851f44</guid><dc:creator>azwawe</dc:creator><description>&lt;p&gt;Hi, thanks for responding Einar.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Anyway, I got the solution. My senior engineer told me to expand it and implement it one by one. The way to implement this array is like the code below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int ch201_write_byte(ch201_device *dev_ptr, uint16_t mem_addr, uint8_t data_value) {
	uint8_t message[2];
	message[0] = sizeof(data_value);
	message[1] = data_value;
	int ch_err = i2c_block_write(CH201_I2C_ADDR_PROG, mem_addr, sizeof(message), message);
	return ch_err;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;TBH, I don&amp;#39;t know why I have to do that, but at least it works. Hehe.&lt;/p&gt;
&lt;p&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: value of uint8_t array suddenly changed and sizeof value is not correct</title><link>https://devzone.nordicsemi.com/thread/396662?ContentTypeID=1</link><pubDate>Mon, 21 Nov 2022 13:11:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:426187d2-2eb6-412a-b285-dcab5fda4e40</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You are right, sizeof a uint8 is always 1. This could be caused by a stack overflow, some other part of the code in an interrupt for instance that overwrites and corrupts this memory, or similar.&amp;nbsp;It could also be just a issue with debugging, for instance if you are debugging optimized code things might look strange. A bit more information about your code and how you debug would be needed in order to say more precisely what the cause is here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>