Coder Social home page Coder Social logo

adafruit_busio's Introduction

Adafruit Bus IO Library Build Status

This is a helper library to abstract away I2C & SPI transactions and registers

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

MIT license, all text above must be included in any redistribution

adafruit_busio's People

Contributors

anhardt avatar caternuson avatar ebd232 avatar eringerli avatar evaherrada avatar hathach avatar hoffmannjan avatar howard-wa9axq avatar jeromelebel avatar kurte avatar ladyada avatar mcudude avatar mecparts avatar mirzafahad avatar monroewilliams avatar olaffilies avatar paintyourdragon avatar rgiese avatar rjoomen avatar robtillaart avatar siddacious avatar silabs-bozont avatar slav-at-attachix avatar solhuebner avatar spencekonde avatar stuthedew avatar tyeth avatar werecatf avatar wol avatar yilungao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_busio's Issues

Problem with Adafruit_AHTX0 #53

trying to use Adafruit_AHTX0

Hardware:
Mac OS 10.13
Arduino IDE 1.8
Board ESP32-C3-DevKitM-1

I'm trying to upload an example to use the AHT10 temperature sensor but I'm getting the following error:

/Users/firemedia1/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0-alpha1/cores/esp32/Arduino.h:107:66: note: suggested alternative: 'GPIO_IN_REG'
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
^~~~~~~~~~~~
/Users/firemedia1/Dropbox/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.cpp:58:33: note: in expansion of macro 'portInputRegister'
misoPort = (BusIO_PortReg *)portInputRegister(digitalPinToPort(misopin));
^~~~~~~~~~~~~~~~~

Arduino 101 SPI_BITORDER_MSBFIRST error

  • Arduino board: Arduino 101
  • Arduino IDE version: Arduino 1.6.9
  • List the steps to reproduce the problem below: Compiled basic_readings example from the Adafruit MPU6050 library.

I get two errors when I compile it:
..\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:37:43: error: could not convert 'SPI_BITORDER_MSBFIRST' from '_BitOrder' to 'BitOrder'

                  BitOrder dataOrder = SPI_BITORDER_MSBFIRST,

                                       ^

...\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:42:43: error: could not convert 'SPI_BITORDER_MSBFIRST' from '_BitOrder' to 'BitOrder'

                  BitOrder dataOrder = SPI_BITORDER_MSBFIRST,

Could you please fix this?

Thanks.

If NO_GLOBAL_INSTANCES or NO_GLOBAL_SERIAL is defined, not able to find Serial in Adafruit_BusIO_Register.h

  • Arduino board: ESP32 WROOM32 module

  • Arduino IDE version (found in Arduino -> About Arduino menu): Using VS Code with ESPIDF, CMake, Arduino as a submodule: espressif/arduino-esp32 v2.0.5

Compile with -DNO_GLOBAL_SERIAL. Causes HardwareSerial.h to not extern HardwareSerial Serial; which means that Adafruit_BusIO_Register.h #L74 tries to use &Serial as a default argument but it doesn't exist.

Solution would be to use the same define guard around the method declarations so if NO_GLOBAL_INSTANCES or NO_GLOBAL_SERIAL is defined, it will not add in a default argument.

Adafruit BusIO v1.11.1 breaks begin_SPI() on SAMD51 with BMP388

I updated a bunch of libraries from Adafruit and I discovered that opening the BMP388 barometric pressure sensor over SPI is failing. BusIO versions before v1.11.1 work fine.

Hardware

Software

  • Arduino IDE 1.8.19 (or 1.8.16)
  • https://github.com/adafruit/Adafruit_BMP3XX, using its example program 'bmp3xx_simpletest'
  • changed two lines for ChipSelect and begin_SPI(), see code sketch below
  • error message from sketch is "Could not find a valid BMP3 sensor, check wiring!"
  • have tested a few Griduino assemblies, this hardware design has worked well for a year and is unchanged

Some recent BusIO changes include the comment "there doesn't seem to be a supported #define that this code can use to tell which core it's building against." This topic might be relevant to my SAMD51 devices. I don't know what the fix should be. For some other things, I've used:

  • #if defined(SAMD_SERIES)
  • #if defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS)

Hope this helps.
Barry Hansen

Code from bmp3xx_simpletest

There are 2 changes for my wiring from Feather to BMP388. Look for "<---" markers.

