void get_accel(float *zValue)
{
	uint8_t buf;
	uint8_t zl;
	uint8_t zh;
	volatile HAL_StatusTypeDef error;

	buf = 0x2C;						//Low Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC_acel, &buf,sizeof(buf),1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, (uint16_t)adress_LSM303DLHC_acel, &zl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf = 0x2D;						//High Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC_acel, &buf,sizeof(buf),1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, (uint16_t)adress_LSM303DLHC_acel, &zh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}


	*zValue = (float)((int16_t)((zh<<8) | zl))*0.000649;
}
Exemplo n.º 2
0
void CMagnetometer::readZRawValue()
{
	UInt8 zLowByte		= 0x00U;
	UInt8 zHighByte		= 0x00U;
	UInt8 zLowAddress  	= sReadZLowValue;
	UInt8 zHighAddress 	= sReadZHighValue;

	HAL_I2C_Master_Transmit(&mI2CHandle, sDeviceAddress, &(zLowAddress), 1U, 5U);
	HAL_I2C_Master_Receive(&mI2CHandle, sDeviceAddress, &zLowByte, sizeof(zLowByte), 5U);
	HAL_I2C_Master_Transmit(&mI2CHandle, sDeviceAddress, &(zHighAddress), 1U, 5U);
	HAL_I2C_Master_Receive(&mI2CHandle, sDeviceAddress, &zHighByte, sizeof(zHighByte), 5U);
	mZRawValue = (static_cast<UInt16>(zLowByte) | (static_cast<UInt16>(zHighByte) << 8U));
}
Exemplo n.º 3
0
UInt16 CMagnetometer::getXOffset()
{
	UInt8 xLowByte 		= 0x00U;
	UInt8 xHighByte 	= 0x00U;
	UInt8 xLowAddress  	= sOFFSET_X_L_M;
	UInt8 xHighAddress 	= sOFFSET_X_H_M;

	HAL_I2C_Master_Transmit(&mI2CHandle, sDeviceAddress, &(xLowAddress), 1U, 5U);
	HAL_I2C_Master_Receive(&mI2CHandle, sDeviceAddress, &xLowByte, sizeof(xLowByte), 5U);
	HAL_I2C_Master_Transmit(&mI2CHandle, sDeviceAddress, &(xHighAddress), 1U, 5U);
	HAL_I2C_Master_Receive(&mI2CHandle, sDeviceAddress, &xHighByte, sizeof(xHighByte), 5U);
	return (static_cast<UInt16>(xLowByte) | (static_cast<UInt16>(xHighByte) << 8U));
}
Exemplo n.º 4
0
STATIC mp_obj_t pyb_i2c_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
    pyb_i2c_obj_t *self = args[0];

    // parse args
    mp_arg_val_t vals[PYB_I2C_RECV_NUM_ARGS];
    mp_arg_parse_all(n_args - 1, args + 1, kw_args, PYB_I2C_RECV_NUM_ARGS, pyb_i2c_recv_args, vals);

    // get the buffer to receive into
    mp_buffer_info_t bufinfo;
    mp_obj_t o_ret = pyb_buf_get_for_recv(vals[0].u_obj, &bufinfo);

    // receive the data
    HAL_StatusTypeDef status;
    if (in_master_mode(self)) {
        if (vals[1].u_int == PYB_I2C_MASTER_ADDRESS) {
            nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "addr argument required"));
        }
        mp_uint_t i2c_addr = vals[1].u_int << 1;
        status = HAL_I2C_Master_Receive(self->i2c, i2c_addr, bufinfo.buf, bufinfo.len, vals[2].u_int);
    } else {
        status = HAL_I2C_Slave_Receive(self->i2c, bufinfo.buf, bufinfo.len, vals[2].u_int);
    }

    if (status != HAL_OK) {
        // TODO really need a HardwareError object, or something
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_Exception, "HAL_I2C_xxx_Receive failed with code %d", status));
    }

    // return the received data
    if (o_ret == MP_OBJ_NULL) {
        return vals[0].u_obj;
    } else {
        return mp_obj_str_builder_end(o_ret);
    }
}
Exemplo n.º 5
0
void AP_ReadBuffer(uint8_t RegAddr, uint8_t *aRxBuffer, uint8_t RXBUFFERSIZE)
{
    /* -> Lets ask for register's address */
    AP_WriteBuffer(&RegAddr, 1);
 
    /* -> Put I2C peripheral in reception process */
    while(HAL_I2C_Master_Receive(&AP_I2C_HANDLE, AP_I2C_ADDR, aRxBuffer, (uint16_t)RXBUFFERSIZE, (uint32_t)1000) != HAL_OK)
    {
        /* Error_Handler() function is called when Timeout error occurs.
         * When Acknowledge failure occurs (Slave don't acknowledge it's address)
         * Master restarts communication
         */
        if (HAL_I2C_GetError(&AP_I2C_HANDLE) != HAL_I2C_ERROR_AF)
        {
            //DEBUG(3, "In I2C::WriteBuffer -> error");
            //Error_Handler(4);
					PUTZ_ASSERT(false);
        }
    }
 
    /* -> Wait for the end of the transfer */
    /* Before starting a new communication transfer, you need to check the current
     * state of the peripheral; if it’s busy you need to wait for the end of current
     * transfer before starting a new one.
     * For simplicity reasons, this example is just waiting till the end of the
     * transfer, but application may perform other tasks while transfer operation
     * is ongoing.
     **/
    while (HAL_I2C_GetState(&AP_I2C_HANDLE) != HAL_I2C_STATE_READY)
    {
    }
}
Exemplo n.º 6
0
uint8_t ADXL345::readByte(uint8_t address){
	uint8_t data = 0;
	/* first send Slave address and register address to read form */
	HAL_I2C_Master_Transmit(&this->i2c2, (uint16_t)ADXL_WRITE, &address, 1, 1000);
	/* receive 1 byte data */
	HAL_I2C_Master_Receive(&this->i2c2, (uint16_t)ADXL_READ, &data, 1, 1000);
	return data;
}
Exemplo n.º 7
0
int VL6180x_I2CRead(VL6180xDev_t addr, uint8_t *buff, uint8_t len) {
    int status;
    status = HAL_I2C_Master_Receive(i2c_bus, addr, buff, len, def_i2c_time_out);
    if (status) {
        XNUCLEO6180XA1_I2C1_Init(&hi2c1);
    }

    return status;
}
Exemplo n.º 8
0
/**
 * @brief	Transmits data as a master to a slave, used in ISR
 * @param	DevAddress: Address for the slave device
 * @param	Data: Pointer to a buffer where data will be stored
 * @param	Size: Size of the amount of data to receive
 * @retval	None
 */
