8000 mimxrt/machine_i2c.c: Make I2C bus ID arg optional with default. by malcolm-sparkfun · Pull Request #16956 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

mimxrt/machine_i2c.c: Make I2C bus ID arg optional with default. #16956

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

Conversation

malcolm-sparkfun
Copy link
Contributor

Summary

This PR adds for the mimxrt port the same functionality as the already approved #16671. It gives the option to not pass an I2C Bus ID when creating a machine I2C object on the mimxrt port. This would allow users on mimxrt platforms to simply declare an I2C object with machine.I2C() without passing any arguments, thus creating an object with a default I2C ID of 0 (freq and drive were already optional for this port).

Testing

Tested on TEENSY4.0 and TEENSY4.1 Boards:

  • Created machine.I2C object by passing no arguments to I2C(). Verified that it successfully could use the scan() method to detect a connected sensor.
  • Exercised I2C object by using it with an example program performing reads and writes to a sensor.

Trade-offs and Alternatives

I simply chose the default I2C ID to be 0, which may not be the desired default for some boards? As far as I could tell, this seemed like a fairly reasonable choice.

Signed-off-by: Malcolm McKellips <malcolm.mckellips@sparkfun.com>
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@robert-hh
Copy link
Contributor

Thanks for the contribution. This change is already covered in a different PR #16876, last commit, which addresses I2C, SPI and UART.

@malcolm-sparkfun
Copy link
Contributor Author

Oh perfect, thank you. I will close this then.

@dpgeorge
Copy link
Member

It looks like both this and #16876 have the same changes, which is good, you both implicitly agreed that I2C instance 0 is a good default.

ricksorensen added a commit to ricksorensen/micropython that referenced this pull request Apr 13, 2025
This addresses issue micropython#17103.

The new default I2C init does not require setting SCL or SDA but
the default pins for C3 (and S3?) conflict with the espressif
GPIO usage.
For the C3, pins 18/19 are for USB/JTAG. If used for
I2C() they will cause the REPL to hang on initialization of the I2C.
For the S3 pin 19 is allocated for USB/JTAG also but the
defaults do not seem to affect the REPL.

See PR micropython#16956
See Issue micropython#17103

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
ricksorensen added a commit to ricksorensen/micropython that referenced this pull request Apr 16, 2025
his addresses issue micropython#17103.

The new default I2C init does not require setting SCL or SDA but
the default pins for C3 (and S3?) conflict with the espressif
GPIO usage.
For the C3, pins 18/19 are for USB/JTAG. If used for
I2C() they will cause the REPL to hang on initialization of the I2C.
For the S3 pin 19 is allocated for USB/JTAG also but the
defaults do not seem to affect the REPL.  This pull request updates
pin settings for the non base ESP32 models (C3,C6,S2,S3,...).

See PR micropython#16956
See Issue micropython#17103

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
ricksorensen added a commit to ricksorensen/micropython that referenced this pull request May 14, 2025
This addresses issue micropython#17103.

The default I2C init does not require setting SCL or SDA but
the default pins for C3 (and S3?) conflict with the espressif
GPIO usage.

For the C3, pins 18/19 are for USB/JTAG. If used for
I2C() they will cause the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the
defaults do not seem to affect the REPL.  Also the default pins for
I2C(2) were 25/26 which are invalid for S3.

This pull request updates pin settings for C3 and S3 I2C defaults
if not specified during the build.

See PR micropython#16956
See Issue micropython#17103

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
ricksorensen added a commit to ricksorensen/micropython that referenced this pull request May 14, 2025
This addresses issue micropython#17103.

The default I2C init does not require setting SCL or SDA but
the default pins for C3, S3, and S2 conflict with the espressif
GPIO usage.

For the C3, pins 18/19 are for USB/JTAG. If used for
I2C() they will cause the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the
defaults do not seem to affect the REPL.  Also the default pins for
I2C(2) were 25/26 which are invalid for S3 and S2.

This pull request updates pin settings for C3, S3 and S2 I2C defaults
if not specified during the build.

See PR micropython#16956
See Issue micropython#17103

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
projectgus pushed a commit to ricksorensen/micropython that referenced this pull request May 16, 2025
This addresses issue micropython#17103.

The default I2C init does not require setting SCL or SDA but
the default I2C0 pins for C3, S3 conflict with the espressif
GPIO usage.

For the C3, pins 18/19 are for USB/JTAG. If used for
I2C() they will cause the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the
defaults do not seem to affect the REPL.

See PR micropython#16956
See Issue micropython#17103

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
dpgeorge pushed a commit to ricksorensen/micropython that referenced this pull request May 16, 2025
The default I2C init does not require setting SCL or SDA but the default
I2C0 pins for C3, S3 conflict with the espressif GPIO usage.

For the C3, pins 18/19 are for USB/JTAG.  If used for I2C() they will cause
the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the defaults do not
seem to affect the REPL.

See related micropython#16956.

Fixes issue micropython#17103.

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
lawrencedudley pushed a commit to lawrencedudley/micropython-esp32-pcnt that referenced this pull request May 29, 2025
The default I2C init does not require setting SCL or SDA but the default
I2C0 pins for C3, S3 conflict with the espressif GPIO usage.

For the C3, pins 18/19 are for USB/JTAG.  If used for I2C() they will cause
the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the defaults do not
seem to affect the REPL.

See related micropython#16956.

Fixes issue micropython#17103.

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
eliclement pushed a commit to eliclement/micropython that referenced this pull request Jun 2, 2025
The default I2C init does not require setting SCL or SDA but the default
I2C0 pins for C3, S3 conflict with the espressif GPIO usage.

For the C3, pins 18/19 are for USB/JTAG.  If used for I2C() they will cause
the REPL to hang on initialization of the I2C.

For the S3 pin 19 is allocated for USB/JTAG also but the defaults do not
seem to affect the REPL.

See related micropython#16956.

Fixes issue micropython#17103.

Signed-off-by: Rick Sorensen <rick.sorensen@gmail.com>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
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

Successfully merging this pull request may close these issues.

3 participants
0