diff Small_CPU/Src/i2c.c @ 160:e3ca52b8e7fa

Merge with FlipDisplay
author heinrichsweikamp
date Thu, 07 Mar 2019 15:06:43 +0100
parents 22a1094545f3
children e9cce686fe41
line wrap: on
line diff
--- a/Small_CPU/Src/i2c.c	Sat Oct 06 15:02:11 2018 +0200
+++ b/Small_CPU/Src/i2c.c	Thu Mar 07 15:06:43 2019 +0100
@@ -69,9 +69,9 @@
 {
 	I2cHandle.Instance             = I2Cx;
   I2cHandle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
-  I2cHandle.Init.ClockSpeed      = 100000;//400000;
+  I2cHandle.Init.ClockSpeed      = 100000;//400000; REDUCED for compatibility with  HMC5583L + MMA8452Q
   I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
-  I2cHandle.Init.DutyCycle       = I2C_DUTYCYCLE_16_9;
+  I2cHandle.Init.DutyCycle       = I2C_DUTYCYCLE_2;
   I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
   I2cHandle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLED;
   I2cHandle.Init.OwnAddress1     = 0x01;
@@ -79,6 +79,10 @@
 	global.dataSendToSlaveStopEval = 1;
 
 	global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle);
+	HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED);
+	HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F);
+
+
 
 	global.dataSendToSlaveStopEval = 0;
 	if(global.dataSendToSlavePending)
@@ -116,10 +120,11 @@
 		I2C_Error_count();
 	}
 	global.dataSendToSlaveStopEval = 0;
-	if(global.dataSendToSlavePending)
-	{
-		scheduleSpecial_Evaluate_DataSendToSlave();
-	}
+	//TODO: REMOVE.
+//	if(global.dataSendToSlavePending)
+//	{
+//		scheduleSpecial_Evaluate_DataSendToSlave();
+//	}
 	return (HAL_StatusTypeDef)global.I2C_SystemStatus;
 }
 
@@ -132,17 +137,18 @@
 	
 	global.dataSendToSlaveStopEval = 1;
 
-	global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress,  pData, Size, 100 /*FIXME , 1*/);
+	global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress,  pData, Size,100 /*FIXME , 1*/);
 	if(global.I2C_SystemStatus != HAL_OK)
 	{
 		I2C_Error_count();
 	}
 
 	global.dataSendToSlaveStopEval = 0;
-	if(global.dataSendToSlavePending)
-	{
-		scheduleSpecial_Evaluate_DataSendToSlave();
-	}
+	//TODO: REMOVE.
+//	if(global.dataSendToSlavePending)
+//	{
+//		scheduleSpecial_Evaluate_DataSendToSlave();
+//	}
 	
 	return (HAL_StatusTypeDef)global.I2C_SystemStatus;
 }
@@ -157,17 +163,19 @@
 
 	global.dataSendToSlaveStopEval = 1;
 
-  localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress,  pData, Size, 100);
+  localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress,  pData, Size, 10);
 	if(localHALstatusReturn != HAL_OK)
 	{
 		I2C_Error_count();
 	}
 
 	global.dataSendToSlaveStopEval = 0;
-	if(global.dataSendToSlavePending)
-	{
-		scheduleSpecial_Evaluate_DataSendToSlave();
-	}
+	//TODO: REMOVE.
+//	if(global.dataSendToSlavePending)
+//	{
+//		scheduleSpecial_Evaluate_DataSendToSlave();
+//	}
+
 	return (HAL_StatusTypeDef)localHALstatusReturn;
 }