Mercurial > public > ostc4
comparison 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 |
comparison
equal
deleted
inserted
replaced
80:cc2bb7bb8456 | 160:e3ca52b8e7fa |
---|---|
67 | 67 |
68 HAL_StatusTypeDef MX_I2C1_Init(void) | 68 HAL_StatusTypeDef MX_I2C1_Init(void) |
69 { | 69 { |
70 I2cHandle.Instance = I2Cx; | 70 I2cHandle.Instance = I2Cx; |
71 I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; | 71 I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
72 I2cHandle.Init.ClockSpeed = 100000;//400000; | 72 I2cHandle.Init.ClockSpeed = 100000;//400000; REDUCED for compatibility with HMC5583L + MMA8452Q |
73 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; | 73 I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED; |
74 I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_16_9; | 74 I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; |
75 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; | 75 I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED; |
76 I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; | 76 I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED; |
77 I2cHandle.Init.OwnAddress1 = 0x01; | 77 I2cHandle.Init.OwnAddress1 = 0x01; |
78 | 78 |
79 global.dataSendToSlaveStopEval = 1; | 79 global.dataSendToSlaveStopEval = 1; |
80 | 80 |
81 global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); | 81 global.I2C_SystemStatus = HAL_I2C_Init(&I2cHandle); |
82 HAL_I2CEx_AnalogFilter_Config(&I2cHandle, I2C_ANALOGFILTER_ENABLED); | |
83 HAL_I2CEx_ConfigDigitalFilter(&I2cHandle,0x0F); | |
84 | |
85 | |
82 | 86 |
83 global.dataSendToSlaveStopEval = 0; | 87 global.dataSendToSlaveStopEval = 0; |
84 if(global.dataSendToSlavePending) | 88 if(global.dataSendToSlavePending) |
85 { | 89 { |
86 scheduleSpecial_Evaluate_DataSendToSlave(); | 90 scheduleSpecial_Evaluate_DataSendToSlave(); |
114 if(global.I2C_SystemStatus != HAL_OK) | 118 if(global.I2C_SystemStatus != HAL_OK) |
115 { | 119 { |
116 I2C_Error_count(); | 120 I2C_Error_count(); |
117 } | 121 } |
118 global.dataSendToSlaveStopEval = 0; | 122 global.dataSendToSlaveStopEval = 0; |
119 if(global.dataSendToSlavePending) | 123 //TODO: REMOVE. |
120 { | 124 // if(global.dataSendToSlavePending) |
121 scheduleSpecial_Evaluate_DataSendToSlave(); | 125 // { |
122 } | 126 // scheduleSpecial_Evaluate_DataSendToSlave(); |
127 // } | |
123 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | 128 return (HAL_StatusTypeDef)global.I2C_SystemStatus; |
124 } | 129 } |
125 | 130 |
126 | 131 |
127 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) | 132 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size) |
130 return (HAL_StatusTypeDef)(global.I2C_SystemStatus & 0x03); | 135 return (HAL_StatusTypeDef)(global.I2C_SystemStatus & 0x03); |
131 | 136 |
132 | 137 |
133 global.dataSendToSlaveStopEval = 1; | 138 global.dataSendToSlaveStopEval = 1; |
134 | 139 |
135 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size, 100 /*FIXME , 1*/); | 140 global.I2C_SystemStatus = HAL_I2C_Master_Transmit(&I2cHandle, DevAddress, pData, Size,100 /*FIXME , 1*/); |
136 if(global.I2C_SystemStatus != HAL_OK) | 141 if(global.I2C_SystemStatus != HAL_OK) |
137 { | 142 { |
138 I2C_Error_count(); | 143 I2C_Error_count(); |
139 } | 144 } |
140 | 145 |
141 global.dataSendToSlaveStopEval = 0; | 146 global.dataSendToSlaveStopEval = 0; |
142 if(global.dataSendToSlavePending) | 147 //TODO: REMOVE. |
143 { | 148 // if(global.dataSendToSlavePending) |
144 scheduleSpecial_Evaluate_DataSendToSlave(); | 149 // { |
145 } | 150 // scheduleSpecial_Evaluate_DataSendToSlave(); |
151 // } | |
146 | 152 |
147 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | 153 return (HAL_StatusTypeDef)global.I2C_SystemStatus; |
148 } | 154 } |
149 | 155 |
150 | 156 |
155 | 161 |
156 uint8_t localHALstatusReturn = 0xFF; | 162 uint8_t localHALstatusReturn = 0xFF; |
157 | 163 |
158 global.dataSendToSlaveStopEval = 1; | 164 global.dataSendToSlaveStopEval = 1; |
159 | 165 |
160 localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 100); | 166 localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); |
161 if(localHALstatusReturn != HAL_OK) | 167 if(localHALstatusReturn != HAL_OK) |
162 { | 168 { |
163 I2C_Error_count(); | 169 I2C_Error_count(); |
164 } | 170 } |
165 | 171 |
166 global.dataSendToSlaveStopEval = 0; | 172 global.dataSendToSlaveStopEval = 0; |
167 if(global.dataSendToSlavePending) | 173 //TODO: REMOVE. |
168 { | 174 // if(global.dataSendToSlavePending) |
169 scheduleSpecial_Evaluate_DataSendToSlave(); | 175 // { |
170 } | 176 // scheduleSpecial_Evaluate_DataSendToSlave(); |
177 // } | |
178 | |
171 return (HAL_StatusTypeDef)localHALstatusReturn; | 179 return (HAL_StatusTypeDef)localHALstatusReturn; |
172 } | 180 } |
173 | 181 |