Skip to content

Commit 70ff735

Browse files
committed
stmhal, cc3200: Change i2c.scan() method to scan addresses 0x08-0x77.
A standard I2C address is 7 bits but addresses 0b0000xxx and 0b1111xxx are reserved. The scan() method is changed to reflect this, along with the docs.
1 parent 26fd0ac commit 70ff735

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

cc3200/mods/pybi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_deinit_obj, pyb_i2c_deinit);
377377
STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
378378
pyb_i2c_check_init(&pyb_i2c_obj);
379379
mp_obj_t list = mp_obj_new_list(0, NULL);
380-
for (uint addr = 1; addr <= 127; addr++) {
380+
for (uint addr = 0x08; addr <= 0x77; addr++) {
381381
for (int i = 0; i < 3; i++) {
382382
if (pyb_i2c_scan_device(addr)) {
383383
mp_obj_list_append(list, mp_obj_new_int(addr));

docs/library/machine.I2C.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Methods
106106

107107
.. method:: i2c.scan()
108108

109-
Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
109+
Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of those that respond.
110110
Only valid when in master mode.
111111

112112
Constants

stmhal/i2c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ STATIC mp_obj_t pyb_i2c_is_ready(mp_obj_t self_in, mp_obj_t i2c_addr_o) {
475475
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_i2c_is_ready_obj, pyb_i2c_is_ready);
476476

477477
/// \method scan()
478-
/// Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
478+
/// Scan all I2C addresses from 0x08 to 0x77 and return a list of those that respond.
479479
/// Only valid when in master mode.
480480
STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
481481
pyb_i2c_obj_t *self = self_in;
@@ -486,7 +486,7 @@ STATIC mp_obj_t pyb_i2c_scan(mp_obj_t self_in) {
486486

487487
mp_obj_t list = mp_obj_new_list(0, NULL);
488488

489-
for (uint addr = 1; addr <= 127; addr++) {
489+
for (uint addr = 0x08; addr <= 0x77; addr++) {
490490
for (int i = 0; i < 10; i++) {
491491
HAL_StatusTypeDef status = HAL_I2C_IsDeviceReady(self->i2c, addr << 1, 10, 200);
492492
if (status == HAL_OK) {

0 commit comments

Comments
 (0)