FaBo3Axis-ADXL345-Library

Working libraries, libraries being ported and related hardware
User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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?
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by BennehBoy » Mon Jan 23, 2017 9:17 pm

Stumped. HELP :D
-------------------------------------
https://github.com/BennehBoy

zmemw16
Posts: 1484
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: FaBo3Axis-ADXL345-Library

Post by 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

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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
Thanks, I looked at the SSD1306 but couldn't see anything obvious (to me), I'll revisit.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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?
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by BennehBoy » Tue Jan 24, 2017 9:07 am

OK, going to try stop asking dumb questions then finding the answers with a quick search.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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

Code: Select all

//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;
}
ARDUINO Wire.cpp

Code: Select all

uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
{
  if (isize > 0) {
  // send internal address; this mode allows sending a repeated start to access
  // some devices' internal registers. This function is executed by the hardware
  // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers)

  beginTransmission(address);

  // the maximum size of internal address is 3 bytes
  if (isize > 3){
    isize = 3;
  }

  // write internal register address - most significant byte first
  while (isize-- > 0)
    write((uint8_t)(iaddress >> (isize*8)));
  endTransmission(false);
  }

  // clamp to buffer length
  if(quantity > BUFFER_LENGTH){
    quantity = BUFFER_LENGTH;
  }
  // perform blocking read into buffer
  uint8_t read = twi_readFrom(address, rxBuffer, quantity, sendStop);
  // set rx buffer iterator vars
  rxBufferIndex = 0;
  rxBufferLength = read;

  return read;
}
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by 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.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 420
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: FaBo3Axis-ADXL345-Library

Post by BennehBoy » Tue Jan 24, 2017 3:32 pm

Project code for anyone interested -> https://github.com/BennehBoy/LRDuino
-------------------------------------
https://github.com/BennehBoy

Post Reply