int main(void){ SystemInit(); TM_DELAY_Init(); TM_ILI9341_Init(); TM_ILI9341_SetLayer1(); /* Initialize USART2 at 115200 baud, TX: PD5, RX: PD6 */ TM_USART_Init(USART2, TM_USART_PinsPack_2, 115200); uint8_t wacc = 0x3A; // 0xA6 uint8_t racc = 0x3B; // 0xA7 // 0x2D POWER_CTL: Power-saving features control TM_I2C_Write(I2C2, wacc, 0x2D, 0x08); // 0x31 DATA_FORMAT: Data format control //TM_I2C_Write(I2C1, wacc, 0x31, 0x0B); // FULL_RES and +- 16g TM_I2C_Write(I2C2, wacc, 0x31, 0x01); // fixed resolution and +- 4g // 0x2C BW_RATE: Data rate and power mode control TM_I2C_Write(I2C2, wacc, 0x2C, 0x0A); char str[16] = {0}; sprintf(str, "delay = 100"); TM_USART_Puts(USART2, str); while(1){ TM_ILI9341_Fill(ILI9341_COLOR_WHITE); TM_ILI9341_Puts(30, 30, str, &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLUE2); uint8_t buff[6] = {0}; int16_t tri[3] = {0}; TM_I2C_ReadMulti(I2C2, racc, 0x32, buff, 6); // original read digit tri[0] = (int16_t) ((uint16_t)buff[1] << 8 | (uint16_t)buff[0]); tri[1] = (int16_t) ((uint16_t)buff[3] << 8 | (uint16_t)buff[2]); tri[2] = (int16_t) ((uint16_t)buff[5] << 8 | (uint16_t)buff[4]); float ftri[3] = {0}, divisor = 128.0f; ftri[0] = (float) tri[0] / divisor; ftri[1] = (float) tri[1] / divisor; ftri[2] = (float) tri[2] / divisor; sprintf(str, "%.3f,%.3f,%.3f\n\r", ftri[0], ftri[1], ftri[2]); TM_USART_Puts(USART2, str); TM_ILI9341_Puts(30, 50, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); Delayms(100); } }
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) { } }
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"); } }
void TM_DS1307_SetYear(uint8_t year) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_YEAR, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(year, 0, 99))); }
void TM_DS1307_SetMonth(uint8_t month) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_MONTH, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(month, 1, 12))); }
void TM_DS1307_SetDate(uint8_t date) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_DATE, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(date, 1, 31))); }
void TM_DS1307_SetDay(uint8_t day) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_DAY, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(day, 1, 7))); }
void TM_DS1307_SetHours(uint8_t hours) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_HOURS, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(hours, 0, 23))); }
void TM_DS1307_SetMinutes(uint8_t minutes) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_MINUTES, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(minutes, 0, 59))); }
void TM_DS1307_SetSeconds(uint8_t seconds) { TM_I2C_Write(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_SECONDS, TM_DS1307_Bin2Bcd(TM_DS1307_CheckMinMax(seconds, 0, 59))); }