void I2C2_ReceiveFromISR(uint8_t DevAddress, uint8_t* pBuffer, uint16_t Size)
{
	/* Try to take the semaphore in case some other process is using the device */
	if (xSemaphoreTakeFromISR(xSemaphore, NULL) == pdTRUE)
	{
		HAL_I2C_Master_Receive(&I2C_Handle, (uint16_t)(DevAddress << 1), pBuffer, Size, 500); /* TODO: Check timeout value */
		xSemaphoreGiveFromISR(xSemaphore, NULL);
	}
}
Exemplo n.º 9
0
Arquivo: sccb.c Projeto: 12019/openmv
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
{
    uint8_t data=0;

    __disable_irq();
    if((HAL_I2C_Master_Transmit(&I2CHandle, slv_addr, &reg, 1, TIMEOUT) != HAL_OK)
    || (HAL_I2C_Master_Receive(&I2CHandle, slv_addr, &data, 1, TIMEOUT) != HAL_OK)) {
        data=0xFF;
    }
    __enable_irq();
    return data;
}
Exemplo n.º 10
0
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
    if (length == 0) return 0;
  
    I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);

    // Reception process with 5 seconds timeout
    if (HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)address, (uint8_t *)data, length, 5000) != HAL_OK) {
        return 0; // Error
    }

    return length;
}
Exemplo n.º 11
0
void BQ27542_read(unsigned char cmd, unsigned int bytes)
{
  unsigned char tx[1];

  tx[0] = cmd;
  if(HAL_I2C_Master_Transmit(&hi2c1, bq27542_ADDR, tx, 1, 0xFFFF) != HAL_OK){
	  BQ27542_error();
  }
  if(HAL_I2C_Master_Receive(&hi2c1, bq27542_ADDR, RxData, bytes, 0xFFFF) != HAL_OK){
	  BQ27542_error();
  }

}
Exemplo n.º 12
0
//Read n_bytes of data from device
int I2C_receive_data(I2C_Device_t *device, uint8_t *p_data, uint16_t n_bytes) {
    int ret;
    I2C_HandleTypeDef *hi2c;
    if (device->I2Cx == I2C1) {
        hi2c = &hi2c1;
    } else {
        return -1; // Not implemented
    }


    ret = HAL_I2C_Master_Receive(hi2c, device->address, p_data,n_bytes,device->timeout);
    return ret;
}
Exemplo n.º 13
0
bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
{
    HAL_StatusTypeDef status;

    if(reg_ == 0xFF)
        status = HAL_I2C_Master_Receive(&i2cHandle[device].Handle,addr_ << 1,buf, len, I2C_DEFAULT_TIMEOUT);
    else
        status = HAL_I2C_Mem_Read(&i2cHandle[device].Handle,addr_ << 1, reg_, I2C_MEMADD_SIZE_8BIT,buf, len, I2C_DEFAULT_TIMEOUT);

    if(status != HAL_OK)
        return i2cHandleHardwareFailure(device);

    return true;
}
Exemplo n.º 14
0
/**
  * @brief  Read a register of the device through I2C.
  * @param  Addr: Device address on I2C Bus.  
  * @param  pBuffer: The address to store the read data 
  * @param  Length: buffer size to be read
  * @retval None
  */
