Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using INA in Teensy 3.x boards #30

Closed
AluminioVanadio opened this issue Oct 14, 2018 · 11 comments
Closed

Using INA in Teensy 3.x boards #30

AluminioVanadio opened this issue Oct 14, 2018 · 11 comments
Assignees
Labels
enhancement New feature or request

Comments

@AluminioVanadio
Copy link

I have been unable tu use the library in a teensy 3.2 board, I changed the include from Wire.h to i2c_t3.h. It compiles but at least the example file does not detect an INA226. I can detect it using a scanner sketch which runs OK in teensy.

@SV-Zanshin
Copy link
Collaborator

SV-Zanshin commented Oct 14, 2018 via email

@AluminioVanadio
Copy link
Author

Hi,
I tried BackgroundRead also, with the library freshly installed and does not compile :

Compiling 'BackgroundRead' for 'Teensy 3.2 / 3.1'

BackgroundRead.ino: 71:5: error: expected constructor, destructor, or type conversion before '(' token
ISR (PCINT0_vect) { \ handle pin change interrupt D8

BackgroundRead.ino: In function void setup()
Error compiling project sources
Build failed for project 'BackgroundRead'

BackgroundRead.ino: 95:3: error: 'PCIFR' was not declared in this scope
PCIFR |= bit (digitalPinToPCICRbit(INA_ALERT_PIN)); \ clear any outstanding interrupt

BackgroundRead.ino: 96:3: error: 'PCICR' was not declared in this scope
PCICR |= bit (digitalPinToPCICRbit(INA_ALERT_PIN)); \ enable interrupt for the group

Using Visual Studio IDE.

Compiles OK selecting an Arduino Leonardo. It looks like port manupulation in teensy is different. Also I don not hace interrupts pins hooked up.
DisplayReadings compiles but it does not detect the INA226.
No INA device found, retrying in 10s...
No INA device found, retrying in 10s...
No INA device found, retrying in 10s...

SDA and SCL pins are correctly mapped by Wire.h looking at the scope.

@SV-Zanshin
Copy link
Collaborator

SV-Zanshin commented Oct 15, 2018 via email

@SV-Zanshin SV-Zanshin self-assigned this Oct 15, 2018
@AluminioVanadio
Copy link
Author

Hello Arnd.
I added the code, and maxDevices is at 0. I forced maxDevices to 127 and it works OK, you are right, there are differences in the EEPROM implementation of the Teensy.
Thanks

SV-Zanshin pushed a commit that referenced this issue Oct 16, 2018
@SV-Zanshin
Copy link
Collaborator

I added some #ifdefs to support the TEENSY boards to the code, that should work for your implementation now.

@SV-Zanshin SV-Zanshin added the enhancement New feature or request label Oct 16, 2018
@AluminioVanadio
Copy link
Author

AluminioVanadio commented Oct 17, 2018

Line 188 of the modified INA.cpp file has the variable type declaration missing:
uint8_t maxDevices = 2048 / sizeof(inaEE);
But stiil doesn't work in teensy 3.2, unless I assign maxDevices a fixed value.

@SV-Zanshin
Copy link
Collaborator

SV-Zanshin commented Oct 17, 2018 via email

@SV-Zanshin SV-Zanshin reopened this Oct 17, 2018
SV-Zanshin pushed a commit that referenced this issue Oct 17, 2018
@AluminioVanadio
Copy link
Author

Hi,
If I compile with line 188 in INA.ccp unmodified I get the following compiler error:
Compiling 'DisplayReadings' for 'Teensy 3.2 / 3.1'
INA.cpp: In member function uint8_t INA_Class::begin(uint8_t, uint32_t, uint8_t)

INA.cpp: 188:3: error: 'maxDevices' was not declared in this scope
maxDevices = 2048 \ sizeof(inaEE); \ defined, so use 2Kb as value
Error compiling libraries
Build failed for project 'DisplayReadings'

Looking at i2c_t3, made for teensy boards, they use the following definitions for detecting all board models:
#if defined(MK20DX128) || defined(MK20DX256) || defined(MKL26Z64) ||
defined(MK64FX512) || defined(MK66FX1M0) // 3.0/3.1-3.2/LC/3.5/3.6

#include "i2c_t3.h"
Thanks again

SV-Zanshin pushed a commit that referenced this issue Oct 18, 2018
@SV-Zanshin
Copy link
Collaborator

The compiler error would seem to indicate that the branch in the #ifdef was taken correctly, but I've added the directives you listed above to the code and fixed the way that the variable "maxDevices" is declared. Can you check to see if the current version works correctly?

@AluminioVanadio
Copy link
Author

Hi,
The problem is that 2048/ sizeof(inaEE) is 256, and maxDevices is 8 bit long, so making maxDevices a 16 bit integer or limiting maxDevices to 255 should work.
I modified it to:
maxDevices = 2048 / sizeof(inaEE)-1;
and works fine.

SV-Zanshin pushed a commit that referenced this issue Oct 19, 2018
Support TEENSY and removed overflow error when using devices with large EEPROM
@SV-Zanshin
Copy link
Collaborator

Thanks for pointing out that error - I should start using those bigger boards to broaden my horizons from the much more resource-restricted Atmel processors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants