Home
Forums
New posts
Search forums
What's new
New posts
Latest activity
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
All Topics
Language & Culture
SpresenseとIIS3DWBでの通信ができません
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="OrangeJuice" data-source="post: 739937"><p>Spresense+Spresense拡張ボードの環境でIIS3DWBの加速度センサを利用したいと考えています.</p><p>事前にArduinoでは動作確認済みのコードを使って,Spresenseで動作させようとしたところ「IIS3DWB not functioning!」と出て,getChipID関数で正しくデバイスのIDが取得できません.</p><p>ソースコードを添付しますので,何かお気づきの点があればご助言いただきたいです.</p><p></p><p>なお,拡張ボードの電圧設定は5V,IIS3DWBとSpresenseの結線は以下の通りです.</p><p></p><table style='width: 100%'><tr><th>Spresense</th><th>IIS3DWB</th></tr><tr><td>3.3V</td><td>3.3V</td></tr><tr><td>SPI CS(D10)</td><td>SS</td></tr><tr><td>SPI MOSI(D11)</td><td>MOSI</td></tr><tr><td>SPI MISO(D12)</td><td>MISO</td></tr><tr><td>SPI SCK(D13)</td><td>SCK</td></tr><tr><td>GND</td><td>GND</td></tr></table><p></p><p>[CODE] #include <IIS3DWB.h></p><p> #include "SPI.h"</p><p></p><p> #define SerialDebug true // set to true to get Serial output for debugging</p><p> #define CSPIN 10</p><p></p><p> /* Specify sensor parameters (sample rate is same as the bandwidth 6.3 kHz by default)</p><p> * choices are: AFS_2G, AFS_4G, AFS_8G, AFS_16G </p><p> */ </p><p> uint8_t Ascale = AFS_4G;</p><p> </p><p> float aRes; // scale resolutions per LSB for the accel </p><p> float accelBias[3] = {0.0f, 0.0f, 0.0f}; // offset biases for the accel </p><p> int16_t IIS3DWBData[4] = {0}; // Stores the 16-bit signed sensor output</p><p> float ax, ay, az, accelTemp; // variables to hold latest accel data values </p><p> uint8_t IIS3DWBstatus;</p><p> </p><p> volatile bool IIS3DWB_DataReady = true, IIS3DWB_Wakeup = true;</p><p></p><p> IIS3DWB IIS3DWB(CSPIN); // instantiate IIS3DWB class</p><p></p><p> void setup() </p><p> {</p><p> Serial.begin(115200);</p><p> delay(4000);</p><p> </p><p> SPI.begin(); // Start SPI serial peripheral</p><p> Serial.print("SPI Start!\n");</p><p> </p><p> // Configure SPI ship select for sensor breakout</p><p> pinMode(CSPIN, OUTPUT);</p><p> digitalWrite(CSPIN, HIGH); // disable SPI at start</p><p> </p><p> // Read the IIS3DWB Chip ID register, this is a good test of communication</p><p> Serial.println("IIS3DWB accel...");</p><p> uint8_t c = IIS3DWB.getChipID(); // Read CHIP_ID register for IIS3DWB</p><p> Serial.print("IIS3DWB "); Serial.print("I AM "); Serial.print(c, HEX); Serial.print(" I should be "); Serial.println(0x7B, HEX);</p><p> Serial.println(" ");</p><p> </p><p> if(c == 0x7B) // check if all SPI sensors have acknowledged</p><p> {</p><p> Serial.println("IIS3DWB is online..."); </p><p> Serial.println(" ");</p><p> </p><p> // reset IIS3DWB to start fresh</p><p> IIS3DWB.reset();</p><p></p><p> // get accel sensor resolution, only need to do this once</p><p> aRes = IIS3DWB.getAres(Ascale);</p><p> </p><p> IIS3DWB.selfTest();</p><p> </p><p> IIS3DWB.init(Ascale); // configure IIS3DWB </p><p></p><p> IIS3DWB.offsetBias(accelBias);</p><p> Serial.println("accel biases (mg)"); Serial.println(1000.0f * accelBias[0]); Serial.println(1000.0f * accelBias[1]); Serial.println(1000.0f * accelBias[2]);</p><p> Serial.println(" ");</p><p> delay(1000); </p><p> </p><p> }</p><p> else </p><p> {</p><p> if(c != 0x6A) Serial.println(" IIS3DWB not functioning!"); </p><p> while(1){};</p><p> }</p><p> </p><p> }</p><p> /* End of setup */</p><p></p><p> void loop() {</p><p> </p><p> if(IIS3DWB_DataReady) // Handle data ready condition</p><p> {</p><p> IIS3DWBstatus = IIS3DWB.DRstatus(); // read data ready status</p><p> if (IIS3DWBstatus & 0x01) { // if new accel data is available, read it</p><p> IIS3DWB.readAccelData(IIS3DWBData); </p><p> // Now we'll calculate the accleration value into actual g's</p><p> ax = (float)IIS3DWBData[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set</p><p> ay = (float)IIS3DWBData[1]*aRes - accelBias[1]; </p><p> az = (float)IIS3DWBData[2]*aRes - accelBias[2]; </p><p> }</p><p> } // end of data ready interrupt handlin</p><p></p><p> // end sensor interrupt handling</p><p> </p><p> if(SerialDebug) { // report latest accel data</p><p> Serial.print("ax = "); Serial.print((int)1000*ax); </p><p> Serial.print(" ay = "); Serial.print((int)1000*ay); </p><p> Serial.print(" az = "); Serial.print((int)1000*az); Serial.println(" mg");</p><p> }</p><p></p><p> IIS3DWBData[3] = IIS3DWB.readTempData(); // get IIS3DWB chip temperature</p><p> accelTemp = ((float) IIS3DWBData[3]) / 256.0f + 25.0f; // Accel chip temperature in degrees Centigrade</p><p> // Print temperature in degrees Centigrade </p><p> if(SerialDebug) {</p><p> Serial.print("IIS3DWB temperature is "); Serial.print(accelTemp, 1); Serial.println(" degrees C"); // Print T values to tenths of a degree C</p><p> }</p><p></p><p> }</p><p> /* End of main loop */</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="OrangeJuice, post: 739937"] Spresense+Spresense拡張ボードの環境でIIS3DWBの加速度センサを利用したいと考えています. 事前にArduinoでは動作確認済みのコードを使って,Spresenseで動作させようとしたところ「IIS3DWB not functioning!」と出て,getChipID関数で正しくデバイスのIDが取得できません. ソースコードを添付しますので,何かお気づきの点があればご助言いただきたいです. なお,拡張ボードの電圧設定は5V,IIS3DWBとSpresenseの結線は以下の通りです. [TABLE] [TR] [TH]Spresense[/TH] [TH]IIS3DWB[/TH] [/TR] [TR] [TD]3.3V[/TD] [TD]3.3V[/TD] [/TR] [TR] [TD]SPI CS(D10)[/TD] [TD]SS[/TD] [/TR] [TR] [TD]SPI MOSI(D11)[/TD] [TD]MOSI[/TD] [/TR] [TR] [TD]SPI MISO(D12)[/TD] [TD]MISO[/TD] [/TR] [TR] [TD]SPI SCK(D13)[/TD] [TD]SCK[/TD] [/TR] [TR] [TD]GND[/TD] [TD]GND[/TD] [/TR] [/TABLE] [CODE] #include <IIS3DWB.h> #include "SPI.h" #define SerialDebug true // set to true to get Serial output for debugging #define CSPIN 10 /* Specify sensor parameters (sample rate is same as the bandwidth 6.3 kHz by default) * choices are: AFS_2G, AFS_4G, AFS_8G, AFS_16G */ uint8_t Ascale = AFS_4G; float aRes; // scale resolutions per LSB for the accel float accelBias[3] = {0.0f, 0.0f, 0.0f}; // offset biases for the accel int16_t IIS3DWBData[4] = {0}; // Stores the 16-bit signed sensor output float ax, ay, az, accelTemp; // variables to hold latest accel data values uint8_t IIS3DWBstatus; volatile bool IIS3DWB_DataReady = true, IIS3DWB_Wakeup = true; IIS3DWB IIS3DWB(CSPIN); // instantiate IIS3DWB class void setup() { Serial.begin(115200); delay(4000); SPI.begin(); // Start SPI serial peripheral Serial.print("SPI Start!\n"); // Configure SPI ship select for sensor breakout pinMode(CSPIN, OUTPUT); digitalWrite(CSPIN, HIGH); // disable SPI at start // Read the IIS3DWB Chip ID register, this is a good test of communication Serial.println("IIS3DWB accel..."); uint8_t c = IIS3DWB.getChipID(); // Read CHIP_ID register for IIS3DWB Serial.print("IIS3DWB "); Serial.print("I AM "); Serial.print(c, HEX); Serial.print(" I should be "); Serial.println(0x7B, HEX); Serial.println(" "); if(c == 0x7B) // check if all SPI sensors have acknowledged { Serial.println("IIS3DWB is online..."); Serial.println(" "); // reset IIS3DWB to start fresh IIS3DWB.reset(); // get accel sensor resolution, only need to do this once aRes = IIS3DWB.getAres(Ascale); IIS3DWB.selfTest(); IIS3DWB.init(Ascale); // configure IIS3DWB IIS3DWB.offsetBias(accelBias); Serial.println("accel biases (mg)"); Serial.println(1000.0f * accelBias[0]); Serial.println(1000.0f * accelBias[1]); Serial.println(1000.0f * accelBias[2]); Serial.println(" "); delay(1000); } else { if(c != 0x6A) Serial.println(" IIS3DWB not functioning!"); while(1){}; } } /* End of setup */ void loop() { if(IIS3DWB_DataReady) // Handle data ready condition { IIS3DWBstatus = IIS3DWB.DRstatus(); // read data ready status if (IIS3DWBstatus & 0x01) { // if new accel data is available, read it IIS3DWB.readAccelData(IIS3DWBData); // Now we'll calculate the accleration value into actual g's ax = (float)IIS3DWBData[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set ay = (float)IIS3DWBData[1]*aRes - accelBias[1]; az = (float)IIS3DWBData[2]*aRes - accelBias[2]; } } // end of data ready interrupt handlin // end sensor interrupt handling if(SerialDebug) { // report latest accel data Serial.print("ax = "); Serial.print((int)1000*ax); Serial.print(" ay = "); Serial.print((int)1000*ay); Serial.print(" az = "); Serial.print((int)1000*az); Serial.println(" mg"); } IIS3DWBData[3] = IIS3DWB.readTempData(); // get IIS3DWB chip temperature accelTemp = ((float) IIS3DWBData[3]) / 256.0f + 25.0f; // Accel chip temperature in degrees Centigrade // Print temperature in degrees Centigrade if(SerialDebug) { Serial.print("IIS3DWB temperature is "); Serial.print(accelTemp, 1); Serial.println(" degrees C"); // Print T values to tenths of a degree C } } /* End of main loop */ [/CODE] [/QUOTE]
Name
Verification
Post reply
Home
Forums
All Topics
Language & Culture
SpresenseとIIS3DWBでの通信ができません
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top