FaBo3Axis-ADXL345-Library

BennehBoy
Thu Jan 12, 2017 11:12 am
https://github.com/FaBoPlatform/FaBo3Ax … 45-Library

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? :D

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.


danieleff
Thu Jan 12, 2017 11:49 am
I think that library is fine as it is. Did not test it, but it’s not like you have to change every int to run on STM32.

BennehBoy
Thu Jan 12, 2017 4:57 pm
OK fair enough :D

Presumably it would ever so slightly reduce the amount of dynamic ram used though.


BennehBoy
Mon Jan 23, 2017 3:09 pm
Board arrived,

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


BennehBoy
Mon Jan 23, 2017 4:56 pm
I’ve checked the obvious stuff:

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.


BennehBoy
Mon Jan 23, 2017 5:34 pm
Generic I2C scanner finds the device

Scanning...
I2C device found at address 0x53 !
done


zmemw16
Mon Jan 23, 2017 5:57 pm
try the sniffers from the Wire lib examples, one of them usually works for me.

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>


BennehBoy
Mon Jan 23, 2017 6:07 pm
I tried a sniffer, see previous post, it returns the correct address.

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);
};


BennehBoy
Mon Jan 23, 2017 8:14 pm
OK, so paired everything back, and the library works fine in isolation.

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??

:(


BennehBoy
Mon Jan 23, 2017 8:16 pm
Actually, no it doesn’t, it’s pulling the same random result back….

BennehBoy
Mon Jan 23, 2017 9:07 pm
Suspect this is a problem with inheritance from WireBase.available()

Anyone else got some sample I2C code that uses this method?


BennehBoy
Mon Jan 23, 2017 9:17 pm
Stumped. HELP :D

zmemw16
Tue Jan 24, 2017 12:36 am
did a grep -R _i2caddr on the F1 libraries directory, only the files Adafruit_SSD1306/Adafruit_SSD1306_STM32.h & cpp have it

a search for i2caddr on here gave 4 results, one mentioning a #define I2CADDR (blah)

stephen


BennehBoy
Tue Jan 24, 2017 7:30 am
zmemw16 wrote:did a grep -R _i2caddr on the F1 libraries directory, only the files Adafruit_SSD1306/Adafruit_SSD1306_STM32.h & cpp have it

a search for i2caddr on here gave 4 results, one mentioning a #define I2CADDR (blah)

stephen


BennehBoy
Tue Jan 24, 2017 8:32 am
SSd1306 uses HardWire & doesn’t do any reads, just writes.

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.


BennehBoy
Tue Jan 24, 2017 9:02 am
I found this post which infers that the Wire implementation does not work with slave devices…

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?


BennehBoy
Tue Jan 24, 2017 9:07 am
OK, going to try stop asking dumb questions then finding the answers with a quick search.

BennehBoy
Tue Jan 24, 2017 11:57 am
OK, so not sure if this comment on ::requestFrom method in WireBase.cpp is an indicator of the issue?

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;
}


BennehBoy
Tue Jan 24, 2017 3:18 pm
I’ve switched over to the adafruit ADXL345 library, code size is larger (~3kb) but that doesn’t matter too much on this device.

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.


BennehBoy
Tue Jan 24, 2017 3:32 pm
Project code for anyone interested -> https://github.com/BennehBoy/LRDuino

Leave a Reply

Your email address will not be published. Required fields are marked *