<?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>Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14175/accelerometer-giving-out-random-output</link><description>Hello.
I am using a nrf51822 with sdk 10 and softdevice 130.
It has an accelerometer mma8653 to read the orientation of the chip, I am trying to get the x,y and z co-ordinates from it using i2c method and have a nrf_drv_twi example as reference but</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 Jun 2016 04:24:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14175/accelerometer-giving-out-random-output" /><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54150?ContentTypeID=1</link><pubDate>Fri, 03 Jun 2016 04:24:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8c1a0b9-4c75-4341-82b3-49a05823349f</guid><dc:creator>piyush</dc:creator><description>&lt;p&gt;I meant the read values off from any registers go to 0xFF rather than an expected value. We tried to read the device ID on 0x0D assuming we would get 0x5A but there too we got 0xFF. Which is why I tried with 0x19 as the datasheet said that the read would return 0x00 but there too I&amp;#39;m only getting 0xFF or 0xFE. I erased the softdevice and connected the TWI pins to arduino and implemented the TWI there and the device is working just fine. Also implemented the &amp;#39;I2C device scan&amp;#39; for arduino and it shows the device being ack but when in comes to implement TWI resistors, mounted a new chip, also have tried just with the chip and nRF51 Dev board too, no luck. Which, is why I am not being able to exactly locate where the issue could be.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54149?ContentTypeID=1</link><pubDate>Thu, 02 Jun 2016 13:54:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b2297f0-1c65-412c-b01a-6cadf8d4c44c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;What do you mean with &amp;quot;rx_buffer goes straight to 0xFF&amp;quot;?&lt;/p&gt;
&lt;p&gt;In your main while loop you call MMA_I2C_data_read(). There you call &lt;code&gt;MMA_I2C_register_read(MMA_ADDR, 0x19, rx_buffer, sizeof(rx_buffer));&lt;/code&gt;. This will start a read from address 0x19. According to &lt;a href="https://www.google.no/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=1&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=0ahUKEwj11svhvYnNAhUpAZoKHclLCz0QFggdMAA&amp;amp;url=http%3A%2F%2Fcache.nxp.com%2Ffiles%2Fsensors%2Fdoc%2Fdata_sheet%2FMMA8653FC.pdf%3Fpspll%3D1&amp;amp;usg=AFQjCNHqeaxgsAxrqjtgSBRW7jWXnwx5KQ"&gt;this datasheet&lt;/a&gt; address 0x19 is reserved, and it looks like it should return 0x00?&lt;/p&gt;
&lt;p&gt;Have you checked if any of the TWI function calls return any errors? You can do it like described &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/?answer=60126#post-id-60126"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54148?ContentTypeID=1</link><pubDate>Thu, 02 Jun 2016 08:18:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:552ba649-d2ff-406f-b3c5-b1b34b51488e</guid><dc:creator>piyush</dc:creator><description>&lt;p&gt;Hey Martin, the i2c works fine with other chips, tried it with capacitive touch module, read and write work fine there. here is the link for a new folder with just mma code. could you please try it out and tell about the error. the rx_buffer goes straight to 0xFF. Thanks in advance.
&lt;a href="https://drive.google.com/open?id=0B4dJxTKQG_n5MzlLa3hRSVpUeEE"&gt;drive.google.com/open&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54147?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 15:16:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39dbff27-abe8-4b97-9475-918dfdfdb1f0</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Are you able to read and write from the chip at all? I can see that you enable the TWI, but have you &lt;em&gt;initiated&lt;/em&gt; it with the proper configuration somewhere? &lt;a href="https://github.com/Martinsbl/twi-find-devices-on-bus"&gt;Here&lt;/a&gt; is a simple example you can use to check your connections and to see how you configure the TWI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54146?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 14:57:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32caca19-5260-42a8-a9f2-f08cb403ad00</guid><dc:creator>piyush</dc:creator><description>&lt;p&gt;Hey Martin, thanks for the reply, I tried the way you suggested but it it shows random value. I have called the read function several times in main.c so that i can see the variation in the values there itself in watch1. the values change for the 1st function call but even after realigning the chip the value remains same. 1 more thing, i tried getting the device id instead of the accelerometer reading and it does not show the device address as well. So, i think there is a different problem. Thanks for helping :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accelerometer giving out random output</title><link>https://devzone.nordicsemi.com/thread/54145?ContentTypeID=1</link><pubDate>Mon, 30 May 2016 13:40:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6786443b-5c79-480c-9bb8-ed8875e73df3</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;When you read your X, Y, and Z values it looks like you read the Most Significant Byte (MSB) of the X-value first (at address 0x01). Hence your values are stored in rx_buffer like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;rx_buffer[0] = X value MSB
rx_buffer[1] = X value LSB
rx_buffer[2] = Y value MSB
rx_buffer[3] = Y value LSB
rx_buffer[4] = Z value MSB
rx_buffer[5] = Z value LSB
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So when you write&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*x_value = (rx_buffer[1]&amp;lt;&amp;lt;8)|rx_buffer[0];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You shift the &lt;em&gt;least&lt;/em&gt; significant byte 8 bits to the left. Try to write this instead:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*x_value = (rx_buffer[0]&amp;lt;&amp;lt;8)|rx_buffer[1];
*y_value = (rx_buffer[2]&amp;lt;&amp;lt;8)|rx_buffer[3];
*z_value = (rx_buffer[4]&amp;lt;&amp;lt;8)|rx_buffer[5];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;Also it seems like you have a bug in &lt;code&gt;mma8653_xyz_read()&lt;/code&gt;. &lt;code&gt;uint16_t * x_value&lt;/code&gt; should be &lt;code&gt;int16_t * x_value&lt;/code&gt;. I.e. use signed integers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>