void show_i2c(void) { I2C_DeInit(I2C3); TM_I2C_Init(I2C3, TM_I2C_PinsPack_1, 200000); for (int i=0;i<0xFF;i++) if (TM_I2C_IsDeviceConnected(I2C3, i)) printf("Device available at address: %02X\n\r",i); }
bool SFP_Init() { I2C_DeInit(SFP_I2C_PORT); TM_I2C_Init(SFP_I2C_PORT, SFP_I2C_PINS, SFP_I2C_SPEED); if (TM_I2C_IsDeviceConnected(SFP_I2C_PORT, SFP_I2C_ADDRESS)) { return true; } return false; }
bool SI7021_begin() { _si_exists = false; I2C_DeInit(SI7021_I2C_PORT); TM_I2C_Init(SI7021_I2C_PORT, SI7021_I2C_PINS, SI7021_I2C_SPEED); if (TM_I2C_IsDeviceConnected(SI7021_I2C_PORT, SI7021_ADDRESS)) { _si_exists = true; } return _si_exists; }
int main(void) { uint16_t i; uint8_t devices_found = 0; char buffer[20]; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds on board */ TM_DISCO_LedInit(); /* Init LCD on STM32F429-Discovery board */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Set background color */ TM_ILI9341_Fill(0x1234); /* Init I2C3 peripheral, PA8, PC9 */ TM_I2C_Init(I2C3, TM_I2C_PinsPack_1, 100000); /* Make search and show on LCD */ for (i = 2; i < 0xFF; i += 2) { /* Check if device detected */ if (TM_I2C_IsDeviceConnected(I2C3, i)) { /* Format string */ sprintf(buffer, "Device: %02X", i); /* Print to LCD */ TM_ILI9341_Puts(10, 10 + 12 * devices_found++, buffer, &TM_Font_7x10, 0x0000, 0x1234); } } while (1) { } }
void zspmStat (void) { //TM_I2C_Init(ZSPM_I2C, ZSPM_I2C_PINSPACK, ZSPM_I2C_SPEED); if (!TM_I2C_IsDeviceConnected(ZSPM_I2C, ZSPM_I2C_ADDRESS)) { TM_USART_Puts(MENU_USART,"ZMDI charger is not available\r\n"); } else { uint8_t test=0; uint8_t tmp=0; TM_I2C_Write(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG_ENABLE, BIT_EN_CFG); printf("Register 0: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_STATUS)); printf("Register 2: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG1)); printf("Register 3: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG2)); printf("Register 4: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG3)); printf("Register 5: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG4)); printf("Register 6: %x\n\r",TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG5)); test=TM_I2C_Read(ZSPM_I2C, ZSPM_I2C_ADDRESS, ZSPM_CONFIG1); tmp=(test&BIT_PRE_CHRG)>>6; if(tmp==0x00) printf("Precharge current 50mA\n\r"); else if (tmp==0x01) printf("Precharge current 100mA\n\r"); else if (tmp==0x02) printf("Precharge current 185mA\n\r"); else if (tmp==0x03) printf("Precharge current 370mA\n\r"); } }