Rev 360 | Rev 378 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 360 | Rev 362 | ||
---|---|---|---|
Line 236... | Line 236... | ||
236 | I2C_GenerateSTOP (I2C1, DISABLE); // free the bus |
236 | I2C_GenerateSTOP (I2C1, DISABLE); // free the bus |
237 | } |
237 | } |
238 | I2C_State = I2C_STATE_IDLE; |
238 | I2C_State = I2C_STATE_IDLE; |
239 | I2C_Error = I2C_ERROR_NOACK; |
239 | I2C_Error = I2C_ERROR_NOACK; |
240 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
240 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
241 | LED_GRN_OFF; |
- | |
242 | return; |
241 | return; |
243 | } |
242 | } |
244 | else |
243 | else |
245 | { // depending on current i2c state |
244 | { // depending on current i2c state |
246 | switch(status) |
245 | switch(status) |
247 | { |
246 | { |
248 | // the start condition was initiated on the bus |
247 | // the start condition was initiated on the bus |
249 | case I2C_EVENT_MASTER_MODE_SELECT: |
248 | case I2C_EVENT_MASTER_MODE_SELECT: |
250 | LED_GRN_ON; |
- | |
251 | // update current bus state variable |
249 | // update current bus state variable |
252 | // jump to rx state if there is nothing to send |
250 | // jump to rx state if there is nothing to send |
253 | switch(I2C_Direction) |
251 | switch(I2C_Direction) |
254 | { |
252 | { |
255 | case I2C_MODE_TRANSMITTER: |
253 | case I2C_MODE_TRANSMITTER: |
Line 259... | Line 257... | ||
259 | case I2C_MODE_RECEIVER: |
257 | case I2C_MODE_RECEIVER: |
260 | if (I2C_RxBufferSize == 0) // nothing to send? |
258 | if (I2C_RxBufferSize == 0) // nothing to send? |
261 | { |
259 | { |
262 | I2C_GenerateSTOP (I2C1, ENABLE); |
260 | I2C_GenerateSTOP (I2C1, ENABLE); |
263 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
261 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
264 | // LED_GRN_OFF; |
- | |
265 | I2C_State = I2C_STATE_IDLE; |
262 | I2C_State = I2C_STATE_IDLE; |
266 | I2C_Error = I2C_ERROR_NONE; |
263 | I2C_Error = I2C_ERROR_NONE; |
267 | return; |
264 | return; |
268 | } |
265 | } |
269 | else |
266 | else |
Line 273... | Line 270... | ||
273 | break; |
270 | break; |
Line 274... | Line 271... | ||
274 | 271 | ||
275 | default: // invalid direction |
272 | default: // invalid direction |
276 | I2C_GenerateSTOP (I2C1, ENABLE); |
273 | I2C_GenerateSTOP (I2C1, ENABLE); |
277 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
- | |
278 | LED_GRN_OFF; |
274 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
279 | I2C_State = I2C_STATE_IDLE; |
275 | I2C_State = I2C_STATE_IDLE; |
280 | I2C_Error = I2C_ERROR_UNKNOWN; |
276 | I2C_Error = I2C_ERROR_UNKNOWN; |
281 | return; |
277 | return; |
282 | } |
278 | } |
Line 308... | Line 304... | ||
308 | break; |
304 | break; |
Line 309... | Line 305... | ||
309 | 305 | ||
310 | default: // unknown I2C state |
306 | default: // unknown I2C state |
311 | // should never happen |
307 | // should never happen |
312 | I2C_GenerateSTOP (I2C1, ENABLE); |
- | |
313 | LED_GRN_OFF; |
308 | I2C_GenerateSTOP (I2C1, ENABLE); |
314 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
309 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
315 | I2C_State = I2C_STATE_IDLE; |
310 | I2C_State = I2C_STATE_IDLE; |
316 | I2C_Error = I2C_ERROR_UNKNOWN; |
311 | I2C_Error = I2C_ERROR_UNKNOWN; |
317 | return; |
312 | return; |
Line 338... | Line 333... | ||
338 | } |
333 | } |
339 | else |
334 | else |
340 | { // stop communication |
335 | { // stop communication |
341 | I2C_GenerateSTOP(I2C1, ENABLE); // generate stop condition to free the bus |
336 | I2C_GenerateSTOP(I2C1, ENABLE); // generate stop condition to free the bus |
342 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
337 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
343 | // LED_GRN_OFF; |
- | |
344 | I2C_State = I2C_STATE_IDLE; // ready for new actions |
338 | I2C_State = I2C_STATE_IDLE; // ready for new actions |
345 | I2C_Error = I2C_ERROR_NONE; |
339 | I2C_Error = I2C_ERROR_NONE; |
346 | } |
340 | } |
347 | } |
341 | } |
348 | break; |
342 | break; |
Line 362... | Line 356... | ||
362 | // call the rx handler function to process recieved data |
356 | // call the rx handler function to process recieved data |
363 | if(I2C_pRxHandler != NULL) (*I2C_pRxHandler)((u8*)I2C_Buffer, I2C_RxBufferSize); |
357 | if(I2C_pRxHandler != NULL) (*I2C_pRxHandler)((u8*)I2C_Buffer, I2C_RxBufferSize); |
364 | I2C1_Timeout = SetDelay(I2C1_TIMEOUT); |
358 | I2C1_Timeout = SetDelay(I2C1_TIMEOUT); |
365 | DebugOut.Analog[15]++; |
359 | DebugOut.Analog[15]++; |
366 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
360 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
367 | // LED_GRN_OFF; |
- | |
368 | I2C_State = I2C_STATE_IDLE; |
361 | I2C_State = I2C_STATE_IDLE; |
369 | I2C_Error = I2C_ERROR_NONE; |
362 | I2C_Error = I2C_ERROR_NONE; |
370 | return; |
363 | return; |
371 | } |
364 | } |
372 | Rx_Idx++; |
365 | Rx_Idx++; |
Line 378... | Line 371... | ||
378 | break; |
371 | break; |
Line 379... | Line 372... | ||
379 | 372 | ||
380 | default:// unknown event |
373 | default:// unknown event |
381 | // should never happen |
374 | // should never happen |
382 | I2C_GenerateSTOP (I2C1, ENABLE); |
- | |
383 | LED_GRN_OFF; |
375 | I2C_GenerateSTOP (I2C1, ENABLE); |
384 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
376 | VIC_ITCmd(I2C1_ITLine, DISABLE); |
385 | I2C_State = I2C_STATE_IDLE; |
377 | I2C_State = I2C_STATE_IDLE; |
386 | I2C_Error = I2C_ERROR_UNKNOWN; |
378 | I2C_Error = I2C_ERROR_UNKNOWN; |
387 | break; |
379 | break; |