I2C: improve bus signal probing
This commit is contained in:
parent
1065a37cdb
commit
5fa6a58e9b
|
@ -229,7 +229,26 @@ bool i2c_master_check_signals(uint32_t i2c)
|
|||
while (true);
|
||||
}
|
||||
|
||||
return (0!=gpio_get(GPIO_PORT_SCL(i2c), GPIO_PIN_SCL(i2c)) && 0!=gpio_get(GPIO_PORT_SDA(i2c), GPIO_PIN_SDA(i2c)));
|
||||
// pull SDA and SDC low to check if there are pull-up resistors
|
||||
uint32_t sda_crl = GPIO_CRL(GPIO_PORT_SDA(i2c)); // backup port configuration
|
||||
uint32_t sda_crh = GPIO_CRH(GPIO_PORT_SDA(i2c)); // backup port configuration
|
||||
uint32_t sda_bsrr = GPIO_BSRR(GPIO_PORT_SDA(i2c)); // backup port configuration
|
||||
uint32_t scl_crl = GPIO_CRL(GPIO_PORT_SCL(i2c)); // backup port configuration
|
||||
uint32_t scl_crh = GPIO_CRH(GPIO_PORT_SCL(i2c)); // backup port configuration
|
||||
uint32_t scl_bsrr = GPIO_BSRR(GPIO_PORT_SCL(i2c)); // backup port configuration
|
||||
gpio_set_mode(GPIO_PORT_SDA(i2c), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_PIN_SDA(i2c)); // configure signal as pull down
|
||||
gpio_set_mode(GPIO_PORT_SCL(i2c), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO_PIN_SCL(i2c)); // configure signal as pull down
|
||||
gpio_clear(GPIO_PORT_SDA(i2c), GPIO_PIN_SDA(i2c)); // pull down
|
||||
gpio_clear(GPIO_PORT_SCL(i2c), GPIO_PIN_SCL(i2c)); // pull down
|
||||
bool to_return = (0!=gpio_get(GPIO_PORT_SCL(i2c), GPIO_PIN_SCL(i2c)) && 0!=gpio_get(GPIO_PORT_SDA(i2c), GPIO_PIN_SDA(i2c))); // check if the signals are still pulled high by external stronger pull-up resistors
|
||||
GPIO_CRL(GPIO_PORT_SDA(i2c)) = sda_crl; // restore port configuration
|
||||
GPIO_CRH(GPIO_PORT_SDA(i2c)) = sda_crh; // restore port configuration
|
||||
GPIO_BSRR(GPIO_PORT_SDA(i2c)) = sda_bsrr; // restore port configuration
|
||||
GPIO_CRL(GPIO_PORT_SCL(i2c)) = scl_crl; // restore port configuration
|
||||
GPIO_CRH(GPIO_PORT_SCL(i2c)) = scl_crh; // restore port configuration
|
||||
GPIO_BSRR(GPIO_PORT_SCL(i2c)) = scl_bsrr; // restore port configuration
|
||||
|
||||
return to_return;
|
||||
}
|
||||
|
||||
void i2c_master_reset(uint32_t i2c)
|
||||
|
|
Loading…
Reference in New Issue