static HAL_StatusTypeDef I2C2_ReceiveData(uint16_t Addr, uint8_t * pBuffer, uint16_t Length)
  {
  HAL_StatusTypeDef status = HAL_OK;
  
  status = HAL_I2C_Master_Receive(&heval_I2c2, Addr, pBuffer, Length, I2c2Timeout); 

  /* Check the communication status */
  if(status != HAL_OK)
  {
    /* Execute user timeout callback */
    I2C2_Error();
  }        
  return status;
}
Exemplo n.º 15
0
void test_EasterEgg(void)
{
	ExpanderSetbit(7,0);
	HAL_Delay(100);
	ExpanderSetbit(7,1);
	HAL_Delay(100);

	ssd1306Init(0);
	ssd1306ClearScreen();
	ssd1306Refresh();

	// I2C
	uint8_t aTxBuffer[3]; // = {control, c};
	aTxBuffer[0] = 0x0;
	aTxBuffer[1] = 0x1;
	aTxBuffer[2] = 0x5;

	uint8_t aRxBuffer[1]; // = {control, c};
	aRxBuffer[0] = 0x0;

	ssd1306ClearScreen();

	while(HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)0x50<<1, (uint8_t*)aTxBuffer, 3, 10000)!= HAL_OK)
	{
	  /* Error_Handler() function is called when Timout error occurs.
		 When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
		 Master restarts communication */
	  if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
	  {
		  ssd1306PrintInt(10,  15, "Bad Send", 0, &Font_5x8);
	  }

	}

	while(HAL_I2C_Master_Receive(&hi2c1, (uint16_t)0x50<<1, (uint8_t*)aRxBuffer, 1, 10000)!= HAL_OK)
	{
	  /* Error_Handler() function is called when Timout error occurs.
		 When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
		 Master restarts communication */
	  if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
	  {
		  ssd1306PrintInt(10,  25, "Bad recv", 0, &Font_5x8);
	  }

	}

	ssd1306PrintInt(10,  35, "Fini : ", aRxBuffer[0], &Font_5x8);
	ssd1306Refresh();

}
Exemplo n.º 16
0
/* Gets register values for accel, gyro and temp data and puts them into correct format */
void IMUGetMotion()
{
	uint8_t address[] = {0x3B}; /* Start Address */
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)address, 1, 100);
	HAL_I2C_Master_Receive(&hi2c1, IMU_ADDRESS<<1, (uint8_t *)rawIMU, 14, 200);
    
    Motion.x = (float) ( (int16_t)((rawIMU[0] << 8) | rawIMU[1]) ) / accelConvFactor;
    Motion.y = (float) ( (int16_t)((rawIMU[2] << 8) | rawIMU[3]) ) / accelConvFactor;
    Motion.z = (float) ( (int16_t)((rawIMU[4] << 8) | rawIMU[5]) ) / accelConvFactor;
    
    Motion.temp = ((float) ( (int16_t)((rawIMU[6] << 8) | rawIMU[7]) ) + 12412.0) / 340.0;

    Motion.roll  = (float) ( (int16_t)((rawIMU[8]  << 8) | rawIMU[9] ) ) / gyroConvFactor;
    Motion.pitch = (float) ( (int16_t)((rawIMU[10] << 8) | rawIMU[11]) ) / gyroConvFactor;
    Motion.yaw   = (float) ( (int16_t)((rawIMU[12] << 8) | rawIMU[13]) ) / gyroConvFactor;
}
Exemplo n.º 17
0
uint8_t SCCB_Read(uint8_t addr)
{
    uint8_t data=0;

    __disable_irq();
    if (HAL_I2C_Master_Transmit(&I2CHandle, SLAVE_ADDR, &addr, 1, TIMEOUT) != HAL_OK) {
        data = 0xFF;
        goto error_w;
    }
    if (HAL_I2C_Master_Receive(&I2CHandle, SLAVE_ADDR, &data, 1, TIMEOUT) != HAL_OK) {
        data = 0xFF;
    }
error_w:
    __enable_irq();
    return data;
}
Exemplo n.º 18
0
uint8_t tca9545_get(){
	uint8_t buf = 0;
	uint8_t retry = 0;
	while (HAL_OK != HAL_I2C_Master_Receive(&hi2c1, TCA9545_ADDR, &buf, 1, TCA9545_TIMEOUT))
	{
		retry++;
		if (retry > TCA9545_retry)
		{
			DEBUG_ERROR("Failed to connect TCA9545!\n");
			return 0;
		}
		DEBUG_ERROR("TCA9545 not found! retry\n");
		tca9545_reset();
	}
	return	buf;
}
Exemplo n.º 19
0
uint8_t SCCB_Read(uint8_t addr)
{
    uint8_t data=0;
		uint8_t res =  HAL_I2C_Master_Transmit(&hnd, SLAVE_ADDR, &addr, 1, TIMEOUT);
	printf("res: %u",res);
    //__disable_irq();
    if (res != HAL_OK) {
        data = 0xFF;
        goto error_w;
    }
    if (HAL_I2C_Master_Receive(&hnd, SLAVE_ADDR, &data, 1, TIMEOUT) != HAL_OK) {
        data = 0xFF;
    }
error_w:
    //__enable_irq();
    return data;
}
Exemplo n.º 20
0
void PCF8563_read_datetime(date_time_t volatile *dt)
{
union{  
  struct{
    uint8_t bcd_sec;
    uint8_t bcd_min;
    uint8_t bcd_hrs;
    uint8_t bcd_day;
    uint8_t wek;   
    uint8_t bcd_mon;
    uint8_t bcd_yer;
  }Fields;
  uint8_t arrWeekDays[7];
}Time;
uint8_t data = 0;

//  LowVoltage = VL_sec.7
//  Century    = C_Mon.7

// Disable interrupts so the i2c process is not disrupted.
data = PCF8563_SECONDS_REG;

 HAL_I2C_Master_Transmit(&hi2c2, PCF8563_WRITE_ADDRESS, &data, 1, 200);
// Read the date/time registers inside the PCF8563.

HAL_I2C_Master_Receive(&hi2c2, PCF8563_READ_ADDRESS, Time.arrWeekDays, 7, 100); 
 
// Convert the date/time values from BCD to
// unsigned 8-bit integers.  Unpack the bits
// in the PCF8563 registers where required.
 Time.Fields.bcd_sec &= 0x7F;
 Time.Fields.bcd_mon &= 0x7F;
 
dt->seconds = bcd2bin(Time.Fields.bcd_sec);   
dt->minutes = bcd2bin(Time.Fields.bcd_min);     
dt->hours   = bcd2bin(Time.Fields.bcd_hrs & 0x3F);
dt->day     = bcd2bin(Time.Fields.bcd_day & 0x3F);
dt->month   = bcd2bin(Time.Fields.bcd_mon & 0x1F);
dt->weekday =    Time.Fields.wek & 0x07;
dt->year    = bcd2bin(Time.Fields.bcd_yer);   

}
Exemplo n.º 21
0
void i2c_send1(void)
{
    char buf[] = {0x00, 0x00};
    if(HAL_I2C_Master_Transmit(&hi2c, (uint16_t)0xAE, (uint8_t*)buf, 2, 10000) != HAL_OK)
    {
        if (HAL_I2C_GetError(&hi2c) != HAL_I2C_ERROR_AF)
        {
            led_on();
            return;
        }
    }
    while(HAL_I2C_Master_Receive(&hi2c, (uint16_t)0xAF, (uint8_t *)buf, 2, 10000) != HAL_OK)
    {
        if (HAL_I2C_GetError(&hi2c) != HAL_I2C_ERROR_AF)
        {
            led_on();
            return;
        }
    }
}
Exemplo n.º 22
0
void i2c (){

		
	I2C_tx_buffer[0]=(uint8_t)MODE;
	
	HAL_I2C_Master_Transmit(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_tx_buffer[0], 1,100);
	//HAL_Delay(10);
	HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
		//HAL_I2C_Master_Transmit_IT(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_tx_buffer[0], 1);
		while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY); //waiting for the end of current transfer before starting a new one
	

		HAL_I2C_Master_Receive(&hi2c1, (uint16_t) I2C_ADDRESS, &I2C_rx_buffer[0], 1,100);
		while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY); //waiting for the end of current transfer

	for(int i=0;i<10;i++){
		HAL_GPIO_TogglePin(Kimenet_GPIO_Port,Kimenet_Pin);
		HAL_Delay (500);
	}
	
}
/**
  * @brief Reads the word in temperature measurement register of the device and returns the current status of the specified address.
  * @param  h_i2c: pointer to the i2c bus peripheral handle that the temperature sensor ics are connected.
  * @param  device_i2c_address: i2c adress of the sensor to request measurement.
  * @param  receive_word: pointer to the word where the measurement register will be returned.
  * @retval TC_74_STATUS.
  */
 TC_74_STATUS TC74_read_device_temperature(I2C_HandleTypeDef *h_i2c, uint8_t device_i2c_address, int8_t *receive_word ) {

	 TC_74_STATUS device_status;
	 /*Read temperature*/
	 /*master sends the slave's temperature register adrress to read back*/
	 uint8_t transmit_packet = TC74_TEMPERATURE_REGISTER;
	 if (HAL_I2C_Master_Transmit(h_i2c, device_i2c_address, (uint8_t*)&transmit_packet, 1, 100) != HAL_OK) {
		 //soft error handle
		 device_status = DEVICE_ERROR;
	 }

 	 if (HAL_I2C_Master_Receive(h_i2c, device_i2c_address, receive_word, 1, 100) != HAL_OK) {
		 //soft error handle
 		device_status = DEVICE_ERROR;
	 }

 	 if(device_status!=DEVICE_ERROR){
 		 device_status = TC74_read_device_status(h_i2c, device_i2c_address);
 	 }

	 return device_status;
 }
 /**
   * @brief Reads the word in device status register of the device and returns the current status of the specified address.
   * @param  h_i2c: pointer to the i2c bus peripheral handle that the temperature sensor ics are connected.
   * @param  device_i2c_address: i2c adress of the sensor to request measurement.
   * @param  receive_word: pointer to the word where the measurement register will be returned.
   * @retval TC_74_STATUS.
   */
 TC_74_STATUS TC74_read_device_status(I2C_HandleTypeDef *h_i2c, uint8_t device_i2c_address ) {

	 TC_74_STATUS device_status = DEVICE_STATUS_LAST_VALUE;
	 HAL_StatusTypeDef res;
	/*Read control regiter*/
	/*master sends the slave's temperature register adrress to read back*/
	uint8_t transmit_packet[2] = { TC74_CONFIGURATION_REGISTER, TC74_AWAKE_COMMAND };
	if ((res=HAL_I2C_Master_Transmit(h_i2c, device_i2c_address, transmit_packet, 1, 100) )!= HAL_OK) {
		//soft error handle
		device_status = DEVICE_ERROR;
	}

	uint8_t receive_word;
 	if ((res=HAL_I2C_Master_Receive(h_i2c, device_i2c_address, &receive_word, 1, 100)) != HAL_OK) {
		//soft error handle
 		device_status = DEVICE_ERROR;
	}

 	if(device_status!=DEVICE_ERROR){
 		if ((receive_word&0b10111111) == TC74_STANDBY_COMMAND){
 			device_status = DEVICE_STANDBY;
 		}
 		else if((receive_word&0b10111111) == TC74_AWAKE_COMMAND){
 			device_status = DEVICE_NORMAL_DATA_NOT_READY;
 			/*check data ready bit*/
 			if ((receive_word&0b11011111) == TC74_DATA_READY_FLAG){
 				device_status = DEVICE_NORMAL_DATA_READY;
 			}

 		}
 		else{
 			device_status = DEVICE_STATUS_LAST_VALUE;
 		}
 	}


	return device_status;
}
Exemplo n.º 25
0
bool i2cRead(I2CDevice device, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
{
    if (device == I2CINVALID || device > I2CDEV_COUNT) {
        return false;
    }

    I2C_HandleTypeDef *pHandle = &i2cDevice[device].handle;

    if (!pHandle->Instance) {
        return false;
    }

    HAL_StatusTypeDef status;

    if (reg_ == 0xFF)
        status = HAL_I2C_Master_Receive(pHandle ,addr_ << 1, buf, len, I2C_DEFAULT_TIMEOUT);
    else
        status = HAL_I2C_Mem_Read(pHandle, addr_ << 1, reg_, I2C_MEMADD_SIZE_8BIT,buf, len, I2C_DEFAULT_TIMEOUT);

    if (status != HAL_OK)
        return i2cHandleHardwareFailure(device);

    return true;
}
Exemplo n.º 26
0
/* Configs the IMU with various settings for sensitivity */
void IMUConfig(int accelrange, int gyrorange)
{
	/* Figures out what settings to apply */
	     if (accelrange == 4)  {accelRegister = 0x08; accelConvFactor = 8192; }
	else if (accelrange == 8)  {accelRegister = 0x10; accelConvFactor = 4096; }
	else if (accelrange == 16) {accelRegister = 0x18; accelConvFactor = 2048; }
	   else  /*Defults to 2*/  {accelRegister = 0x00; accelConvFactor = 16384;}

	     if (gyrorange == 500) {gyroRegister = 0x08; gyroConvFactor = 65.5; }
	else if (gyrorange == 1000){gyroRegister = 0x10; gyroConvFactor = 32.8; }
	else if (gyrorange == 2000){gyroRegister = 0x18; gyroConvFactor = 16.4; }
	   else /*Defults to 250*/ {gyroRegister = 0x00; gyroConvFactor = 131;  }
	
	/* Does the configuration */
	uint8_t addressAndData[2] = {IMU_WHOAMI, 0x00};
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)addressAndData, 1, 100);	/* This should return the WHOAMI register */
	HAL_I2C_Master_Receive(&hi2c1, IMU_ADDRESS<<1, (uint8_t *)rawIMU, 1, 100);
	if (rawIMU[0] == 0x68){print("\r\n[OK] IMU Found");}
	else{print("\r\n[ERROR] IMU not found");}
 
	addressAndData[0] = IMU_CFG;
	addressAndData[1] = 0x00;
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)addressAndData, 2, 100); /* Reset LPF */

	addressAndData[0] = IMU_ACCEL_CFG;
	addressAndData[1] = accelRegister;
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)addressAndData, 2, 100);

	addressAndData[0] = IMU_ACCEL_CFG;
	addressAndData[1] = accelRegister;
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)addressAndData, 2, 100);

	addressAndData[0] = IMU_PWR_MGMT1;
	addressAndData[1] = 0x00;
	HAL_I2C_Master_Transmit(&hi2c1, IMU_ADDRESS<<1, (uint8_t*)addressAndData, 2, 100); /* Bring IMU out of reset */
}
Exemplo n.º 27
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure LED3 and LED4 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /*##-1- Configure the I2C peripheral #######################################*/
  I2cHandle.Instance             = I2Cx;

  I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_10BIT;
  I2cHandle.Init.ClockSpeed      = 400000;
  I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  I2cHandle.Init.DutyCycle       = I2C_DUTYCYCLE_16_9;
  I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  I2cHandle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLE;
  I2cHandle.Init.OwnAddress1     = I2C_ADDRESS;
  I2cHandle.Init.OwnAddress2     = 0xFE;

  if(HAL_I2C_Init(&I2cHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

#ifdef MASTER_BOARD

  /* Configure USER Button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);

  /* Wait for USER Button press before starting the Communication */
  while (BSP_PB_GetState(BUTTON_KEY) != 1)
  {
  }

  /* Wait for USER Button release before starting the Communication */
  while (BSP_PB_GetState(BUTTON_KEY) != 0)
  {
  }

  /* The board sends the message and expects to receive it back */

  /*##-2- Start the transmission process #####################################*/
  /* While the I2C in reception process, user can transmit data through
     "aTxBuffer" buffer */
  /* Timeout is set to 10S */
  while(HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
  {
    /* Error_Handler() function is called when Timeout error occurs.
       When Acknowledge failure occurs (Slave don't acknowledge it's address)
       Master restarts communication */
    if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
    {
      Error_Handler();
    }
  }

  /* Turn LED3 on: Transfer in Transmission process is correct */
  BSP_LED_On(LED3);

  /* Wait for USER Button press before starting the Communication */
  while (BSP_PB_GetState(BUTTON_KEY) != 1)
  {
  }

  /* Wait for USER Button release before starting the Communication */
  while (BSP_PB_GetState(BUTTON_KEY) != 0)
  {
  }

  /*##-3- Put I2C peripheral in reception process ############################*/
  /* Timeout is set to 10S */
  while(HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK)
  {
    /* Error_Handler() function is called when Timeout error occurs.
       When Acknowledge failure occurs (Slave don't acknowledge it's address)
       Master restarts communication */
    if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
    {
      Error_Handler();
    }
  }

  /* Turn LED3 off: Transfer in reception process is correct */
  BSP_LED_Off(LED3);

#else

  /* The board receives the message and sends it back */

  /*##-2- Put I2C peripheral in reception process ############################*/
  /* Timeout is set to 10S  */
  if(HAL_I2C_Slave_Receive(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK)
  {
    /* Transfer error in reception process */
    Error_Handler();
  }

  /* Turn LED3 on: Transfer in reception process is correct */
  BSP_LED_On(LED3);

  /*##-3- Start the transmission process #####################################*/
  /* While the I2C in reception process, user can transmit data through
     "aTxBuffer" buffer */
  /* Timeout is set to 10S */
  if(HAL_I2C_Slave_Transmit(&I2cHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
  {
    /* Transfer error in transmission process */
    Error_Handler();
  }

  /* Turn LED3 off: Transfer in transmission process is correct */
  BSP_LED_Off(LED3);

#endif /* MASTER_BOARD */

  /*##-4- Compare the sent and received buffers ##############################*/
  if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))
  {
    /* Processing Error */
    Error_Handler();
  }

  /* Infinite loop */
  while (1)
  {
  }
}
Exemplo n.º 28
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    sAPP_PIXARM_READ_DATA* data;
    sAPP_PIXARM_READ_REQ* req;
    uint8_t iter = 1;
    HAL_StatusTypeDef stat;
    
    /* STM32F4xx HAL library initialization:
        - Configure the Flash prefetch, instruction and Data caches
        - Configure the Systick to generate an interrupt each 1 msec
        - Set NVIC Group Priority to 4
        - Global MSP (MCU Support Package) initialization
        */
    HAL_Init();
    
    /* Configure LED4, LED5 and LED6 */
    BSP_LED_Init(LED4);
    BSP_LED_Init(LED5);
    BSP_LED_Init(LED6);
    BSP_LED_Init(LED3);
    
    /* Configure the system clock to 168 MHz */
    SystemClock_Config();
    
    /*##-1- Configure the I2C peripheral ######################################*/
    I2cHandle.Instance             = I2Cx;
    
    I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
    I2cHandle.Init.ClockSpeed      = 400000;
    I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    I2cHandle.Init.DutyCycle       = I2C_DUTYCYCLE_16_9;
    I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    I2cHandle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLE;
    I2cHandle.Init.OwnAddress1     = I2C_ADDRESS;
    I2cHandle.Init.OwnAddress2     = 0x0;
    
    if(HAL_I2C_Init(&I2cHandle) != HAL_OK)
    {
        /* Initialization Error */
        Error_Handler();    
    }
    
    Test_Log_Init();
    
    /* Configure USER Button */
    BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
    
    /* Wait for USER Button press before starting the Communication */
    while (BSP_PB_GetState(BUTTON_KEY) != 1)
    {
    }
    
    /* Wait for USER Button release before starting the Communication */
    while (BSP_PB_GetState(BUTTON_KEY) != 0)
    {
    }
    
    BSP_LED_On(LED3);
    BSP_LED_Off(LED6);
    BSP_LED_Off(LED4);
    
    /* The board sends the message and expects to receive it back */
    Test_Log("Starting I2C Handshake.\r\n");
    
    /*##-2- Start the transmission process #####################################*/  
    /* Timeout is set to 10S */
    while(HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
    {
        /* Error_Handler() function is called when Timeout error occurs.
        When Acknowledge failure occurs (Slave don't acknowledge it's address)
        Master restarts communication */
        if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
        {
            Error_Handler();
        }
    }
    
    
    
    /*##-3- Put I2C peripheral in reception process ############################*/ 
    /* Timeout is set to 10S */ 
    while((stat = HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, aRxBuffer, RXBUFFERSIZE, 10000)) != HAL_OK)
    {
        /* Error_Handler() function is called when Timeout error occurs.
        When Acknowledge failure occurs (Slave don't acknowledge it's address)
        Master restarts communication */
        if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
        {
        Error_Handler();
        }   
    }
    
    /* Turn LED6 on: Transfer in reception process is correct */
    BSP_LED_On(LED6);
    
    /*##-4- Compare the sent and received buffers ##############################*/
    //if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))
    //{
    //    /* Processing Error */
    //    Error_Handler();
    //}
    
    Test_Log("Finished I2C Handshaking.\r\n");
    
    
    req = (sAPP_PIXARM_READ_REQ *) bTxBuffer;
    data = (sAPP_PIXARM_READ_DATA *) aRxBuffer;
    
    /* Infinite loop */  
    while (1)
    {
        
        /*##-2- Start the transmission process #####################################*/  
        /* Timeout is set to 10S */
        Test_Log("Iteration %d\r\n", iter);
        while((stat = HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, bTxBuffer, TXBUFFERSIZE, 10000)) !=  HAL_OK)
        {
            /* Error_Handler() function is called when Timeout error occurs.
            When Acknowledge failure occurs (Slave don't acknowledge it's address)
            Master restarts communication */
            if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
            {
                Test_Log("Error during Transmission. Transmission Error no. %d\r\n", stat);
                Test_Log("Error During Transmission.\r\n");
                Error_Handler();
            }
            //Test_Log("Transmit Failed. Error no. %d. Trying again.\r\n", stat);
        }
        
        while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
        {
        }
        
        req->rotation_absolute = 0;
        
        /*##-3- Put I2C peripheral in reception process ############################*/ 
        /* Timeout is set to 10S */ 
        while((stat = HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, aRxBuffer, RXBUFFERSIZE, 10000)) != HAL_OK)
        {
            /* Error_Handler() function is called when Timeout error occurs.
            When Acknowledge failure occurs (Slave don't acknowledge it's address)
            Master restarts communication */
            if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
            {
                Test_Log("Error during Reception. Receive Error no. %d\r\n", stat);
                Test_Log("Error during Reception. I2C Error no. %d\r\n", HAL_I2C_GetError(&I2cHandle));
                Error_Handler();
            }
            //Test_Log("Receive Failed. Error no. %d. Trying again.\r\n", stat);
        }
        
        while (HAL_I2C_GetState(&I2cHandle) != HAL_I2C_STATE_READY)
        {
        }
        
        // Validate the data
        if (data->cmd != 0x04)
        {
            Test_Log("CMD incorrect on packet. Received %x.\r\n", data->cmd);
        }
        if (data->x_intensity != 4)
        {
            Test_Log("X incorrect on packet. Received %d.\r\n", data->x_intensity);
        }
        if (data->y_intensity != 4)
        {
            Test_Log("Y incorrect on packet. Received %d.\r\n", data->y_intensity);
        }
        if (data->z_intensity != 4)
        {
            Test_Log("Z incorrect on packet. Received %d.\r\n", data->z_intensity);
        }
        if (data->rotation_absolute != (int16_t) 36000)
        {
            Test_Log("Rotation in packet was %d.\r\n", data->rotation_absolute);
            Test_Log("Replying with same rotation.\r\n");
            req->rotation_absolute = data->rotation_absolute;
        }
        if (data->flag != 0xFF)
        {
            Test_Log("Flag incorrect on packet. Received %x.\r\n", data->flag);
        }
        
        HAL_Delay(100);
        iter++;
    }
}
Exemplo n.º 29
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F0xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 48 MHz */
  SystemClock_Config();

  /* Configure LED_GREEN and LED_RED */
  BSP_LED_Init(LED_GREEN);
  BSP_LED_Init(LED_RED);
  
  /*##-1- Configure the I2C peripheral ######################################*/
  I2cHandle.Instance             = I2Cx;
  
  I2cHandle.Init.Timing          = I2C_TIMING;
  I2cHandle.Init.OwnAddress1     = I2C_ADDRESS;
  I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_10BIT;
  I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  I2cHandle.Init.OwnAddress2     = 0xFF;
  I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  I2cHandle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLE;  
  
  if(HAL_I2C_Init(&I2cHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();    
  }

  /* Enable the Analog I2C Filter */
  HAL_I2CEx_ConfigAnalogFilter(&I2cHandle,I2C_ANALOGFILTER_ENABLE);

#ifdef MASTER_BOARD
  
  /* Configure User Button*/
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

  /* Wait for User Button press before starting the Communication */
  while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET)
  {
  }
  
  /* Wait for User Button release before starting the Communication */
  while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_SET)
  {
  }
  
  /* The board sends the message and expects to receive it back */
  
  /*##-2- Start the transmission process #####################################*/  
  /* While the I2C in reception process, user can transmit data through 
     "aTxBuffer" buffer */
  /* Timeout is set to 10S */
  while(HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
  {
    /* Error_Handler() function is called when Timout error occurs.
       When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
       Master restarts communication */
    if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
    {
      Error_Handler();
    }
  }
  
  /* Turn LED_GREEN on: Transfer in Transmission process is correct */
  BSP_LED_On(LED_GREEN);

  /* Wait for User Button press before starting the Communication */
  while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_RESET)
  {
  }
  
  /* Wait for User Button release before starting the Communication */
  while (BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_SET)
  {
  }

  /*##-3- Put I2C peripheral in reception process ############################*/ 
  /* Timeout is set to 10S */ 
  while(HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK)
  {
    /* Error_Handler() function is called when Timout error occurs.
       When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
       Master restarts communication */
    if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
    {
      Error_Handler();
    }
  }
  
  /* Turn LED_GREEN off: Transfer in reception process is correct */
  BSP_LED_Off(LED_GREEN);
  
