If I’ve read things correctly, all I should need to do to get this working for STM32 is correctly type the variables?
I see in the code that it uses ‘int’ regularly, presumably these need to be typed as int16_t.
I haven’t spotted any of the other nasties and am assuming that the STM32 version of Wire will take care of i2c.
So, what’s the correct way to go about this, should I fork the original authors code and issue a PR for the edits or do we make a private copy postfixed STM32? Or is anyone else bothered and I just reference a local version? ![]()
I ditched adafruits ADXL345 libraries (also requires their generic sensor library) in favour of this one because it’s way less bloaty.
Just trying to get things lined up ready for when my boards arrive.
Presumably it would ever so slightly reduce the amount of dynamic ram used though.
Transferred my project over to it and started to code the differences in.
Working so far:
3X SSD1306 OLED’s working using software SPI (adafruit library)
A max 31586 working over another software SPI bus (adafruit library)
Analogue inputs working fine, using a 4096 vs 1024 divisor.
What I can’t get to work is the fabo over I2C.
The fabo relies on Wire.h for hardware I2C, do I need to include a maple mini variant of this with I2C hardcoded to pins 15 & 16? Those are the pins silkscreened on my board and match this reference -> https://developer.mbed.org/media/upload … nout01.png
The 345 board I’m using has a regulator on, it’s passing 3.3v so the chip is getting VCC.
The pullup resistors on the board are 4.7K
The library has a searchdevice method on the object, this is what is failing – suspect it’s something to do with how things are cast in the code, OR I’ve just plain got the I2C pins wrong/something, OR it’s some quirk of multiple I2C buses and the code is expecting an address that doens’t exist.
Not massively familiar with I2C so I guess it’s time to go do some googling.
Scanning...
I2C device found at address 0x53 !
done
the other is trying the address + 1, e.g. 0x3C & 0x3D istr a 9.98″ OLED doing that for some reason – link set to an alternate address ?
stephen
<edit> i need to type faster </edit>
Here’s the definition of the address from the library header:
/** SLAVE_ADDRESS */
#define ADXL345_SLAVE_ADDRESS 0x53
I’m pretty sure there’s something going wrong with the way that the library constructor works on STM32, but I’m not the worlds greatest coder (especially object oriented code) so am a bit clueless at the moment.
Here’s the class definition from the library header:
class FaBo3Axis
{
public:
FaBo3Axis(uint8_t addr = ADXL345_SLAVE_ADDRESS);
bool searchDevice(void);
void configuration(void);
void powerOn(void);
void readXYZ(int *x, int *y, int *z);
uint8_t readIntStatus();
void enableTap();
bool isSingleTap(uint8_t value);
bool isDoubleTap(uint8_t value);
private:
uint8_t _i2caddr;
void writeI2c(uint8_t register_addr, uint8_t value);
void readI2c(uint8_t register_addr, uint8_t num, uint8_t *buf);
};
So either my code is stomping on it, or it doesn’t play well in conjunction with the other software SPI libraries I’m using but only for STM32??
![]()
Anyone else got some sample I2C code that uses this method?
a search for i2caddr on here gave 4 results, one mentioning a #define I2CADDR (blah)
stephen
a search for i2caddr on here gave 4 results, one mentioning a #define I2CADDR (blah)
stephen
Think I’m on the right track with the available() method, just need to find some other STM32 code that makes use of it when reading.
http://www.stm32duino.com/viewtopic.php?t=446
The ADXL345 operates as a slave -> https://www.sparkfun.com/datasheets/Sen … DXL345.pdf
I’m a complete novice at this hardware level stuff, is it correct that the Wire implementation won’t work with slaves?
Please could anyone who knows more about how this code works please comment?
I’ve also pasted the Arduino Wire.h equivalent below
STM32 WireBase.cpp
//TODO: Add the ability to queue messages (adding a boolean to end of function
// call, allows for the Arduino style to stay while also giving the flexibility
// to bulk send
uint8 WireBase::requestFrom(uint8 address, int num_bytes) {
if (num_bytes > WIRE_BUFSIZ) {
num_bytes = WIRE_BUFSIZ;
}
itc_msg.addr = address;
itc_msg.flags = I2C_MSG_READ;
itc_msg.length = num_bytes;
itc_msg.data = &rx_buf[rx_buf_idx];
process();
rx_buf_len += itc_msg.xferred;
itc_msg.flags = 0;
return rx_buf_len;
}
I’ve wrapped the library calls in conditionals so if built on smaller hardware it uses the fabo library.
Best of both worlds but messy code.
When I know more about this stuff I may revisit and make my own much smaller library.

