<?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>nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29850/nrf52840-mpu9250-magnetometer-reading</link><description>Hello, I am using nrf52840 PDK, sdk 13.0.0. I managed to read accel, gyro data from the MPU9250 using MPU library based on this example . However, I got magnetometer reading 0. I&amp;#39;ve checked this question and this question .
Here is the code how I setup</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Feb 2018 08:40:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29850/nrf52840-mpu9250-magnetometer-reading" /><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/120936?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 08:40:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36055c8d-0496-4916-bccb-12183973031f</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Yes. Why do you need to call it twice? Unless you need two sepparate TWI busses, then you only need one instance. You can pass a pointer to this instance to your various C files which is usually how it is done in our SDK drivers.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/120851?ContentTypeID=1</link><pubDate>Wed, 14 Feb 2018 14:13:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5a81f9c-7d89-400e-ab4a-e1b10b145641</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;I wrote another c file including an h file, the function above is defined in there. But when I call this function in the main, the&amp;nbsp;program gets stuck and the code after the calling doesn&amp;#39;t execute. I called&amp;nbsp;NRF_DRV_TWI_INSTANCE(0) to create a twi instance in my&amp;nbsp;c file, as&amp;nbsp;I kept your&amp;nbsp;twi instance at the same time. Will having two same twi instances cause the error?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/120777?ContentTypeID=1</link><pubDate>Wed, 14 Feb 2018 07:40:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07484438-a251-4f90-b937-fd96e8684dae</guid><dc:creator>MartinBL</dc:creator><description>[quote user="qszxluyu"]it seems cannot be executed properly, [/quote]
&lt;p&gt;So what happens exactly?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/120770?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2018 22:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b886607-349f-49e3-a856-d5c38ddd33dd</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;Hello Martin, I&amp;#39;ve solved this problem, the code is correct, the error is caused by the design flaw of the MPU evaluation board. But I met another problem, I tried to modify your mpu_read_register function, but it seems cannot be executed properly, here is the function, could you pls have a look?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t mpu_twi_read(uint8_t slave_addr,uint8_t reg_addr,uint32_t length,uint8_t *data)
{
	  uint32_t err_code;
		uint32_t timeout = MPU_TWI_TIMEOUT;
	
	  err_code = nrf_drv_twi_tx(&amp;amp;m_twi_instance, slave_addr, &amp;amp;reg_addr, 1, false);
		if(err_code != NRF_SUCCESS) return err_code;

    while((!twi_tx_done) &amp;amp;&amp;amp; --timeout);
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_tx_done = false;	
	
	  err_code = nrf_drv_twi_rx(&amp;amp;m_twi_instance, slave_addr, data, length);
    if(err_code != NRF_SUCCESS) return err_code;
		
		timeout = MPU_TWI_TIMEOUT;
    while((!twi_rx_done) &amp;amp;&amp;amp; --timeout);
    if(!timeout) return NRF_ERROR_TIMEOUT;
    twi_rx_done = false;
	
		return err_code;
};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118641?ContentTypeID=1</link><pubDate>Wed, 31 Jan 2018 14:02:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ee690ef-e161-421c-a731-30772dbec4dd</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;Sorry for the typo, &amp;#39;goes wrong&amp;#39; I mean.  Thank you anyway.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118642?ContentTypeID=1</link><pubDate>Wed, 31 Jan 2018 12:22:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bf0e77c-557a-4579-ae73-3a2a33ef112c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;What do you mean by &amp;quot;the magnetometer goes on my MPU9250&amp;quot;? I don&amp;#39;t know if it is broken. At least it is responding and not completely dead. I tested with &lt;a href="https://www.ebay.com/itm/9-Axis-MPU-9250-Attitude-Module-Accelerator-Magnetometer-replace-for-MPU-9150-/271910672852"&gt;one of these&lt;/a&gt;, by the way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118643?ContentTypeID=1</link><pubDate>Wed, 31 Jan 2018 04:18:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d28c3ed3-e303-45fd-8484-8cb8394065e5</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;Hello, sorry for delayed reply. Thank you for testing my code, I checked my code those days and I still got reading 0. If my code works on your device, is it reasonable for me to get the conclusion that the magnetometer goes on my MPU9250 in your opinion?  Thank you very much for your time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118637?ContentTypeID=1</link><pubDate>Thu, 25 Jan 2018 08:49:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1542e6b-c8a5-4f71-b185-c7161906765a</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I pulled your code and it shows me this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2806.Untitled.png" alt="asdf" /&gt;&lt;/p&gt;
&lt;p&gt;Seems to work fine. I haven&amp;#39;t tested whether the values are good though, but at least they are not 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118640?ContentTypeID=1</link><pubDate>Tue, 23 Jan 2018 13:55:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9a01cfe-104d-427e-a2b3-ba2751e16c0a</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;Hello, I&amp;#39;ve tried single mode measurement as well as the two continuous measurements, I&amp;#39;ve updated my code to include a reading from measurement data register, but the reading is still 0. I also posted this question on Invensense web.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118639?ContentTypeID=1</link><pubDate>Tue, 23 Jan 2018 11:11:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d6d4d58-6f2d-4bdb-816e-5e4d58b57f16</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;If you write &amp;#39;1&amp;#39; to the control register (CNTL1 at 0x0A) you start a single magnetometer measurement. It could be that you start the measurement, but read the data before the measurement is completed. When I put in a 5ms delay between starting a single mode measurement and reading the data it worked fine (with an MPU 9150 though). If you write &amp;#39;6&amp;#39; to the register instead you will start continuous measurements.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118638?ContentTypeID=1</link><pubDate>Mon, 22 Jan 2018 20:12:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7e27578-c114-4231-85e3-dc7cabf1cd9a</guid><dc:creator>YooLoo</dc:creator><description>&lt;p&gt;Hello,
Thank you for your reply! I followed your advice and edited my code. However, the reading of magnetometer is still 0. I&amp;#39;ve used nrf_drv_mpu_read_magnetometer_registers to check the value of 0x00 device id and 0x0A CNTL, and everything seems fine. What else might go wrong?
I&amp;#39;ve updated the question to include my result observed from Termite.
My project files can be found in &lt;a href="https://github.com/qszxluyu/FYP_workspace/tree/debug_magn"&gt;this branch&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52840 MPU9250 Magnetometer Reading</title><link>https://devzone.nordicsemi.com/thread/118636?ContentTypeID=1</link><pubDate>Mon, 22 Jan 2018 14:29:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a0cd40f-52d9-4d41-8e29-1c1850c523a9</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It seems like I forgot to add functions for actually starting the magnetometer. Please refer to the &lt;a href="https://cdn.sparkfun.com/assets/learn_tutorials/5/5/0/MPU-9250-Register-Map.pdf"&gt;MPU 9250 register map&lt;/a&gt; and look at Chapter 5.8, CNTL1: Control 1. Write e.g. 6 to this register to start continuous measurement.&lt;/p&gt;
&lt;p&gt;A quick and dirty way to do it is to include nrf_drv_mpu.h in main.c and call nrf_drv_mpu_write_magnetometer_register(0x0A, 6) when you initialize your MPU.&lt;/p&gt;
&lt;p&gt;Note to MPU 9150 users: There is no continuous mode on the MPU 9150 so a single measurement has to be started before every read. Note that it seems like it takes ~5ms from the measurement is started until valid data is ready to be read.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>