#else
  
  /* The board receives the message and sends it back */

  /*##-2- Put I2C peripheral in reception process ############################*/ 
  /* Timeout is set to 10S  */
  if(HAL_I2C_Slave_Receive(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE, 10000) != HAL_OK)
  {
    /* Transfer error in reception process */
    Error_Handler();       
  }
  
  /* Turn LED_GREEN on: Transfer in reception process is correct */
  BSP_LED_On(LED_GREEN);
  
  /*##-3- Start the transmission process #####################################*/  
  /* While the I2C in reception process, user can transmit data through 
     "aTxBuffer" buffer */
  /* Timeout is set to 10S */
  if(HAL_I2C_Slave_Transmit(&I2cHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
  {
    /* Transfer error in transmission process */
    Error_Handler();    
  }
  
  /* Turn LED_GREEN off: Transfer in transmission process is correct */
  BSP_LED_Off(LED_GREEN);
  
#endif /* MASTER_BOARD */

  /*##-4- Compare the sent and received buffers ##############################*/
  if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)aRxBuffer,RXBUFFERSIZE))
  {
    /* Processing Error */
    Error_Handler();      
  }
 
  /* Infinite loop */  
  while (1)
  {
  }
}
Exemplo n.º 30
0
/**
 *
 * @param *vector Pointer to a Buffer in witch the 3 components of the magnetfield
 * 		  vector gets stored
 */
