<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis MicrocontrollersのトピックRe: SD card write function affect the sensor datas in KL25Z</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379636#M20152</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for ur wonderful help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Jan 2015 11:45:44 GMT</pubDate>
    <dc:creator>deepir</dc:creator>
    <dc:date>2015-01-05T11:45:44Z</dc:date>
    <item>
      <title>SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379631#M20147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;SD card data write affect the sensor read:&lt;/STRONG&gt;&amp;nbsp; In my program i used one accelerometer(MMA8451Q) , Magnetometer(FXOS8700Q), gyroscope sensor(FXAS21000) and KL25Z, I read all the datas from sensors perfectly, Now i try to store the datas in sd card, In that time i use fopen function, that time sensor datas are not read correctly(Gyroscope and magnetometer In that time also Accelerometer read correct value), please help me, In my project i used FRDM-KL25Z and FRDM-FXS-MULTI-Rev C.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I insert the code below &lt;/P&gt;&lt;OL&gt;&lt;LI&gt;include "mbed.h" &lt;/LI&gt;&lt;LI&gt;include "MMA8451Q.h" &lt;/LI&gt;&lt;LI&gt;include "FXAS21000.h" &lt;/LI&gt;&lt;LI&gt;include "FXOS8700Q.h" &lt;/LI&gt;&lt;LI&gt;include "SDFileSystem.h" &lt;/LI&gt;&lt;/OL&gt;&lt;OL&gt;&lt;LI&gt;if&amp;nbsp; &lt;SPAN class="d50mvhbdp9"&gt;defined&lt;/SPAN&gt; (TARGET_KL25Z) || defined (TARGET_KL46Z) PinName const SDA = PTE25; PinName const SCL = PTE24; &lt;/LI&gt;&lt;LI&gt;elif defined (TARGET_KL05Z) PinName const SDA = PTB4; PinName const SCL = PTB3; &lt;/LI&gt;&lt;LI&gt;elif defined (TARGET_K20D50M) PinName const SDA = PTB1; PinName const SCL = PTB0; &lt;/LI&gt;&lt;LI&gt;else &lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="d50mvhbdp9"&gt;error&lt;/SPAN&gt; TARGET NOT DEFINED &lt;/LI&gt;&lt;LI&gt;endif &lt;/LI&gt;&lt;/OL&gt;&lt;OL&gt;&lt;LI&gt;define MMA8451_I2C_ADDRESS (0x1d&amp;lt;&amp;lt;1) &lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;FXOS8700Q_mag mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); &lt;EM&gt; Proper Ports and I2C address for Freescale Multi Axis &lt;SPAN class="d50mvhbdp9"&gt;shield&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;MotionSensorDataUnits mag_data;&lt;/P&gt;&lt;P&gt;MotionSensorDataCounts mag_raw;&lt;/P&gt;&lt;P&gt;FXAS21000 gyro( A4, A5); Serial pc(USBTX, USBRX);&lt;/P&gt;&lt;P&gt;SDFileSystem sd(D11, D12, D13, A2, "sd"); &lt;EM&gt; MOSI, MISO, SCK, CS FILE *fp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;int main(void) { float gyro_data[3]; float x, y, z; int i; pc.baud(115200);&lt;/P&gt;&lt;P&gt;&amp;nbsp; MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); mag.enable(); printf("MMA8451 ID: %d\n", acc.getWhoAmI());&lt;/P&gt;&lt;P&gt;&amp;nbsp; fp = fopen("/sd/straightLine_CalInertialAndMag.csv", "r"); remove("/sd/straightLine_CalInertialAndMag.csv"); &lt;EM&gt;&amp;nbsp; fp = fopen("/sd/straightLine_CalInertialAndMag.csv", "a"); &lt;/EM&gt;&amp;nbsp; fprintf(fp,"Packet number,Gyroscope X (deg/s),Gyroscope Y (deg/s),Gyroscope Z (deg/s),Accelerometer X (g),Accelerometer Y (g),Accelerometer Z (g),Magnetometer X (G),Magnetometer Y (G),Magnetometer Z (G)\n\r"); &lt;EM&gt; fclose(fp); for(i=0;i&amp;lt;250;i++) { fp = fopen("/sd/straightLine_CalInertialAndMag1.csv", "a"); fprintf(fp,"%4.2f,%4.2f,%4.2f,%1.2f,%1.2f,%1.2f,%4.1f,%4.1f,%4.1f,\n\r",gyro_data[0], gyro_data[1], gyro_data[2],x,y,z,mag_data.x, mag_data.y, mag_data.z); fclose(fp);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; x = abs(acc.getAccX()); y = abs(acc.getAccY()); z = abs(acc.getAccZ());&lt;/P&gt;&lt;P&gt;&amp;nbsp; gyro.ReadXYZ(gyro_data);&lt;/P&gt;&lt;P&gt;&amp;nbsp; mag.getAxis(mag_data); wait(0.2);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;EM&gt; if (fp == NULL) &lt;/EM&gt; { &lt;EM&gt; pc.printf("Unable to write the file\r\n"); &lt;/EM&gt;} &lt;EM&gt; else &lt;/EM&gt; { &lt;EM&gt; &lt;/EM&gt; fclose(fp);&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;EM&gt;} printf("%1.2f,%1.2f,%1.2f,%4.2f,%4.2f,%4.2f,%4.1f,%4.1f,%4.1f,\n\r", x,y,z,gyro_data[0],gyro_data[1],gyro_data[2],mag_data.x,mag_data.y,mag_data.z); wait(0.1);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; } }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Oct 2014 09:23:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379631#M20147</guid>
      <dc:creator>deepir</dc:creator>
      <dc:date>2014-10-09T09:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379632#M20148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepi R，&lt;/P&gt;&lt;P&gt;I've reviewed your question and let me make your question clearly.&lt;/P&gt;&lt;P&gt;The demo read the these sensor values well, the SD operation also works well by itself. On other hand, it can't read correct sensor value when they work together.&lt;/P&gt;&lt;P&gt;I think you must use the SPI interface to operate the SD card, so I want to know whether the SPI interface also share with the sensors or not.&lt;/P&gt;&lt;P&gt;And I'd like to suggest that you can try this method that after you had read all sensor values successful, then create a file in SD card.&lt;/P&gt;&lt;P&gt;Hope this reply help.&lt;BR /&gt;Have a great day,&lt;BR /&gt;(my name)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Oct 2014 08:57:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379632#M20148</guid>
      <dc:creator>jeremyzhou</dc:creator>
      <dc:date>2014-10-14T08:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379633#M20149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have few questions, I hope answering these ques will help you to resolve the issues faster&lt;/P&gt;&lt;P&gt;1. At what rate you are extracting the data from sensor?&lt;/P&gt;&lt;P&gt;2. Are all the sensors sharing the I2c/SPI bus?&lt;/P&gt;&lt;P&gt;3. Are you creating and closing the file each time writing the data?&lt;/P&gt;&lt;P&gt;4. Data being stored is int or float ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Jan 2015 04:30:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379633#M20149</guid>
      <dc:creator>Amit_Kumar1</dc:creator>
      <dc:date>2015-01-01T04:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379634#M20150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1.I am using the data rate at 100khz.&lt;/P&gt;&lt;P&gt;2.All sensors sharing I2C&lt;/P&gt;&lt;P&gt;3.Yes&lt;/P&gt;&lt;P&gt;4.Float&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Jan 2015 06:09:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379634#M20150</guid>
      <dc:creator>deepir</dc:creator>
      <dc:date>2015-01-02T06:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379635#M20151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on your inputs, There are few suggestions from my side,&lt;/P&gt;&lt;P&gt;1. FXOS8700CQ can be used for extracting accelerometer + magnetometer data. As the no. of devices increases on I2C bus , there are chances of Bus faults. If you use a combined sensor then the data coming out will be much synchronized. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.If you look at page 47 of Datasheet of FXAS21000 Gyro&amp;nbsp; ERRATA A.1. There it is mentioned that It needs to be connected to a dedicated I2C bus (Without sharing with other sensors as it will give erroneous data) which in your case is happening. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Workaround:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect it to different I2C /SPI without sharing line with any other devices.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. If you are using FATFs while each time closing/opening files takes around 2-3 milliseconds which makes the program to hang for that duration. Due to this you will miss some entries. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; workaround:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; use fopen at the beginning of the program and fclose at the end , each time after fwrite, use "f_lseek" ,which will take less time. Or you can buffer the readings and use f_lseek at some regular time intervals so that data is not lost if accidentally the card is removed/ power failure. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. If using FATFs , It is clearly mentioned that it doesn't support floating point data write &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; workaround:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; use sprintf and convert floating point to string and print it as a string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I faced some of these issues and this is how I resolved.&lt;/P&gt;&lt;P&gt;Hope It Helps!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 07:17:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379635#M20151</guid>
      <dc:creator>Amit_Kumar1</dc:creator>
      <dc:date>2015-01-05T07:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: SD card write function affect the sensor datas in KL25Z</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379636#M20152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for ur wonderful help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 11:45:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/SD-card-write-function-affect-the-sensor-datas-in-KL25Z/m-p/379636#M20152</guid>
      <dc:creator>deepir</dc:creator>
      <dc:date>2015-01-05T11:45:44Z</dc:date>
    </item>
  </channel>
</rss>

