English
Language : 

ISL78610 Datasheet, PDF (57/98 Pages) Intersil Corporation – Multi-Cell Li-Ion Battery Manager
ISL78610
shift register as shown in Figure 66. The CRC value is calculated
using the base command data only. The CRC value is not
included in the calculation.
The host microcontroller calculates the CRC when sending
commands or writing data. The calculation is repeated in the
ISL78610 and checked for compliance. The ISL78610 calculates
the CRC when responding with data (device reads). The host
microcontroller then repeats the calculation and checks for
compliance.
DIN
+
+
FF0
FF1
FF2
FF3
FIGURE 66. 4-BIT CRC CALCULATION
Attribute VB_Name = "isl78610evb_crc4_lib"
' File - isl78610evb_crc4_lib.bas
' Copyright (c) 2010 Intersil
' -----------------------------------------------------------------------------
Option Explicit
'***********************************************************
' CRC4 Routines
'***********************************************************
Public Function CheckCRC4(myArray() As Byte) As Boolean
'returns True if CRC4 checksum (low nibble of last byte in myarray)
'is good. Array can be any length
Dim crc4 As Byte
Dim lastnibble As Byte
lastnibble = myArray(UBound(myArray)) And &HF
crc4 = CalculateCRC4(myArray)
If lastnibble = crc4 Then
CheckCRC4 = True
Else
CheckCRC4 = False
End If
End Function
Public Sub AddCRC4(myArray() As Byte)
'adds CRC4 checksum (low nibble in last byte in array)
'array can be any length
Dim crc4 As Byte
crc4 = CalculateCRC4(myArray)
myArray(UBound(myArray)) = (myArray(UBound(myArray)) And &HF0) Or
crc4
End Sub
Public Function CalculateCRC4(ByRef myArray() As Byte) As Byte
'calculates/returns the CRC4 checksum of array contents excluding
'last low nibble. Array can be any length
Dim size As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim bit0 As Boolean, bit1 As Boolean, bit2 As Boolean, bit3 As Boolean
Dim ff0 As Boolean, ff1 As Boolean, ff2 As Boolean, ff3 As Boolean
Dim carry As Boolean
Dim arraycopy() As Byte
Dim result As Byte
'copy data so we do not clobber source array
ReDim arraycopy(LBound(myArray) To UBound(myArray)) As Byte
For i = LBound(myArray) To UBound(myArray)
arraycopy(i) = myArray(i)
Next
'initialize bits
bit0 = False
bit1 = False
bit2 = False
bit3 = False
'simple implementation of CRC4 (using polynomial 1 + X + X^4)
For i = LBound(arraycopy) To UBound(arraycopy)
'last nibble is ignored for CRC4 calculations
If i = UBound(arraycopy) Then
k=4
Else
k=8
End If
For j = 1 To k
'shift left one bit
carry = (arraycopy(i) And &H80) > 0
arraycopy(i) = (arraycopy(i) And &H7F) * 2
'see ISL78610 datasheet, Fig 11: 4-bit CRC calculation
ff0 = carry Xor bit3
ff1 = bit0 Xor bit3
ff2 = bit1
ff3 = bit2
bit0 = ff0
bit1 = ff1
bit2 = ff2
bit3 = ff3
Next j
Next i
'combine bits to obtain CRC4 result
result = 0
If bit0 Then
result = result + 1
End If
If bit1 Then
result = result + 2
End If
If bit2 Then
result = result + 4
End If
If bit3 Then
result = result + 8
End If
CalculateCRC4 = result
End Function
FIGURE 67. EXAMPLE CRC CALCULATION ROUTINE (VISUAL BASIC)
Submit Document Feedback 57
FN8830.1
June 16, 2016