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

Regarding I2C Fast Mode #2

Closed
ta2edchimp opened this issue Apr 13, 2017 · 1 comment
Closed

Regarding I2C Fast Mode #2

ta2edchimp opened this issue Apr 13, 2017 · 1 comment

Comments

@ta2edchimp
Copy link
Contributor

In the original Indio lib sources, "I2C Fast Mode" is used during IndioClass::analogRead.
It is commented out in the current current codebase.

Is this because of not being supported by the new D21G topboard at all, or is it just not supported this way (as the comment states it)?

1. If it is not supported by the D21G at all, why not just conditionally exclude or include setting the TWBR (using e.g. the ARDUINO_AVR_IND1286 and alike symbolic constants)?

2. If it is not supported in the previously used, hardcoded way, may I propose the following:

According to documentation about the "Two Wire Interface and the Wire Library" (see here for example), the TWBR / Two Wire Bit Rate should be generated as follows:

TWBR = ((CPU_FREQ / TWI_FREQ) - 16) / 2

The Atmega32u4 and AT90USB1286 both run with 16 MHz, so according to the formular above, as well as the hint about "400 kHz" (I assume clockspeed / twi frequency) in the original Indio library sources, this comes down to a TWBR of 12, as it indeed is hardcoded in the original sources.

According to the Tech. Details enlisted in the Industruino shop, the ATSAMD21G16 runs at 48 MHz, so, while maintaining the TWI_FREQ of 400 kHz, the TWBR should be:

TWBR = ((48,000,000 / 400,000) - 16) / 2 = 52

Unfortunately, I did not yet find the time to set up an Industruino using the new topboard, so I am currently unable to test it. But maybe this is something you guys might want to try for yourself (unless my thoughts are complete nonsense).

@ta2edchimp
Copy link
Contributor Author

Just a quick follow up:

  1. The CPU_FREQ macro has been renamed to F_CPU inbetween the linked article's date of creation and Arduino IDE 1.6.5
  2. The TWI_FREQ in Industruino's Wire/utility/twi.h is only set to 100 kHz, preventing the calculation of the expected result as in the above proposal.

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

No branches or pull requests

1 participant