如何将 Arduino 库与第二个 Sercom/第二个 I2c 总线一起使用

问题描述 投票:0回答:1

我正准备因为没有适当地谷歌搜索而被排斥,但在过去的一天半里我一直在寻找解决方案,尝试了几十种方法,但没有任何效果。我正在尝试将设备 (Adafruit ADS1115) 从共享我的多个设备的标准 I2C 总线移至其自己的 I2C 总线上。原因是 ADS1115 似乎导致总线上的其他所有设备停止响应。我已经浏览了库文件寻找要更改的配置,但似乎没有什么区别。我尝试了“非阻塞”示例代码,但它也不适合我。我正在使用 freeRTOS,因为我迫切需要线程,并且我认为非阻塞代码可能因此无法正常工作。我认为使用单独的 I2C 端口可能会解决这个问题,但我一辈子都不知道该怎么做。那里有一堆本质上相同的示例,但它们只展示了如何使用电线库创建端口,但 Adafruit 库似乎是上面的一层?如果有人可以向我展示如何修改“非阻塞”示例代码以使用一组不同的引脚,我将非常感激。我正在使用 Adafruit grandcentral m4 并且想要在引脚 25 和 24 上使用 SDA1 和 SCL1。 好的,明白了。我以为我已经读到您可以使用任何 Sercom 并假设我的格式中的某些内容不正确。您

不能
arduino i2c
1个回答
0
投票
引脚图

上找到了对 sercom6 的引用 这是可供参考的工作代码: #include <Adafruit_ADS1X15.h> #include <Wire.h> #define pinSDA1 25 #define pinSCL1 24 Adafruit_ADS1115 ads; /* Use this for the 16-bit version */ //Adafruit_ADS1015 ads; /* Use this for the 12-bit version */ TwoWire I2cB(&sercom6, pinSDA1, pinSCL1); void setup(void) { Serial.begin(115200); delay(1000); Serial.println("Hello!"); Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)"); Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)"); // The ADC input range (or gain) can be changed via the following // functions, but be careful never to exceed VDD +0.3V max, or to // exceed the upper and lower limits if you adjust the input range! // Setting these values incorrectly may destroy your ADC! // ADS1015 ADS1115 // ------- ------- // ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default) // ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV // ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV if (!ads.begin(0x48, &I2cB)) { Serial.println("Failed to initialize ADS."); while (1); } // Start the first conversion. ads.startADCReading(MUX_BY_CHANNEL[0], /*continuous=*/false); } void loop(void){ // Serial.println("hello again"); // delay(1000); // return; // If we don't have new data, skip this iteration. if (!ads.conversionComplete()) { return; } int16_t results = ads.getLastConversionResults(); Serial.print("Differential: "); Serial.print(results); Serial.print("("); Serial.print(ads.computeVolts(results)); Serial.println("mV)"); // Start another conversion. ads.startADCReading(MUX_BY_CHANNEL[0], /*continuous=*/false); delay(1000); }

© www.soinside.com 2019 - 2024. All rights reserved.