Rev 136 | Rev 141 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 136 | Rev 137 | ||
---|---|---|---|
Line 337... | Line 337... | ||
337 | } |
337 | } |
338 | } |
338 | } |
339 | else // the last tx buffer byte was send |
339 | else // the last tx buffer byte was send |
340 | { |
340 | { |
341 | // send crc byte at the end |
341 | // send crc byte at the end |
- | 342 | crc = ~crc; // flip all bits in the checksum |
|
342 | I2C_SendData(I2C1, crc); |
343 | I2C_SendData(I2C1, crc); |
343 | // generate stop or repeated start condition |
344 | // generate stop or repeated start condition |
344 | if ((I2C_RxBuffer != NULL) && (I2C_RxBufferSize > 0)) // is any answer byte expected? |
345 | if ((I2C_RxBuffer != NULL) && (I2C_RxBufferSize > 0)) // is any answer byte expected? |
345 | { |
346 | { |
346 | I2C_Direction = I2C_MODE_RECEIVER; // switch to master receiver after repeated start condition |
347 | I2C_Direction = I2C_MODE_RECEIVER; // switch to master receiver after repeated start condition |
Line 370... | Line 371... | ||
370 | else if ( Rx_Idx == I2C_RxBufferSize) |
371 | else if ( Rx_Idx == I2C_RxBufferSize) |
371 | { |
372 | { |
372 | // generate a STOP condition on the bus before reading data register |
373 | // generate a STOP condition on the bus before reading data register |
373 | I2C_GenerateSTOP(I2C1, ENABLE); |
374 | I2C_GenerateSTOP(I2C1, ENABLE); |
374 | // compare last byte with checksum |
375 | // compare last byte with checksum |
- | 376 | crc = ~crc;// flip all bits in calulated checksum |
|
375 | if(crc == I2C_ReceiveData(I2C1)) |
377 | if(crc == I2C_ReceiveData(I2C1)) |
376 | { // copy primary rx buffer content to rx buffer if exist |
378 | { // copy primary rx buffer content to rx buffer if exist |
377 | if(I2C_RxBuffer != NULL) |
379 | if(I2C_RxBuffer != NULL) |
378 | { |
380 | { |
379 | memcpy((u8 *)I2C_RxBuffer, (u8 *)I2C_PrimRxBuffer, I2C_RxBufferSize); |
381 | memcpy((u8 *)I2C_RxBuffer, (u8 *)I2C_PrimRxBuffer, I2C_RxBufferSize); |