One wire CRC

Questions on other types of hardware and getting it talking to the ARM CPU
Post Reply
basicchip
Posts: 1090
Joined: Fri Oct 19, 2012 2:39 am
Location: Weeki Watchee, FL
Contact:

One wire CRC

Post by basicchip »

This code should be easy to port.

Do the code internal to the function first.

The function declaration syntax in ARMbasic is a little different with
definitions AS STRING

Details in the help files, take it a line at a time.

--- In ARMexpress@yahoogroups.com, "ross.kingii" wrote:
>
> I am trying to calculate the 1 Wire CRC value on a device and all the samples
of code on the web just dont fit into the flavor of basic on the Armweb.
>
> Does anyone have some code to calculate this already built or can you help me
convert the code below from code written for the BASICX line
>
> Thanks
>
> Code >>
>
> Function Calc_CRC(ByRef buff() as byte, ByVal num_vals as Integer) as byte
>
> Dim Shift_Reg as Byte, SR_lsb as Byte, Data_Bit as Byte, v as Byte
> Dim FB_bit as Byte, i as Integer, j as Integer
>
> Shift_Reg = 0 ' initialize the shift regsiter
>
> For i = 1 to num_vals ' for each byte in the array
> v = buff(i)
>
> For j = 1 to 8 ' for each bit
> Data_Bit = v AND &H01 ' isolate least sign bit
> SR_lsb = Shift_Reg AND &H01
> FB_bit = (Data_Bit XOR SR_lsb) AND &H01
> ' calculate the feed back bit
> Shift_Reg = Shift_Reg \ 2 ' shift right
> If (FB_bit = 1) then
> Shift_Reg = Shift_Reg XOR &H8c
> End if
> 'Call PutB(Shift_Reg) ' for debugging
> 'Call NewLine()
> v = v \ 2 ' next bit now in least sig bit position
> Next
> ' Call PutB(Shift_Reg)
> ' Call NewLine()
> Next
> Calc_CRC = Shift_Reg ' return the result
>
> End Function
>



Post Reply