/***************************************************************************
  This is a library for the BMP3XX temperature & pressure sensor

  Designed specifically to work with the Adafruit BMP388 Breakout
  ----> http://www.adafruit.com/products/3966

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 13     // <--- changed chip select

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Adafruit BMP388 / BMP390 test");

  if (! bmp.begin_SPI(BMP_CS)) {  // hardware SPI mode     <--- uncommented to use hardware SPI
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }

  // Set up oversampling and filter initialization
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}

void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.println();
  delay(2000);
}

Support for bit tranfers....

Is there a way to specify an arbitrary number of bits to transfer via SPI? I have a device that's interface is very SPI-like. But it expects 3bits of command followed by 6 bits of address followed by 8bits of data. But from the code here..(at least the bit banged part) it looks like it sends just 8 bit package.. My guess is I'll have to bit bang this myself...

I2C on different ports

In order to solve crowded projects where several sensors' I2C addresses overlap, it is possible to implement a bitbang transmission on different ports than the physical I2C (see e.g. library BitBang_I2C, which could be included as an extension). Please upgrade BusIO so as to enable all Adafruit sensor libraries to access this kind of communication protocol. This would allow connecting many sensors without collision and without physical multiplexers.

Compile error with max31855k

  • Arduino board: Arduino/Genuino 101

  • Arduino IDE version - 1.18.15

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): Open and upload serialthermocouple from "Adafruit MAX31855 library"
    It returns the following "Error compiling for board Arduino/Genuino 101"

Arduino: 1.8.15 (Mac OS X), Board: "Arduino/Genuino 101"

/Users/daniel/Library/Arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1/bin/arc-elf32-g++ -c -mcpu=quarkse_em -mlittle-endian -g -Os -Wall -fno-reorder-functions -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -fno-defer-pop -Wno-unused-but-set-variable -Wno-main -ffreestanding -fno-stack-protector -mno-sdata -ffunction-sections -fdata-sections -fsigned-char -fno-rtti -fno-exceptions -fcheck-new -D__ARDUINO_ARC__ -std=c++11 -DCONFIG_BLUETOOTH_PERIPHERAL -DCONFIG_BLUETOOTH_CENTRAL -DCONFIG_BLUETOOTH_GATT_CLIENT -w -x c++ -E -CC -DF_CPU=32000000L -DARDUINO=10815 -DARDUINO_ARC32_TOOLS -DARDUINO_ARCH_ARC32 -D__CPU_ARC__ -DCLOCK_SPEED=32 -DCONFIG_SOC_GPIO_32 -DCONFIG_SOC_GPIO_AON -DINFRA_MULTI_CPU_SUPPORT -DCFW_MULTI_CPU_SUPPORT -DHAS_SHARED_MEM -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/common -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/drivers -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/bootcode -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/framework/include -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/cores/arduino -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/variants/arduino_101 -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/SPI/src -I/Users/daniel/Documents/Arduino/libraries/Adafruit_MAX31855_library -I/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/Wire/src /var/folders/p4/vh0y2_vx4gx65lfycjnm2xt80000gn/T/arduino_build_436628/sketch/serialthermocouple.ino.cpp -o /var/folders/p4/vh0y2_vx4gx65lfycjnm2xt80000gn/T/arduino_build_436628/preproc/ctags_target_for_gcc_minus_e.cpp
/Applications/Arduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/p4/vh0y2_vx4gx65lfycjnm2xt80000gn/T/arduino_build_436628/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Users/daniel/Library/Arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1/bin/arc-elf32-g++ -c -mcpu=quarkse_em -mlittle-endian -g -Os -Wall -fno-reorder-functions -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -fno-defer-pop -Wno-unused-but-set-variable -Wno-main -ffreestanding -fno-stack-protector -mno-sdata -ffunction-sections -fdata-sections -fsigned-char -MMD -fno-rtti -fno-exceptions -fcheck-new -D__ARDUINO_ARC__ -std=c++11 -DCONFIG_BLUETOOTH_PERIPHERAL -DCONFIG_BLUETOOTH_CENTRAL -DCONFIG_BLUETOOTH_GATT_CLIENT -DF_CPU=32000000L -DARDUINO=10815 -DARDUINO_ARC32_TOOLS -DARDUINO_ARCH_ARC32 -D__CPU_ARC__ -DCLOCK_SPEED=32 -DCONFIG_SOC_GPIO_32 -DCONFIG_SOC_GPIO_AON -DINFRA_MULTI_CPU_SUPPORT -DCFW_MULTI_CPU_SUPPORT -DHAS_SHARED_MEM -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/common -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/drivers -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/bootcode -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/system/libarc32_arduino101/framework/include -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/cores/arduino -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/variants/arduino_101 -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/SPI/src -I/Users/daniel/Documents/Arduino/libraries/Adafruit_MAX31855_library -I/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO -I/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/Wire/src /var/folders/p4/vh0y2_vx4gx65lfycjnm2xt80000gn/T/arduino_build_436628/sketch/serialthermocouple.ino.cpp -o /var/folders/p4/vh0y2_vx4gx65lfycjnm2xt80000gn/T/arduino_build_436628/sketch/serialthermocouple.ino.cpp.o
In file included from /Users/daniel/Documents/Arduino/libraries/Adafruit_MAX31855_library/examples/serialthermocouple/serialthermocouple.ino:17:0:
/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/SPI/src/SPI.h:47:18: error: invalid conversion from โ€˜intโ€™ to โ€˜BitOrderโ€™ [-fpermissive]
#define MSBFIRST 1
^
/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h:31:31: note: in expansion of macro โ€˜MSBFIRSTโ€™
#define SPI_BITORDER_MSBFIRST MSBFIRST
^
/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h:62:43: note: in expansion of macro โ€˜SPI_BITORDER_MSBFIRSTโ€™
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^
/Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/SPI/src/SPI.h:47:18: error: invalid conversion from โ€˜intโ€™ to โ€˜BitOrderโ€™ [-fpermissive]
#define MSBFIRST 1
^
/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h:31:31: note: in expansion of macro โ€˜MSBFIRSTโ€™
#define SPI_BITORDER_MSBFIRST MSBFIRST
^
/Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h:67:43: note: in expansion of macro โ€˜SPI_BITORDER_MSBFIRSTโ€™
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^
Using library SPI at version 1.0 in folder: /Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/SPI
Using library Adafruit_MAX31855_library at version 1.3.0 in folder: /Users/daniel/Documents/Arduino/libraries/Adafruit_MAX31855_library
Using library Adafruit_BusIO at version 1.8.1 in folder: /Users/daniel/Documents/Arduino/libraries/Adafruit_BusIO
Using library Wire at version 1.0 in folder: /Users/daniel/Library/Arduino15/packages/Intel/hardware/arc32/2.0.4/libraries/Wire
exit status 1
Error compiling for board Arduino/Genuino 101.

Define the meaning of 'type' for BusIO Registers

Not an issue but hopefully helpful input. I didn't know where best to put this info so am providing here. I struggled a bit over what "type" meant when defining a Adafruit_BusIO_Register and then it clicked once I saw the code. To assist future developers here is an attempt at a couple of definitions:

ADDRBIT8_HIGH_TOREAD When reading a register you must actually send the value 0x80 + register to the device. e.g. To read the register 0x0B the register value 0x8B is sent and to write 0x0B is sent.

ADDRBIT8_HIGH_TOWRITE When writing to a register you must actually send the value 0x80 + register to the device. e.g. To write to the register 0x19 the register value 0x99 is sent and to read 0x19 is sent.

Hope this helps. Also can the documentation be generated and included in the git repository?

Design intent question: Why malloc?

Hi I like the Adafruit_BusIO library for its almost zero-overhead abstraction of the I2C and the DAC chip MCP4725. As an embedded programmer of constrained hardware, I wonder why the library invokes the new operator in the code?

In other words, is there a strong reason not to modify the code like the following, in order to avoid malloc at run-time?

--- a/Adafruit_SPIDevice.cpp
+++ b/Adafruit_SPIDevice.cpp
@@ -19,7 +19,7 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, uint32_t freq,
   _sck = _mosi = _miso = -1;
   _spi = theSPI;
   _begun = false;
-  _spiSetting = new SPISettings(freq, dataOrder, dataMode);
+  _spiSetting = SPISettings(freq, dataOrder, dataMode);
   _freq = freq;
   _dataOrder = dataOrder;
   _dataMode = dataMode;
@@ -80,8 +80,6 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin,
  *    @brief  Release memory allocated in constructors
  */
 Adafruit_SPIDevice::~Adafruit_SPIDevice() {
-  if (_spiSetting)
-    delete _spiSetting;
 }
 
 /*!
@@ -283,7 +281,7 @@ uint8_t Adafruit_SPIDevice::transfer(uint8_t send) {
 void Adafruit_SPIDevice::beginTransaction(void) {
   if (_spi) {
 #ifdef BUSIO_HAS_HW_SPI
-    _spi->beginTransaction(*_spiSetting);
+    _spi->beginTransaction(_spiSetting);
 #endif
   }
 }

Issue with version 1.2.0

This library is used in Marlin 2.0 firmware for 3D printing, and since the changes made to Adafruit_MAX31865 yesterday from 1.1.0 to 1.2.0, the firmware no longer compiles. Here is a thread on the issue bigtreetech/BIGTREETECH-SKR-mini-E3#257

The firmware will compile with version 1.1.0.

Here is the output of the error which references the library
ompiling .pio\build\STM32F103RC_btt_512K\liba17\USBComposite\Consumer.cpp.o
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::read(uint8_t*, size_t, bool)':
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_I2CDevice.cpp:160:79: error: no matching function for call to 'TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)'
size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len, (uint8_t)stop);
^
In file included from C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/Wire.h:42:0,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_I2CDevice.h:1,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_I2CDevice.cpp:1:
C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate: uint8 WireBase::requestFrom(uint8, int)
uint8 requestFrom(uint8, int);
^~~~~~~~~~~
C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:101:11: note: candidate expects 2 arguments, 3 provided
C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate: uint8 WireBase::requestFrom(int, int)
uint8 requestFrom(int, int);
^~~~~~~~~~~
C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\libraries\Wire/utility/WireBase.h:106:11: note: candidate expects 2 arguments, 3 provided
*** [.pio\build\STM32F103RC_btt_512K\lib2ab\Adafruit BusIO_ID6214\Adafruit_I2CDevice.cpp.o] Error 1
In file included from .pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.h:55:0,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:17:
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
In file included from .pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:17:0:
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.h:84:32: warning: passing NULL to non-pointer argument 1 of 'Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t, uint32_t, BitOrder, uint8_t, SPIClass*)' [-Wconversion-null]
Adafruit_SPIDevice spi_dev = NULL;
^~~~
In file included from c:\users\lastp.platformio\packages\toolchain-gccarmnoneeabi\arm-none-eabi\include\inttypes.h:22:0,
from C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/avr/pgmspace.h:4,
from C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/WString.h:29,
from C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/wirish.h:47,
from C:\Users\lastp.platformio\packages\framework-arduinoststm32-maple\STM32F1\cores\maple/Arduino.h:30,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.h:50,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:17:
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.h:84:32: error: call to 'Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t, uint32_t, BitOrder, uint8_t, SPIClass*)' uses the default argument for parameter 3, which is not yet defined
Adafruit_SPIDevice spi_dev = NULL;
^
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp: In constructor 'Adafruit_MAX31865::Adafruit_MAX31865(int8_t, int8_t, int8_t, int8_t)':
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:38:76: error: call to 'Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t, int8_t, int8_t, int8_t, uint32_t, BitOrder, uint8_t)' uses the default argument for parameter 6, which is not yet defined
spi_dev = Adafruit_SPIDevice(spi_cs, spi_clk, spi_miso, spi_mosi, 1000000);
^
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp: In constructor 'Adafruit_MAX31865::Adafruit_MAX31865(int8_t)':
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:49:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
Adafruit_SPIDevice(spi_cs, 1000000, SPI_BITORDER_MSBFIRST, SPI_MODE1);
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit_MAX31865\Adafruit_MAX31865.cpp:49:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
Adafruit_SPIDevice(spi_cs, 1000000, SPI_BITORDER_MSBFIRST, SPI_MODE1);
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
*** [.pio\build\STM32F103RC_btt_512K\lib1cd\Adafruit_MAX31865\Adafruit_MAX31865.cpp.o] Error 1
In file included from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_BusIO_Register.h:2:0,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_BusIO_Register.cpp:1:
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
In file included from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:1:0:
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
*** [.pio\build\STM32F103RC_btt_512K\lib2ab\Adafruit BusIO_ID6214\Adafruit_BusIO_Register.cpp.o] Error 1
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:37:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:42:43: note: suggested alternative: 'SPI_CR1_LSBFIRST'
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp: In member function 'void Adafruit_SPIDevice::transfer(uint8_t*, size_t)':
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:99:31: error: no matching function for call to 'SPIClass::transfer(uint8_t*&, size_t&)'
_spi->transfer(buffer, len);
^
In file included from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214/Adafruit_SPIDevice.h:1:0,
from .pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:1:
Marlin\src\HAL\STM32F1/SPI.h:268:11: note: candidate: uint8_t SPIClass::transfer(uint8_t) const
uint8_t transfer(uint8_t data) const;
^~~~~~~~
Marlin\src\HAL\STM32F1/SPI.h:268:11: note: candidate expects 1 argument, 2 provided
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:115:23: error: 'SPI_BITORDER_LSBFIRST' was not declared in this scope
if (_dataOrder == SPI_BITORDER_LSBFIRST) {
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:115:23: note: suggested alternative: 'SPI_CR1_LSBFIRST'
if (_dataOrder == SPI_BITORDER_LSBFIRST) {
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:149:23: error: 'SPI_BITORDER_LSBFIRST' was not declared in this scope
if (_dataOrder == SPI_BITORDER_LSBFIRST) {
^~~~~~~~~~~~~~~~~~~~~
.pio\libdeps\STM32F103RC_btt_512K\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp:149:23: note: suggested alternative: 'SPI_CR1_LSBFIRST'
if (_dataOrder == SPI_BITORDER_LSBFIRST) {
^~~~~~~~~~~~~~~~~~~~~
SPI_CR1_LSBFIRST
*** [.pio\build\STM32F103RC_btt_512K\lib2ab\Adafruit BusIO_ID6214\Adafruit_SPIDevice.cpp.o] Error 1

Unable to communicate with LIS3DH on MagTag via I2C.

  • Arduino board: Adafruit MagTag 2.9"

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.15

  • arduino-esp32 2.0.0 RC-1 installed via the boards manager

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

Upload sketch, reboot and open Serial Monitor.

I believe the issue is being caused by the esp32 implementation of the TwoWire::endTransmission() function expecting the user to call Wire.write() prior to calling Wire.endTransmission()

uint8_t TwoWire::endTransmission(bool sendStop) // Assumes Wire.beginTransaction(), Wire.write()
https://github.com/espressif/arduino-esp32/blob/2af8cc34850c445b1b0694653f086b9f9b1f52f9/libraries/Wire/src/Wire.cpp#L171

Minimum Sketch to reproduce issue:

#include <Adafruit_LIS3DH.h>

Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup() {  
  Serial.begin(115200);
  while (!Serial);
  
  if (! lis.begin(0x19)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start LIS3DH");
    while (1) yield();
  }

  Serial.print("Range = "); Serial.print(2 << lis.getRange());
  Serial.println("G");
}

void loop() {
  // put your main code here, to run repeatedly:

}

image

This seems like an OK workaround:

Adding the following lines to the detected() function in Adafruit_I2CDevice.cpp

bool Adafruit_I2CDevice::detected(void) {
  // Init I2C if not done yet
  if (!_begun && !begin()) {
    return false;
  }

  // A basic scanner, see if it ACK's
  _wire->beginTransmission(_addr);

#ifdef ESP32 
  // ESP32 implementation of wire expects write before endTransmission
  _wire->write(0);
#endif

  if (_wire->endTransmission() == 0) {

image

Heltec CubeCell

Hi

Current versions of the INA219 fail to complie with the Heltec CubeCell HTCC-AB01.

V1.0.7 will complie V 1.0.9 on fails with the following issue:

In file included from .pio\libdeps\cubecell_board_plus\Adafruit BusIO/Adafruit_BusIO_Register.h:10,
                 from .pio\libdeps\cubecell_board_plus\Adafruit [email protected]/Adafruit_INA219.h:21,
                 from src\main.cpp:3:
.pio\libdeps\cubecell_board_plus\Adafruit BusIO/Adafruit_SPIDevice.h:39:9: error: 'BitOrder' does not name a type       
   39 | typedef BitOrder BusIOBitOrder;
      |         ^~~~~~~~
.pio\libdeps\cubecell_board_plus\Adafruit BusIO/Adafruit_SPIDevice.h:69:22: error: 'BusIOBitOrder' has not been declared
   69 |                      BusIOBitOrder dataOrder = SPI_BITORDER_MSBFIRST,
      |                      ^~~~~~~~~~~~~
.pio\libdeps\cubecell_board_plus\Adafruit BusIO/Adafruit_SPIDevice.h:74:22: error: 'BusIOBitOrder' has not been declared
   74 |                      BusIOBitOrder dataOrder = SPI_BITORDER_MSBFIRST,
      |                      ^~~~~~~~~~~~~
.pio\libdeps\cubecell_board_plus\Adafruit BusIO/Adafruit_SPIDevice.h:95:3: error: 'BusIOBitOrder' does not name a type
   95 |   BusIOBitOrder _dataOrder;
      |   ^~~~~~~~~~~~~

Is there a change log? What is the difference between 1.07 and 1.09 onwards and is there a fix?

Thanks

Missing spi.h with Adafruit BusIO 1.3..2 in ESPhome

Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:

  • Do not use GitHub issues for troubleshooting projects and issues. Instead use
    the forums at http://forums.adafruit.com to ask questions and troubleshoot why
    something isn't working as expected. In many cases the problem is a common issue
    that you will more quickly receive help from the forum community. GitHub issues
    are meant for known defects in the code. If you don't know if there is a defect
    in the code then start with troubleshooting on the forum first.

  • If following a tutorial or guide be sure you didn't miss a step. Carefully
    check all of the steps and commands to run have been followed. Consult the
    forum if you're unsure or have questions about steps in a guide/tutorial.

  • For Arduino projects check these very common issues to ensure they don't apply:

    • For uploading sketches or communicating with the board make sure you're using
      a USB data cable and not a USB charge-only cable. It is sometimes
      very hard to tell the difference between a data and charge cable! Try using the
      cable with other devices or swapping to another cable to confirm it is not
      the problem.

    • Be sure you are supplying adequate power to the board. Check the specs of
      your board and plug in an external power supply. In many cases just
      plugging a board into your computer is not enough to power it and other
      peripherals.

    • Double check all soldering joints and connections. Flakey connections
      cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.

    • Ensure you are using an official Arduino or Adafruit board. We can't
      guarantee a clone board will have the same functionality and work as expected
      with this code and don't support them.

If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:

  • Arduino board: ESP32 WROOM32

  • Arduino IDE version (found in Arduino -> About Arduino menu): platform: [email protected]

  • List the steps to reproduce the problem below :

Please find the error: https://pastebin.com/tmd26KJP

Compile error on my Arduino STM32 board, Adafruit-BMP085

stm32f103c8t6 board.
I get the following error when compiling the code https://github.com/adafruit/Adafruit-BMP085-Library/blob/master/examples/BMP085test/BMP085test.ino at Arduino_STM32.

Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::write(const uint8_t*, size_t, bool, const uint8_t*, size_t)':
C:\Users\rizacelik\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:88:47: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8* {aka unsigned char*}' [-fpermissive]
if (_wire->write(prefix_buffer, prefix_len) != prefix_len) {

Interrupts broken on the new attiny series since version 1.1.3

Interrupts broke on the new attiny series (testing on attiny1604) when you started using BusIO. Using the following core: https://github.com/SpenceKonde/megaTinyCore

First off if you try to compile it, you get the error:

Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:38:22: error: 'BitOrder' has not been declared

If you go in and remove the if statements, assuming it's an AVR board, it compiles but the interrupt pin is constantly held HIGH, never reacting to anything. It does this on all versions I've tried since then up to the latest arduino releases by today's date.

This sketch works as expected on 1.1.2, but for any version above it, the interrupt doesn't work:
https://gist.github.com/JasXSL/ed0f35498f64f8736e2fa730bde88b75

error: 'class TwoWire' has no member named 'end'

Our code stopped compiling today and broke our GitHub Actions workflow with the latest release. We are getting the following error:

.pio/libdeps/esp32dev/Adafruit BusIO@src-de43b9da31d281331630329764ceaa16/Adafruit_I2CDevice.cpp: In member function 'void Adafruit_I2CDevice::end()':
.pio/libdeps/esp32dev/Adafruit BusIO@src-de43b9da31d281331630329764ceaa16/Adafruit_I2CDevice.cpp:44:10: error: 'class TwoWire' has no member named 'end'
   _wire->end();

ESP32 with PlataformIO
platformio/espressif32 @ 3.4.0

Release 1.11.3 doesn't compile with Arduino 1.8.13

  • Arduino board: Adafruit ESP32 Feather

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.13

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

I just updated this library from Adafruit (among others) and found it does not compile in Arduino or in PlatformIO.
my project has #include <Adafruit_LEDBackpack.h> which depends on Adafruit_BusIO.

Downgrading Adafruit BusIO to 1.11.2 allows me to compile and run my project.

In case it's relevant, I'm also still using arduino-esp32 1.0.4.

I figured this would be adequate to locate the problem, but let me know if you want/need the verbose output. Here are the errors from the Arduino IDE console output:

C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp: In member function 'bool Adafruit_SPIDevice::write(const uint8_t*, size_t, const uint8_t*, size_t)':
C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:310:61: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(prefix_buffer, nullptr, prefix_len);
                                                             ^
In file included from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.h:9:0,
                 from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\chris\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^
C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:313:47: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(buffer, nullptr, len);
                                               ^
In file included from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.h:9:0,
                 from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\chris\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^
C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp: In member function 'bool Adafruit_SPIDevice::write_then_read(const uint8_t*, size_t, uint8_t*, size_t, uint8_t)':
C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:418:59: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(write_buffer, nullptr, write_len);
                                                           ^
In file included from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.h:9:0,
                 from C:\Users\chris\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\chris\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^

Side effect with hardware SPI causes pin 10 to be high after begin(), regardless of _cs value

  • Arduino board: Uno

  • Arduino IDE version (found in Arduino -> About Arduino menu): VS Code/PlatformIO

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): Call to _spi->begin() at Adafruit_SPIDevice.cpp:67 causes SS (pin 10) to be set HIGH in the arduino library, regardless of the value of _cs. I suggest storing the current pin mode and output state of pin 10 and restoring after the call.

Hang on arduino nano IOT device with Adafruit_MAX31855

  • Arduino board:
    Nano 33 IOT

  • Arduino IDE version (found in Arduino -> About Arduino menu):
    1.8.7

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

Using the Adafruit_MAX31855 sample code, serialthermocouple.ino, I was getting a hang trying to read the thermocouple.readInternal() value. On a different Arduino device (Mega ADK) it was working fine. With some debugging I found that I had to wrap the following digitalWrite to not get called if _mosi was -1 (which it is when using the Adafruit_MAX31855.cpp helper class) : https://github.com/adafruit/Adafruit_BusIO/blob/master/Adafruit_SPIDevice.cpp#L127

Refactor to better separate HW and SW SPI

Current code has a preproc check that will skip all of the code for boards that do not have a hardware SPI capability:

#if !defined(SPI_INTERFACES_COUNT) || \
(defined(SPI_INTERFACES_COUNT) && (SPI_INTERFACES_COUNT > 0))

This prevents using even BusIO's software SPI capability in those cases.

Further, there are numerous code segments in the nominal software parts that are relying on being able to import SPI.h. For example, the software constructor is using SPISettings:

_spiSetting = new SPISettings(freq, dataOrder, dataMode);

as well as SPIMode defs.

To better support software SPI only boards, would help to do a general refactor to better separate the HW/SW code.

Chunkify I2C?

Have recently run into several libraries that have created their own internal chunkification of I2C writes if the outbound buffer exceeds the max buffer size for the target platform. That buffer size information is being provided by this library, via maxBufferSize(). Would it make sense to implement chunkification here in this library?

Same question for reads, although the libraries cited above were not doing that.

Chip Select assert missing from SPIDevice::transfer?

Wanted to use transfer for update of MCP3008 library to BusIO to facilitate the basic readout as a 3 byte xfer:
image

Was not getting any change in readings. Scoped it up and it would not even trigger. Trigger is based on CS line going low. So...took a look..and not seeing anything that is asserting CS in the transfer code similar to what is done in write, read, and write_then_read. Am I missing something?

proposal for robustness for I2C setSpeed()

Triggered today by this warning

...Adafruit_BusIO\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::setSpeed(uint32_t)':
...Adafruit_BusIO\Adafruit_I2CDevice.cpp:267:11: warning: variable 'prescaler' set but not used [-Wunused-but-set-variable]
  uint8_t prescaler = 1; 

Code from Adafruit_I2CDevice.cpp 263++ (some comments are mine)

bool Adafruit_I2CDevice::setSpeed(uint32_t desiredclk) {
#if defined(__AVR_ATmega328__) ||                                              \
    defined(__AVR_ATmega328P__) // fix arduino core set clock
  // calculate TWBR correctly

  uint8_t prescaler = 1;     //   <<<<<<<<<<<< 1
  uint32_t atwbr = ((F_CPU / desiredclk) - 16) / 2;     //  <<<<<<<< 3
  if (atwbr <= 255) {
    prescaler = 1;
    TWSR = 0x0;
  } else if (atwbr <= 1020) {
    atwbr /= 4;
    prescaler = 4;
    TWSR = 0x1;
  } else if (atwbr <= 4080) {
    atwbr /= 16;
    prescaler = 16;
    TWSR = 0x2;
  } else if (atwbr <= 16320) {
    atwbr /= 64;
    prescaler = 64;
    TWSR = 0x3;
  }
 
  //  what if atwbr > 16320  ??   //  <<<<<<<<<<<< 2

#ifdef DEBUG_SERIAL
  Serial.print(F("TWSR prescaler = "));
  Serial.println(prescaler);
  Serial.print(F("TWBR = "));
  Serial.println(atwbr);
#endif
  TWBR = atwb
  return true;

There are some problems,

  1. a warning, that prescaler is not used. (MINOR)
  2. an error when atwbr > 16320, there is no error message. (CLOCK UNDERFLOW)
  3. an error when (F_CPU / desiredclk < 18 => TWBR could become 0 or "negative" (CLOCK OVERFLOW)

Possible rewrite to tackle the above.

bool Adafruit_I2CDevice::setSpeed(uint32_t desiredclk) {
#if defined(__AVR_ATmega328__) ||                                              \
    defined(__AVR_ATmega328P__) // fix arduino core set clock
  // calculate TWBR correctly

  if ((F_CPU / 18) < desiredclk) {
    //  Serial.println(F("I2C.setSpeed too high."));     //  or some error = I2C_SETSPEED_OVERFLOW;
    return false;
  }
  uint32_t atwbr = ((F_CPU / desiredclk) - 16) / 2;
  if (atwbr > 16320) {
    //  Serial.println(F("I2C.setSpeed too low."));    //  or some error = I2C_SETSPEED_UNDERFLOW;
    return false;
  }
  
  if (atwbr <= 255) {
    atwbr /= 1;
    TWSR = 0x0;
  } else if (atwbr <= 1020) {
    atwbr /= 4;
    TWSR = 0x1;
  } else if (atwbr <= 4080) {
    atwbr /= 16;
    TWSR = 0x2;
  } else {           //  if (atwbr <= 16320)
    atwbr /= 64;
    TWSR = 0x3;
  }
  TWBR = atwb;

#ifdef DEBUG_SERIAL
  Serial.print(F("TWSR prescaler = "));
  Serial.println(pow(4, TWSR));
  Serial.print(F("TWBR = "));
  Serial.println(atwbr);
#endif
  return true;

Add check for I2C pull ups?

Any way we could protect against nothing being connected to the bus? This currently leads to code locking up. Here's a simple example:

#include <Adafruit_I2CDevice.h>

#define ADDRESS 0x42

void setup() {
  Serial.begin(9600);
  while(!Serial);
  Serial.println("I2C TEST");

  Serial.println("Create.");
  Adafruit_I2CDevice *i2c_dev = new Adafruit_I2CDevice(ADDRESS, &Wire);

  Serial.println("Begin.");
  i2c_dev->begin();

  Serial.println("Write.");
  uint8_t buffer[1];
  buffer[0] = ADDRESS;
  i2c_dev->write(buffer, 1);

  Serial.println("Done.");
}

void loop() {
}

With pull ups connected, it gets through the code:
Screenshot from 2021-04-01 13-27-20

But without pull ups, it locks up:
Screenshot from 2021-04-01 13-26-49

This should really be something that Wire takes care of. But that's probably not a viable option.

Here's how CP does it for ref:
https://github.com/adafruit/circuitpython/blob/main/ports/atmel-samd/common-hal/busio/I2C.c#L79

Problem with Adafruit_AHTX0

trying to use Adafruit_AHTX0

Hardware:
Mac OS 10.13
Arduino IDE 1.8
Board ESP32-C3-DevKitM-1

I'm trying to upload an example to use the AHT10 temperature sensor but I'm getting the following error:

/Users/firemedia1/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0-alpha1/cores/esp32/Arduino.h:107:66: note: suggested alternative: 'GPIO_IN_REG'
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
^~~~~~~~~~~~
/Users/firemedia1/Dropbox/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.cpp:58:33: note: in expansion of macro 'portInputRegister'
misoPort = (BusIO_PortReg *)portInputRegister(digitalPinToPort(misopin));
^~~~~~~~~~~~~~~~~

SPI_BITORDER_MSBFIRST not defined for STM32 Arduino

Hello folks
This is my first post in Github and I have no idea what I'm doing :)
But I found an issue trying to compile an Arduino project that uses the "Adafruit MPU6050" Library.
The target device is a STMF103C8 (typical bluepill with 64K) and for the board "Hardware" I'm using:
https://github.com/rogerclarkmelbourne/Arduino_STM32

I got the error "SPI_BITORDER_MSBFIRST not defined"

I fixed it modifying the file Adafruit_SPIDevice.h but I don't know how to commit the change neither if the change is correct.

// Some platforms have a BitOrder enum but its named MSBFIRST/LSBFIRST
#if defined(ARDUINO_ARCH_SAMD) || defined(__SAM3X8E__) || defined(NRF52_SERIES) || defined(ARDUINO_ARCH_ARDUINO_CORE_STM32) || defined(ARDUINO_ARCH_MEGAAVR) || defined(_STM32_DEF_))
  #define SPI_BITORDER_MSBFIRST MSBFIRST
  #define SPI_BITORDER_LSBFIRST LSBFIRST
#endif

Basically, I added: || defined(_STM32_DEF_)

Hope this is useful to someone else...

Warning at Arduino Every Board

E:\Programme\Arduino\portable\sketchbook\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::_read(uint8_t*, size_t, bool)':
E:\Programme\Arduino\portable\sketchbook\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:191:78: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
  size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len, (uint8_t)stop);
                                                                              ^
In file included from E:\Programme\Arduino\portable\sketchbook\libraries\Adafruit_BusIO\Adafruit_I2CDevice.h:5:0,
                 from E:\Programme\Arduino\portable\sketchbook\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp:1:
E:\Programme\arduino\portable\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire\src/Wire.h:64:12: note: candidate 1: size_t TwoWire::requestFrom(int, int, int)
     size_t requestFrom(int, int, int);
            ^~~~~~~~~~~
E:\Programme\arduino\portable\packages\arduino\hardware\megaavr\1.8.7\libraries\Wire\src/Wire.h:62:12: note: candidate 2: virtual size_t TwoWire::requestFrom(uint8_t, size_t, bool)
     size_t requestFrom(uint8_t, size_t, bool);
            ^~~~~~~~~~~

That's a bit uncomfortable.
I don't see the reason for the cast here either

Here is a 'solution' that omits the cast on the AVR XMEGA.
Adafruit_I2CDevice.cpp around line 191

// Schnipp
bool Adafruit_I2CDevice::_read(uint8_t *buffer, size_t len, bool stop) {
#if defined(TinyWireM_h)
  size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len);
#elif defined(ARDUINO_ARCH_MEGAAVR)  
   size_t recv = _wire->requestFrom(_addr, len, stop);
#else
 size_t recv = _wire->requestFrom((uint8_t)_addr, (uint8_t)len, (uint8_t)stop);
#endif
// Schnapp

Are there any side effects I've overlooked?

Problem with LPC1769 compiling to use with HTS221 sensor.

Hi there,

I am trying to add HTS221 sensor to BTT SKR 1.4 TURBO 3d printer board using SPI interface via Marlin Firmware. https://www.amazon.com/BIGTREETECH-Controller-Compatible-With12864LCD-5TMC2209/dp/B082QYYFVX

This board has LPC1769 mcu. I added the necessary libraries to platformio but Adafruit-BusIO throws this error during compiling.

In file included from lib\Adafruit_BusIO-master/Adafruit_BusIO_Register.h:2,
from lib\Adafruit_HTS221-master/Adafruit_HTS221.h:22,
from Marlin\src\lcd\dogm\status_screen_DOGM.cpp:44:
lib\Adafruit_BusIO-master/Adafruit_SPIDevice.h:38:22: error: 'BitOrder' has not been declared
38 | BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
| ^~~~~~~~
lib\Adafruit_BusIO-master/Adafruit_SPIDevice.h:43:22: error: 'BitOrder' has not been declared
43 | BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
| ^~~~~~~~
lib\Adafruit_BusIO-master/Adafruit_SPIDevice.h:61:3: error: 'BitOrder' does not name a type
61 | BitOrder _dataOrder;
| ^~~~~~~~
lib\Adafruit_BusIO-master/Adafruit_SPIDevice.h:38:43: error: 'SPI_BITORDER_MSBFIRST' was not declared in this scope
38 | BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
| ^~~~~~~~~~~~~~~~~~~~~
lib\Adafruit_BusIO-master/Adafruit_SPIDevice.h:39:41: error: 'SPI_MODE0' was not declared in this scope; did you mean 'SPI_MODE3'?
39 | uint8_t dataMode = SPI_MODE0, SPIClass *theSPI = &SPI);
| ^~~~~~~~~
| SPI_MODE3
compilation terminated due to -fmax-errors=5.
Compiling .pio\build\LPC1769\src\src\lcd\extui\lib\ftdi_eve_touch_ui\ftdi_eve_lib\basic\commands.cpp.o
*** [.pio\build\LPC1769\src\src\lcd\dogm\status_screen_DOGM.cpp.o] Error 1
======================================================================================= [FAILED] Took 56.65 seconds =======================================================================================

Environment Status Duration


mega2560 IGNORED
mega1280 IGNORED
rambo IGNORED
FYSETC_F6_13 IGNORED
FYSETC_F6_14 IGNORED
sanguino644p IGNORED
sanguino1284p IGNORED
melzi IGNORED
melzi_optiboot IGNORED
at90usb1286_cdc IGNORED
at90usb1286_dfu IGNORED
DUE IGNORED
DUE_USB IGNORED
DUE_debug IGNORED
LPC1768 IGNORED
LPC1769 FAILED 00:00:56.648
STM32F103RC IGNORED
STM32F103RC_fysetc IGNORED
STM32F103RC_btt IGNORED
STM32F103RC_btt_USB IGNORED
STM32F103RC_btt_512K IGNORED
STM32F103RC_btt_512K_USB IGNORED
STM32F103RE IGNORED
STM32F103RE_btt IGNORED
STM32F103RE_btt_USB IGNORED
STM32F4 IGNORED
STM32F7 IGNORED
ARMED IGNORED
STM32F103VE_GTM32 IGNORED
STM32F103VE_longer IGNORED
mks_robin_mini IGNORED
mks_robin_nano IGNORED
mks_robin IGNORED
mks_robin_pro IGNORED
mks_robin_lite IGNORED
mks_robin_lite3 IGNORED
jgaurora_a5s_a1 IGNORED
STM32F103CB_malyan IGNORED
chitu_f103 IGNORED
STM32F401VE_STEVAL IGNORED
FLYF407ZG IGNORED
FYSETC_S6 IGNORED
STM32F407VE_black IGNORED
BIGTREE_SKR_PRO IGNORED
BIGTREE_GTR_V1_0 IGNORED
BIGTREE_BTT002 IGNORED
teensy31 IGNORED
teensy35 IGNORED
esp32 IGNORED
linux_native IGNORED
SAMD51_grandcentral_m4 IGNORED
rumba32_f446ve IGNORED
rumba32_mks IGNORED
include_tree IGNORED
================================================================================== 1 failed, 0 succeeded in 00:00:56.648 ==================================================================================
The terminal process terminated with exit code: 1

Does it means LPC1769 not supported? If its a simple fix I would really like to use that sensor on my project.

I am not a programmer so I dont know how to solve this issue.

Thanks.

How to print out the the value of the register

Hello. I am looking into registers and learning various operations with them. I am using LIS3DH accelerometer sensor with the adafruit library.

For some reason, I am having a lot of troubles trying to print out the value of the register. For example, I want to print CTRL1_REG of the LIS3DH.

Inside Adafruit_LIS3DH.cpp file, I have created my own function for reading the register:

Adafruit_BusIO_Register Adafruit_LIS3DH::read_register(int register){
    Adafruit_BusIO_Register reg_to_read = Adafruit_BusIO_Register(
    i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, register, 1);
    return reg_to_read;

}

Simply, all I want to do is pass the value of the register to the function, and the function would then return me a number or hex value so I know what is set for this register. I have tried the above but I am not fully sure whether I can use the type Adafruit_BusIO_Register as a regular numbe or hex. Is that possible?

In my main arduino code, I call:

  Adafruit_BusIO_Register reg_to_read;
  reg_to_read = lis.read_register(LIS3DH_REG_CTRL4);
  Serial.println(reg_to_read);

But there is an error :

no matching function for call to 'Adafruit_BusIO_Register::Adafruit_BusIO_Register()'

Any help is appreciated. Please suggest me a simplest way how to read a register and print out using serial print

When building in Platform.io for ESP32, there are type casting issues

The build error:

.pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp: In member function 'bool Adafruit_SPIDevice::write(const uint8_t*, size_t, const uint8_t*, size_t)':
.pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:352:61: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(prefix_buffer, nullptr, prefix_len);
                                                             ^
In file included from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.h:9:0,
                 from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\...\.platformio\packages\framework-arduinoespressif32\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^
.pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:355:47: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(buffer, nullptr, len);
                                               ^
In file included from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.h:9:0,
                 from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\...\.platformio\packages\framework-arduinoespressif32\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^
.pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp: In member function 'bool Adafruit_SPIDevice::write_then_read(const uint8_t*, size_t, uint8_t*, size_t, uint8_t)': 
.pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:446:59: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
       _spi->transferBytes(write_buffer, nullptr, write_len);
                                                           ^
In file included from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.h:9:0,
                 from .pio\libdeps\esp32doit-devkit-v1\Adafruit BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\...\.platformio\packages\framework-arduinoespressif32\libraries\SPI\src/SPI.h:73:10: note:   initializing argument 1 of 'void SPIClass::transferBytes(uint8_t*, uint8_t*, uint32_t)'
     void transferBytes(uint8_t * data, uint8_t * out, uint32_t size);
          ^
Compiling .pio\build\esp32doit-devkit-v1\libb81\DHT sensor library\DHT.cpp.o
*** [.pio\build\esp32doit-devkit-v1\lib1c9\Adafruit BusIO\Adafruit_SPIDevice.cpp.o] Error 1

Building with the following in the platformio.ini file fixes the issue (by force):


build_flags =
	-fpermissive # temp fix for Adafruit BusIO library typecasting errors

repository description

The description is "I2C, SPI and UART abstractions for use with Arduino", but there is no UART code in the repository.

Version 1.0 and greater broken on NRF52 feather board (with VEML7700)

Version 0.3 and below compiles fine. See error messages below


Build options changed, rebuilding all
In file included from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:1:0,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:2,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_I2CRegister.h:1,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_VEML7700_Library/Adafruit_VEML7700.h:23,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_VEML7700_Library\examples\veml7700_test\veml7700_test.ino:1:

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h: In static member function 'static byte SPIClass::transfer(byte)':

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:56:3: error: 'SPDR' was not declared in this scope

SPDR = _data;

^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:56:3: note: suggested alternative: 'SPI'

SPDR = _data;

^~~~

SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:12: error: 'SPSR' was not declared in this scope

while (!(SPSR & _BV(SPIF)))

        ^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:12: note: suggested alternative: 'SPI'

while (!(SPSR & _BV(SPIF)))

        ^~~~

        SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:23: error: 'SPIF' was not declared in this scope

while (!(SPSR & _BV(SPIF)))

                   ^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:23: note: suggested alternative: 'SPI'

while (!(SPSR & _BV(SPIF)))

                   ^~~~

                   SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:19: error: '_BV' was not declared in this scope

while (!(SPSR & _BV(SPIF)))

               ^~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:57:19: note: suggested alternative: '_B'

while (!(SPSR & _BV(SPIF)))

               ^~~

               _B

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h: In static member function 'static void SPIClass::attachInterrupt()':

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:3: error: 'SPCR' was not declared in this scope

SPCR |= _BV(SPIE);

^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:3: note: suggested alternative: 'SPI'

SPCR |= _BV(SPIE);

^~~~

SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:15: error: 'SPIE' was not declared in this scope

SPCR |= _BV(SPIE);

           ^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:15: note: suggested alternative: 'SPI'

SPCR |= _BV(SPIE);

           ^~~~

           SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:11: error: '_BV' was not declared in this scope

SPCR |= _BV(SPIE);

       ^~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:63:11: note: suggested alternative: '_B'

SPCR |= _BV(SPIE);

       ^~~

       _B

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h: In static member function 'static void SPIClass::detachInterrupt()':

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:3: error: 'SPCR' was not declared in this scope

SPCR &= ~_BV(SPIE);

^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:3: note: suggested alternative: 'SPI'

SPCR &= ~_BV(SPIE);

^~~~

SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:16: error: 'SPIE' was not declared in this scope

SPCR &= ~_BV(SPIE);

            ^~~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:16: note: suggested alternative: 'SPI'

SPCR &= ~_BV(SPIE);

            ^~~~

            SPI

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:12: error: '_BV' was not declared in this scope

SPCR &= ~_BV(SPIE);

        ^~~

C:\Users\kingr\Google Drive\Arduino\libraries\SPI/SPI.h:67:12: note: suggested alternative: '_B'

SPCR &= ~_BV(SPIE);

        ^~~

        _B

In file included from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:2:0,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_I2CRegister.h:1,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_VEML7700_Library/Adafruit_VEML7700.h:23,

             from C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_VEML7700_Library\examples\veml7700_test\veml7700_test.ino:1:

C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h: At global scope:

C:\Users\kingr\Google Drive\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:27:3: error: 'SPISettings' does not name a type

SPISettings *_spiSetting;

^~~~~~~~~~~

Multiple libraries were found for "SPI.h"
Used: C:\Users\kingr\Google Drive\Arduino\libraries\SPI
Not used: C:\Users\kingr\AppData\Local\Arduino15\packages\adafruit\hardware\nrf52\0.11.0\libraries\SPI
exit status 1
Error compiling for board Adafruit Bluefruit Feather nRF52832.

-O2 breaks this lib on atmel M0

  • Arduino board: itsy bitsy m0

  • Arduino IDE version (found in Arduino -> About Arduino menu): platformio 6.0.2

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too):

Use the following build config and try and use the BusIO library

[env:itsy]
platform = atmelsam
board = adafruit_itsybitsy_m0
framework = arduino
build_flags = -O2
build_unflags = -Os
lib_deps = 6214

main.cpp

#include "Wire.h"
#include <Adafruit_SPIDevice.h>

void setup() {}
void loop() {}

build output (dirty build to reduce length)

Processing itsy (platform: atmelsam; board: adafruit_itsybitsy_m0; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_itsybitsy_m0.html
PLATFORM: Atmel SAM (7.1.0+sha.ec05bdd) > Adafruit ItsyBitsy M0
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:
 - framework-arduino-samd-adafruit @ 1.7.5
 - framework-cmsis @ 2.50400.181126 (5.4.0)
 - framework-cmsis-atmel @ 1.2.2
 - toolchain-gccarmnoneeabi @ 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit BusIO @ 1.12.0
|   |-- SPI @ 1.0
|   |   |-- Adafruit Zero DMA Library @ 1.1.0
|   |   |   |-- Adafruit TinyUSB Library @ 1.4.3
|   |   |-- Adafruit TinyUSB Library @ 1.4.3
|   |-- Wire @ 1.0
|   |   |-- Adafruit TinyUSB Library @ 1.4.3
|-- Wire @ 1.0
|   |-- Adafruit TinyUSB Library @ 1.4.3
Building in release mode
Compiling .pio/build/itsy/src/main.cpp.o
Archiving .pio/build/itsy/lib716/libAdafruit_ZeroDMA.a
Indexing .pio/build/itsy/lib716/libAdafruit_ZeroDMA.a
Archiving .pio/build/itsy/lib0f0/libSPI.a
Indexing .pio/build/itsy/lib0f0/libSPI.a
Compiling .pio/build/itsy/lib6bd/Wire/Wire.cpp.o
Compiling .pio/build/itsy/libc16/Adafruit BusIO/Adafruit_BusIO_Register.cpp.o
Compiling .pio/build/itsy/libc16/Adafruit BusIO/Adafruit_I2CDevice.cpp.o
Compiling .pio/build/itsy/libc16/Adafruit BusIO/Adafruit_SPIDevice.cpp.o
/var/folders/wy/yddn63455wd2vk7m62shqd780000gn/T//ccEbUdN3.s: Assembler messages:
/var/folders/wy/yddn63455wd2vk7m62shqd780000gn/T//ccEbUdN3.s:462: Error: lo register required -- `sub r10,#1'
Compiling .pio/build/itsy/FrameworkArduino/WInterrupts.c.o
Compiling .pio/build/itsy/FrameworkArduino/WMath.cpp.o
Compiling .pio/build/itsy/FrameworkArduino/WString.cpp.o
Compiling .pio/build/itsy/FrameworkArduino/abi.cpp.o
Compiling .pio/build/itsy/FrameworkArduino/avr/dtostrf.c.o
*** [.pio/build/itsy/libc16/Adafruit BusIO/Adafruit_SPIDevice.cpp.o] Error 1

Adafruit BusIO release version 1.9.0 breaks I2C reading of PM25AQI

I just updated a bunch of libraries from Adafruit this evening, and I discovered reading PMSA003I devices over I2C began to fail after I reprogrammed a couple of my devices with the latest libraries. I'm using an Adafruit Huzzah32 (esp32) with the Arduino programming environment. The version of the Adafruit PM25AQI library is 1.0.6 and hasn't changed in about 6 months. I investigated the Adafruit BusIO library as the possible culprit, since it was among the libraries I just updated and it had comments of "chunkify i2c" for the latest changes.

I did some quick testing by using the stock Example program for the Adafruit PM25AQI library, named "PM25_test", with both the latest version of Adafruit BusIO (1.9.0) and the previous version (1.8.3).

The output of "PM25_test" with BusIO version 1.8.3 is as expected.
The output of "PM25_test" with BusIO version 1.9.0 (after finding the PM25 sensor) is the repeating output: "Could not read from AQI"

This behavior is similar with my own custom program using these same libraries.

pass in an initialised wire instance?

Adafruit_I2CDevice

I think I am correct in saying from my scan of the source code this library assumes the wire instance is uninitialised, and if using several higher sensor classes will also reinitialise the wire interface for each sensor

could have a flag passed in to sgp30/sht31 classes to say wire is initialised already, and pass that flag through to the base class, so in the case of an esp-01 can do wire.begin(0,2) and pass that initialised wire instance into the classes with the extra flag saying already initialised.

and with cpp parameter defaults (i.e. wirestarted=false) that can be transparent to existing code. (i.e. existing code that uses the library will still work in default state of passing in an uninitialised wire instance)

I guess it works fine as long as the board uses the default pins of wire.begin which is gpio 4 and gpio 5.

'BitOrder' does not name

Hello I work with ESP32 WROOM and a OLED SSD1331
IDE: vscode
extension: microsoft-arduino

I install Library for oled but i receive this error

In file included from C:\Users\hassan\Documents\Arduino\libraries\Adafruit-GFX-Library-master\Adafruit_GrayOLED.h:31:0,
from C:\Users\hassan\Documents\Arduino\libraries\Adafruit-GFX-Library-master\Adafruit_GrayOLED.cpp:20:
C:\Users\hassan\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:39:9: error: 'BitOrder' does not name a type
typedef BitOrder BusIOBitOrder;
         ^
C:\Users\hassan\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:69:22: error: 'BusIOBitOrder' has not been declared
                      BusIOBitOrder dataOrder = SPI_BITORDER_MSBFIRST,
^
C:\Users\hassan\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:74:22: error: 'BusIOBitOrder' has not been declared
                      BusIOBitOrder dataOrder = SPI_BITORDER_MSBFIRST,
                      ^
C:\Users\hassan\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_SPIDevice.h:95:3: error: 'BusIOBitOrder' does not name a type
   BusIOBitOrder _dataOrder;
   ^

Compilation error when using megaTinyCore under PlatformIO

When using this library with megaTinyCore, I'm facing a compilation error under the PlatformIO IDE, it is however doesn't seem to be an issue when compiling under Arduino IDE.

My Platformio.ini setting:

[env:ATtiny3217]
platform = atmelmegaavr
board = ATtiny3217
framework = arduino
lib_deps =
	adafruit/Adafruit SSD1306@^2.4.3
	adafruit/Adafruit MAX31856 library@^1.2.3
	br3ttb/PID@^1.2.1
	adafruit/Adafruit GFX Library@^1.10.6

The error shows:

Processing ATtiny3217 (platform: atmelmegaavr; board: ATtiny3217; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATtiny3217.html
PLATFORM: Atmel megaAVR (1.4.0) > ATtiny3217
HARDWARE: ATTINY3217 16MHz, 2KB RAM, 32KB Flash
PACKAGES:
 - framework-arduino-megaavr-megatinycore 2.1.5
 - toolchain-atmelavr 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 20 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit SSD1306> 2.4.3
|   |-- <Adafruit GFX Library> 1.10.6
|   |   |-- <Adafruit BusIO> 1.7.2
|   |   |   |-- <SPI> 1.0
|   |   |   |-- <Wire> 1.0
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|-- <Adafruit MAX31856 library> 1.2.3
|   |-- <Adafruit BusIO> 1.7.2
|   |   |-- <SPI> 1.0
|   |   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <PID> 1.2.1
|-- <Adafruit GFX Library> 1.10.6
|   |-- <Adafruit BusIO> 1.7.2
|   |   |-- <SPI> 1.0
|   |   |-- <Wire> 1.0
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <EEPROM> 2.0
|-- <SPI> 1.0
|-- <Wire> 1.0
Building in release mode
Compiling .pio/build/ATtiny3217/src/main.cpp.o
Archiving .pio/build/ATtiny3217/lib5dd/libSPI.a
Indexing .pio/build/ATtiny3217/lib5dd/libSPI.a
Archiving .pio/build/ATtiny3217/lib024/libWire.a
In file included from .pio/libdeps/ATtiny3217/Adafruit MAX31856 library/Adafruit_MAX31856.h:102:
0,
                 from src/main.cpp:133:
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:62:22: error: 'BitOrder' has not bee
n declared
                      BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
                      ^~~~~~~~
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:67:22: error: 'BitOrder' has not bee
n declared
                      BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
                      ^~~~~~~~
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:88:3: error: 'BitOrder' does not nam
e a type
   BitOrder _dataOrder;
   ^~~~~~~~
Indexing .pio/build/ATtiny3217/lib024/libWire.a
Compiling .pio/build/ATtiny3217/libcf4/Adafruit BusIO/Adafruit_BusIO_Register.cpp.o
*** [.pio/build/ATtiny3217/src/main.cpp.o] Error 1
Compiling .pio/build/ATtiny3217/libcf4/Adafruit BusIO/Adafruit_I2CDevice.cpp.o
In file included from .pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_BusIO_Register.h:2:0,
                 from .pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_BusIO_Register.cpp:1:
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:62:22: error: 'BitOrder' has not bee
n declared
                      BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
                      ^~~~~~~~
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:67:22: error: 'BitOrder' has not bee
n declared
                      BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
                      ^~~~~~~~
.pio/libdeps/ATtiny3217/Adafruit BusIO/Adafruit_SPIDevice.h:88:3: error: 'BitOrder' does not nam
e a type
   BitOrder _dataOrder;
   ^~~~~~~~
*** [.pio/build/ATtiny3217/libcf4/Adafruit BusIO/Adafruit_BusIO_Register.cpp.o] Error 1
========================== [FAILED] Took 1.57 seconds ==========================

Pointer to hardware SPI not correctly initialized if hardware is available but software SPI is used

In Adafruit_SPIDevice.h:

class Adafruit_SPIDevice {
<snip>
#ifdef BUSIO_HAS_HW_SPI
  SPIClass *_spi;
  SPISettings *_spiSetting;
#else
  uint8_t *_spi = nullptr;
  uint8_t *_spiSetting = nullptr;
#endif

If hardware SPI is available, _spi is not initialized to nullptr.

If you then use the software SPI constructor, _spi remains unintialized.

Then, in Adafruit_SPIDevice.cpp:

bool Adafruit_SPIDevice::begin(void) {
  if (_cs != -1) {
    pinMode(_cs, OUTPUT);
    digitalWrite(_cs, HIGH);
  }

  if (_spi) { // hardware SPI
#ifdef BUSIO_HAS_HW_SPI
    _spi->begin();
#endif

if(_spi) is used to detect hardware or software SPI mode; since the value of _spi is random and possibly non zero, _spi->begin() is called and promptly causes crashes / undefined behavior.

i2cProcQueue >> IntegerDivideByZero

Hi I use this library to control i2c devices via BLE to send commands from mobile to ESP32. My problem is that when I send many commands I get this error
Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled.

So I dissasembly the code and find the error in this function i2cProcQueue.
I google this error and find that this error is due to unsafe thread crossing.

the driver or BLE is multithread, so I dont know how to use this code without broke the multithread.

I think I have to lock the thread when I use the i2c.write and/or i2c.read.
I think this option shuld by buildin the library

thank you

Adafruit_I2CDevice write() const argument

This isn't an issue but more like a suggestion. Wouldn't it make more sense if Adafruit_I2CDevice write() buffer arguments are const?
The underlying TwoWire write()'s buffer argument is const, which Adafruit_I2CDevice uses. So, instead of:

bool write(uint8_t *buffer, size_t len, bool stop, uint8_t *prefix_buffer, size_t prefix_len);
bool write_then_read(uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop);

it would make more sense if they are:

bool write(const uint8_t *buffer, ... ... ..., const uint8_t *prefix_buffer, ... ... ...);
bool write_then_read(const uint8_t *write_buffer, ... ... ...);

Switching from Wire.h to Adafruit_I2CDevice.h breaks my code, just because the latter doesn't accept const.

issue with compiling the program to ESP8266

Hi Guys, I have a problem with compiling the program to Board ESP8266,

when I use this code Wire.begin(sda,scl); but that error was not in this scope and then I tried to change code like a Wire.begin(4,5); when I verified the code has an error, pls see below the message error

C:\Users\lapto\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp: In member function 'void Adafruit_SPIDevice::transfer(uint8_t*, size_t)':
C:\Users\lapto\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:137:31: error: no matching function for call to 'SPIClass::transfer(uint8_t*&, size_t&)'
_spi->transfer(buffer, len);
^
C:\Users\lapto\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:137:31: note: candidate is:
In file included from C:\Users\lapto\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.h:9:0,
from C:\Users\lapto\Documents\Arduino\libraries\Adafruit_BusIO\Adafruit_SPIDevice.cpp:1:
C:\Users\lapto\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\SPI/SPI.h:65:11: note: uint8_t SPIClass::transfer(uint8_t)
uint8_t transfer(uint8_t data);
^
C:\Users\lapto\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.1\libraries\SPI/SPI.h:65:11: note: candidate expects 1 argument, 2 provided
exit status 1
Error compiling for board Generic ESP8266 Module.

  • Arduino board: ESP8266

  • Arduino IDE version (1.8.19):

Build warning: `[-Werror=unused-but-set-variable]`

  • Arduino board: Uno
  • Arduino IDE version (found in Arduino -> About Arduino menu): ARDUINO_CLI_VERSION=0.23.0
/Arduino/libraries/Adafruit_BusIO/Adafruit_I2CDevice.cpp:267:11: error: variable 'prescaler' set but not used [-Werror=unused-but-set-variable]
   uint8_t prescaler = 1;
           ^~~~~~~~~

Compile issues for boards without SPI

When trying to compile this example:
https://github.com/adafruit/Adafruit_APDS9960/blob/master/examples/proximity_sensor/proximity_sensor.ino
for a target board of Adafruit ProxLight Trinkey (SAMD21), get:

Arduino: 1.8.13 (Linux), Board: "Adafruit ProxLight Trinkey (SAMD21), Small (-Os) (standard), Arduino, Off"

In file included from /home/user/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.cpp:1:
/home/user/Arduino/libraries/Adafruit_BusIO/Adafruit_SPIDevice.h:68:72: error: 'SPI' was not declared in this scope; did you mean 'PI'?
   68 |                      uint8_t dataMode = SPI_MODE0, SPIClass *theSPI = &SPI);
      |                                                                        ^~~
      |                                                                        PI

Arduino SAMD BSP 1.8.11
Adafruit SAMD BSP 1.7.5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.