示例#1
0
文件: main.c 项目: MaJerle/stm32f429
int main(void) {
	uint8_t data[] = {0, 1, 2};
	
	/* Initialize system */
	SystemInit();

	/* Initialize I2C, custom pinout with 100kHt serial clock */
	TM_I2C_Init(I2C1, TM_I2C_PinsPack_Custom, 100000);

	/* Write "5" at location 0x00 to slave with address ADDRESS */
	TM_I2C_Write(I2C1, ADDRESS, 0x00, 5);
	
	/**
	 * Write multi bytes to slave with address ADDRESS
	 * Write to registers starting from 0x00, get data in variable "data" and write 3 bytes
	 */
	TM_I2C_WriteMulti(I2C1, ADDRESS, 0x00, data, 3);
	
	/* Read single byte from slave with 0xD0 (1101 000 0) address and register location 0x00 */
	data[0] = TM_I2C_Read(I2C1, ADDRESS, 0x00);
	
	/**
	 * Read 3 bytes of data from slave with 0xD0 address
	 * First register to read from is at 0x00 location 
	 * Store received data to "data" variable
	 */
	TM_I2C_ReadMulti(I2C1, 0xD0, 0x00, data, 3);
	
	while (1) {

	}
}
示例#2
0
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");
  }
}
示例#3
0
uint8_t TM_DS1307_GetYear(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_YEAR));
}
示例#4
0
uint8_t TM_DS1307_GetMonth(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_MONTH));
}
示例#5
0
uint8_t TM_DS1307_GetDate(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_DATE));
}
示例#6
0
uint8_t TM_DS1307_GetHours(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_HOURS));
}
示例#7
0
uint8_t TM_DS1307_GetMinutes(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_MINUTES));
}
示例#8
0
uint8_t TM_DS1307_GetSeconds(void) {
	return TM_DS1307_Bcd2Bin(TM_I2C_Read(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_SECONDS));
}