| 12345678910111213141516171819202122232425262728293031323334353637 |
- #include "ti/driverlib/dl_i2c.h"
- #include "ti_msp_dl_config.h"
- #include <stdio.h>
- #include <stdint.h>
- /*
- Scans all the addresses of the peripherals:
- */
- void I2C_scanBus(I2C_Regs *i2c) {
- printf("Scanning I2C Bus...\n");
- // **Step 1: Reset I2C Controller if Busy**
- if (DL_I2C_getControllerStatus(i2c) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS) {
- printf("I2C Bus Busy! Resetting I2C Controller...\n");
- DL_I2C_disableController(i2c); // Disable I2C
- delay_cycles(20000);
- DL_I2C_enableController(i2c); // Re-enable I2C
- delay_cycles(20000);
- }
- // **Step 2: Scan I2C Bus**
- for (uint8_t addr = 0x08; addr < 0x78; addr++) { // Valid I2C Address Range
- DL_I2C_startControllerTransfer(i2c, addr, DL_I2C_CONTROLLER_DIRECTION_RX, 1);
- delay_cycles(5000);
-
- if (!(DL_I2C_getControllerStatus(i2c) & DL_I2C_CONTROLLER_STATUS_ERROR)) {
- printf("Device found at: 0x%02X\n", addr);
- }else {
- // Clear the error by resetting the I2C controller
- DL_I2C_disableController(i2c);
- DL_I2C_enableController(i2c);
- }
- }
- //printf("I2C Scan Complete!\n");
- }
|