Mercurial > public > ostc4
comparison Small_CPU/Src/i2c.c @ 104:22a1094545f3 kittz
Tested and alive.
author | Dmitry Romanov <kitt@bk.ru> |
---|---|
date | Mon, 24 Dec 2018 16:15:02 +0300 |
parents | b364c75005bb |
children | e9cce686fe41 |
comparison
equal
deleted
inserted
replaced
103:f5d2f02dc73f | 104:22a1094545f3 |
---|---|
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 = 400000;//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; |
118 if(global.I2C_SystemStatus != HAL_OK) | 118 if(global.I2C_SystemStatus != HAL_OK) |
119 { | 119 { |
120 I2C_Error_count(); | 120 I2C_Error_count(); |
121 } | 121 } |
122 global.dataSendToSlaveStopEval = 0; | 122 global.dataSendToSlaveStopEval = 0; |
123 //TODO: REMOVE. | |
123 // if(global.dataSendToSlavePending) | 124 // if(global.dataSendToSlavePending) |
124 // { | 125 // { |
125 // scheduleSpecial_Evaluate_DataSendToSlave(); | 126 // scheduleSpecial_Evaluate_DataSendToSlave(); |
126 // } | 127 // } |
127 return (HAL_StatusTypeDef)global.I2C_SystemStatus; | 128 return (HAL_StatusTypeDef)global.I2C_SystemStatus; |
134 return (HAL_StatusTypeDef)(global.I2C_SystemStatus & 0x03); | 135 return (HAL_StatusTypeDef)(global.I2C_SystemStatus & 0x03); |
135 | 136 |
136 | 137 |
137 global.dataSendToSlaveStopEval = 1; | 138 global.dataSendToSlaveStopEval = 1; |
138 | 139 |
139 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*/); |
140 if(global.I2C_SystemStatus != HAL_OK) | 141 if(global.I2C_SystemStatus != HAL_OK) |
141 { | 142 { |
142 I2C_Error_count(); | 143 I2C_Error_count(); |
143 } | 144 } |
144 | 145 |
145 global.dataSendToSlaveStopEval = 0; | 146 global.dataSendToSlaveStopEval = 0; |
147 //TODO: REMOVE. | |
146 // if(global.dataSendToSlavePending) | 148 // if(global.dataSendToSlavePending) |
147 // { | 149 // { |
148 // scheduleSpecial_Evaluate_DataSendToSlave(); | 150 // scheduleSpecial_Evaluate_DataSendToSlave(); |
149 // } | 151 // } |
150 | 152 |
159 | 161 |
160 uint8_t localHALstatusReturn = 0xFF; | 162 uint8_t localHALstatusReturn = 0xFF; |
161 | 163 |
162 global.dataSendToSlaveStopEval = 1; | 164 global.dataSendToSlaveStopEval = 1; |
163 | 165 |
164 localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 100); | 166 localHALstatusReturn = HAL_I2C_Master_Receive(&I2cHandle, DevAddress, pData, Size, 10); |
165 if(localHALstatusReturn != HAL_OK) | 167 if(localHALstatusReturn != HAL_OK) |
166 { | 168 { |
167 I2C_Error_count(); | 169 I2C_Error_count(); |
168 } | 170 } |
169 | 171 |
170 global.dataSendToSlaveStopEval = 0; | 172 global.dataSendToSlaveStopEval = 0; |
173 //TODO: REMOVE. | |
171 // if(global.dataSendToSlavePending) | 174 // if(global.dataSendToSlavePending) |
172 // { | 175 // { |
173 // scheduleSpecial_Evaluate_DataSendToSlave(); | 176 // scheduleSpecial_Evaluate_DataSendToSlave(); |
174 // } | 177 // } |
175 | 178 |