BV I2C: add 10-bit slave address support
This commit is contained in:
parent
0cfde88015
commit
422b76cd75
|
@ -116,7 +116,7 @@ static bool busvoodoo_i2c_setup(char** prefix, const char* line)
|
|||
}
|
||||
}
|
||||
if (BUSVOODOO_I2C_SETTING_DONE==busvoodoo_i2c_setting) { // we have all settings, configure I2C
|
||||
i2c_master_setup(BUSVOODOO_I2C, false); // setup I2C
|
||||
i2c_master_setup(BUSVOODOO_I2C, busvoodoo_i2c_speed); // setup I2C
|
||||
if (busvoodoo_i2c_embedded_pullup) {
|
||||
busvoodoo_embedded_pullup(true); // set pull-up
|
||||
printf("use LV to set voltage\n");
|
||||
|
@ -160,7 +160,7 @@ static void busvoodoo_i2c_command_scan(void* argument)
|
|||
{
|
||||
(void)argument; // we won't use the argument
|
||||
if (!i2c_master_check_signals(BUSVOODOO_I2C)) { // ensure SCL and SDA are high
|
||||
printf("SCL or SDA is/are low. The signals need to be pulled up\n");
|
||||
printf("SCL or/and SDA are low. The signals need to be pulled up\n");
|
||||
if (busvoodoo_i2c_embedded_pullup) {
|
||||
printf("set pull-up voltage with LV\n");
|
||||
}
|
||||
|
@ -170,28 +170,37 @@ static void busvoodoo_i2c_command_scan(void* argument)
|
|||
led_off(); // switch LEDs off
|
||||
}
|
||||
printf("scanning for I2C slaves\n");
|
||||
uint16_t i2c_slaves = 0; // number of slaves found
|
||||
int16_t i2c_slaves = 0; // number of slaves found
|
||||
// check for I2C slaves by going through the address space
|
||||
for (uint16_t address=0; address < (1<<busvoodoo_i2c_addressbits); address++) {
|
||||
if (!i2c_master_start(BUSVOODOO_I2C)) { // send start condition
|
||||
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
printf("start condition failed\n"); // show error to user
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
i2c_slaves = -1; // remember error
|
||||
break; // stop scanning
|
||||
} else {
|
||||
busvoodoo_led_blue(100); // pulse blue LED to show transmission
|
||||
}
|
||||
if (i2c_master_select_slave(BUSVOODOO_I2C, address, false)) { // try to select slave
|
||||
if (i2c_master_select_slave(BUSVOODOO_I2C, address, 10==busvoodoo_i2c_addressbits, true)) { // try to select slave
|
||||
busvoodoo_led_red(100); // pulse red LED to show we found a slave
|
||||
printf((busvoodoo_i2c_addressbits>7) ? "0x%03x " : "0x%02x ", address); // display address
|
||||
i2c_slaves++; // increase slave count
|
||||
}
|
||||
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
|
||||
if (!i2c_master_stop(BUSVOODOO_I2C)) { // send stop condition
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
printf("start condition failed\n"); // show error to user
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
i2c_slaves = -1; // remember error
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i2c_slaves>0) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("%u slave(s) found\n", i2c_slaves); // show summary
|
||||
if (i2c_slaves>=0) {
|
||||
printf("%u slave(s) found\n", i2c_slaves); // show summary
|
||||
}
|
||||
}
|
||||
|
||||
static const struct menu_command_t busvoodoo_i2c_commands[] = {
|
||||
|
|
Loading…
Reference in New Issue