void get_magn(int16_t *vector)
{
	uint8_t buf[2];
	uint8_t xl,xh,yl,yh,zl,zh;
	volatile HAL_StatusTypeDef error;

#if Enable_LIS3MDL
	buf[0] = 0x28;						//Low Byte des X-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &xl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x29;						//High Byte des X-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &xh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x2A;						//Low Byte des Y-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &yl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x2B;						//High Byte des Y-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &yh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x2C;						//Low Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &zl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x2D;						//High Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LIS3MDL, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LIS3MDL, &zh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}
#endif

#if Enable_LSM303DLHC
	buf[0] = 0x04;						//Low Byte des X-Anteils Abfragen


	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &xl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x03;						//High Byte des X-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &xh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x08;						//Low Byte des Y-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &yl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x07;						//High Byte des Y-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &yh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x06;						//Low Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &zl,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}

	buf[0] = 0x05;						//High Byte des Z-Anteils Abfragen
	error = HAL_I2C_Master_Transmit(i2c_Handle, (uint16_t)adress_LSM303DLHC, (uint8_t*)buf,1,1000);
	if(error==HAL_OK)
	{
		error = HAL_I2C_Master_Receive(i2c_Handle, adress_LSM303DLHC, &zh,1,500);
		if(error!=HAL_OK){} //TODO Error Handling
	}
#endif

	vector[0] = (xh<<8) | xl;
	vector[1] = (yh<<8) | yl;
	vector[2] = (zh<<8) | zl;
}