예제 #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 TM_DS1307_GetDateTime(TM_DS1307_Time_t* time) {
	uint8_t data[7];
	TM_I2C_ReadMulti(TM_DS1307_I2C, TM_DS1307_I2C_ADDR, TM_DS1307_SECONDS, data, 7);
	
	time->seconds = TM_DS1307_Bcd2Bin(data[TM_DS1307_SECONDS]);
	time->minutes = TM_DS1307_Bcd2Bin(data[TM_DS1307_MINUTES]);
	time->hours = TM_DS1307_Bcd2Bin(data[TM_DS1307_HOURS]);
	time->day = TM_DS1307_Bcd2Bin(data[TM_DS1307_DAY]);
	time->date = TM_DS1307_Bcd2Bin(data[TM_DS1307_DATE]);
	time->month = TM_DS1307_Bcd2Bin(data[TM_DS1307_MONTH]);
	time->year = TM_DS1307_Bcd2Bin(data[TM_DS1307_YEAR]);
}
예제 #3
0
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);
	}

}
예제 #4
0
파일: _SFP.c 프로젝트: elmat-dev/Remote_Dev
void SFP_READ_DDMI_All_8bit (uint8_t* ddmi_buffer) {
  TM_I2C_ReadMulti(SFP_I2C_PORT, SFP_I2C_ADDRESS, temperature, ddmi_buffer, 10);
}
예제 #5
0
파일: _SFP.c 프로젝트: elmat-dev/Remote_Dev
float SFP_READ_DDMI_Single_float (SFP_READ_DDMI_Type_t type) {
  uint8_t buffer[2];
  TM_I2C_ReadMulti(SFP_I2C_PORT, SFP_I2C_ADDRESS, type, buffer, 2);
  return SFP_DDMI_RAW2Float(type,((buffer[0] << 8) | buffer[1]));
}
예제 #6
0
파일: _SFP.c 프로젝트: elmat-dev/Remote_Dev
// read single ddmi data ((for example temp, voltage, tx power, rx power)
// before issuing this command please be sure that correct sfp port was selected
uint16_t SFP_READ_DDMI_Single_16bit (SFP_READ_DDMI_Type_t type) {
	uint8_t buffer[2];
	TM_I2C_ReadMulti(SFP_I2C_PORT, SFP_I2C_ADDRESS, type, buffer, 2);
	return 	((buffer[0] << 8) | buffer[1]);
}