Can't get past "'_crc16_update' was not declared in this scope" compilation error

Hi,
Is anyone else able to replicate this error message? I thought a screenshot might be a quicker way of explaining the issue I'm facing, but I'm not sure the resolution will allow it.

  • Arduino IDE 2.3.10 on a Windows 10 Pro PC
  • A single-line sketch containing the statement:

#include <OneWire.h>

and empty setup() and loop() functions

  • OneWire library showing as up-to-date and installed
    This programme fails to compile with the error message:

Blockquote
h:\Arduino\libraries\OneWire\OneWire.cpp: In static member function 'static uint16_t OneWire::crc16(const uint8_t*, uint16_t, uint16_t)':
h:\Arduino\libraries\OneWire\OneWire.cpp:569:15: error: '_crc16_update' was not declared in this scope
crc = _crc16_update(crc, input[i]);
^~~~~~~~~~~~~
h:\Arduino\libraries\OneWire\OneWire.cpp:569:15: note: suggested alternative: 'crc16_update'
crc = _crc16_update(crc, input[i]);
^~~~~~~~~~~~~
crc16_update
exit status 1

Compilation error: exit status 1

I don't see how it can be an issue with the library - partly because I have had a Arduino Mega running a sketch using all the listed libraries for the past year, and also because if everybody was getting this error, I'd expect to have seen (a lot) more posts on the subject.

A few months ago, I came back to the sketch to make some changes, and couldn't get the programme to compile. I've been trying to find a solution since.

20 minutes ago, I thought I'd found one. I changed the single statement to

#include "OneWire.h";

and it compiled! I changed it back, and it compiled again! And then next time, it didn't. Nor for the four times I tried after that. And now it no longer compiles whichever syntax I use.

I'd suspect a hardware/memory issue, but the behaviour is the same on my Windows 11 laptop, and the error message is always the same.

I've un-installed and re-installed the Arduino IDE, I've tried using older versions of the library, and the old (1.8.19) IDE. Same result.

Thank you for reading this far. If anyone has a suggestion, I'd be happy to hear it. I suspect it'll come down to re-writing the original programme from scratch, using different resources.

Please follow the directions in the pinned post re posting code and error logs in < CODE/ > tags

I just tried the one line sketch and it compiles fine. I have a suspicion but until I see the verbose compile output I can't check it.

Did you perchance at one point change the target processor to a non AVR one and compile successfully?

the onewire.h has this include

#if defined(__AVR__)
#include <util/crc16.h>
#endif

what exact board have you selected?

Your screenshot isn't very useful. Please copy the complete error message and paste it using the forum's code tags so the formatting is preserved.

Have any of your libraries been updated recently?

Which Arduino board are you using now, and which board were you using previously?

Have you tried closing the Arduino IDE completely and then reopening it? Doing so forces a full rebuild from scratch. Occasionally, a bad include file or a previous compilation error can leave the build in an inconsistent state. Restarting the IDE forces all include files to be reloaded and the entire project to be recompiled.

I'm not sure any of these suggestions will solve the problem because there isn't enough information yet to draw a proper conclusion.

ARDUINO MEGA or MEGA 2560 according to the screenshot

Maybe a conflict between ModbusMaster/src/util/crc16.h and AVR Libc /util/crc16.h .

This is true for Arduino IDE 1.x, but not for Arduino IDE 2.x. The Arduino IDE 2.x sketch compilation cache is persistent.

Hi @jacobbess. I'm going to ask you to provide the full verbose output from a compilation. It is possible the additional information present in the verbose output will give us a clue that will allow us to better understand the cause of the error you are encountering.


:red_exclamation_mark: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Open the sketch in Arduino IDE.
  2. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  3. Check the box next to "Show verbose output during: ☐ compile" in the "Preferences" dialog.
  4. Click the "OK" button.
    The "Preferences" dialog will close.
  5. Select Sketch > Verify/Compile from the Arduino IDE menus.
  6. Wait for the compilation to fail.
  7. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  8. Open a reply here on this forum topic by clicking the "Reply" button.
  9. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  10. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  11. Move the cursor outside of the code block markup before you add any additional text to your reply.
  12. Click the "Reply" button to publish the post.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here.

Click here for attachment instructions

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a reply here on this forum topic by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:

    The "Open" dialog will open.
  6. Select the .txt file you saved from the "Open" dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

Under 'Tools | Board:' I see 'Arduino AVR Boards' and 'Arduino UNO R4 Boards' listed. The only boards in Arduino UNO R4 Boards are:

  • Arduino UNO R4 Minima
  • Arduino UNO R4 Wifi
  • Arduino Nano R4

The programme compiles successfully with each of these boards.

From 'Arduino AVR Boards', I selected 'Arduino Mega or Mega 2560'.

sonofcy, gilshultz and ptillisch (thank you for the detailed instructions),

FQBN: arduino:avr:mega
Using board 'mega' from platform in folder: C:\Users\mfulw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.8
Using core 'arduino' from platform in folder: C:\Users\mfulw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.8

Detecting libraries used...
Using cached library dependencies for file: C:\Users\mfulw\AppData\Local\arduino\sketches\8A1D56E9C7DA08E9F03591F926327E8A\sketch\CompileTest.ino.cpp.merged
Alternatives for DallasTemperature.h: [DallasTemperature@4.0.6]
ResolveLibrary(DallasTemperature.h)
  -> candidates: [DallasTemperature@4.0.6]
Alternatives for OneWire.h: [OneWire@2.3.8]
ResolveLibrary(OneWire.h)
  -> candidates: [OneWire@2.3.8]
Alternatives for ModbusMaster.h: [ModbusMaster@2.0.1]
ResolveLibrary(ModbusMaster.h)
  -> candidates: [ModbusMaster@2.0.1]
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
Alternatives for Ethernet3.h: [Ethernet3@1.6.0]
ResolveLibrary(Ethernet3.h)
  -> candidates: [Ethernet3@1.6.0]
Alternatives for PubSubClient.h: [PubSubClient3@3.3.0]
ResolveLibrary(PubSubClient.h)
  -> candidates: [PubSubClient3@3.3.0]
Using cached library dependencies for file: h:\Arduino\libraries\DallasTemperature\DallasTemperature.cpp
Using cached library dependencies for file: h:\Arduino\libraries\OneWire\OneWire.cpp
Using cached library dependencies for file: h:\Arduino\libraries\ModbusMaster\src\ModbusMaster.cpp
Using cached library dependencies for file: C:\Users\mfulw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.8\libraries\SPI\src\SPI.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\Dhcp.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\Dns.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\Ethernet3.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\EthernetClient.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\EthernetServer.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\EthernetUdp3.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\utility\socket.cpp
Using cached library dependencies for file: h:\Arduino\libraries\Ethernet3\src\utility\w5500.cpp
Using cached library dependencies for file: h:\Arduino\libraries\PubSubClient3\src\PubSubClient.cpp
Generating function prototypes...
Using cached sketch with function prototypes.
Compiling sketch...
Using previously compiled file: C:\Users\mfulw\AppData\Local\arduino\sketches\8A1D56E9C7DA08E9F03591F926327E8A\sketch\CompileTest.ino.cpp.o
Compiling libraries...
Compiling library "DallasTemperature"
Using previously compiled file: C:\Users\mfulw\AppData\Local\arduino\sketches\8A1D56E9C7DA08E9F03591F926327E8A\libraries\DallasTemperature\DallasTemperature.cpp.o
Compiling library "OneWire"
"C:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino" "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\mega" "-Ih:\\Arduino\\libraries\\DallasTemperature" "-Ih:\\Arduino\\libraries\\OneWire" "-Ih:\\Arduino\\libraries\\ModbusMaster\\src" "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\libraries\\SPI\\src" "-Ih:\\Arduino\\libraries\\Ethernet3\\src" "-Ih:\\Arduino\\libraries\\PubSubClient3\\src" "h:\\Arduino\\libraries\\OneWire\\OneWire.cpp" -o "C:\\Users\\mfulw\\AppData\\Local\\arduino\\sketches\\8A1D56E9C7DA08E9F03591F926327E8A\\libraries\\OneWire\\OneWire.cpp.o"
h:\Arduino\libraries\OneWire\OneWire.cpp: In static member function 'static uint16_t OneWire::crc16(const uint8_t*, uint16_t, uint16_t)':
h:\Arduino\libraries\OneWire\OneWire.cpp:569:15: error: '_crc16_update' was not declared in this scope
         crc = _crc16_update(crc, input[i]);
               ^~~~~~~~~~~~~
h:\Arduino\libraries\OneWire\OneWire.cpp:569:15: note: suggested alternative: 'crc16_update'
         crc = _crc16_update(crc, input[i]);
               ^~~~~~~~~~~~~
               crc16_update
Using library DallasTemperature at version 4.0.6 in folder: H:\Arduino\libraries\DallasTemperature 
Using library OneWire at version 2.3.8 in folder: H:\Arduino\libraries\OneWire 
Using library ModbusMaster at version 2.0.1 in folder: H:\Arduino\libraries\ModbusMaster 
Using library SPI at version 1.0 in folder: C:\Users\mfulw\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.8\libraries\SPI 
Using library Ethernet3 at version 1.6.0 in folder: H:\Arduino\libraries\Ethernet3 
Using library PubSubClient3 at version 3.3.0 in folder: H:\Arduino\libraries\PubSubClient3 
exit status 1

Compilation error: exit status 1

Thank you

If you want to try something, load this in your IDE


#include <OneWire.h>
void setup() {}
void loop() {}

save it as testb and press the verify button.
Delete (cut) the small shetch from the IDE. (keep the name testb.ino)
copypaste your sketch in the IDE and press the verify button.

  Should work... no warranty

The verbose output shows the error while compiling the OneWire library. Some (Power)Shell trickery to make it easier to read that long command line, copied into clipboard

PS E:\> (Get-Clipboard -Raw) -replace ' (")?-', "`n `$1-"
Compiling library "OneWire"
"C:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
 -c
 -g
 -Os
 -w
 -std=gnu++11
 -fpermissive
 -fno-exceptions
 -ffunction-sections
 -fdata-sections
 -fno-threadsafe-statics
 -Wno-error=narrowing
 -MMD
 -flto
 -mmcu=atmega2560
 -DF_CPU=16000000L
 -DARDUINO=10607
 -DARDUINO_AVR_MEGA2560
 -DARDUINO_ARCH_AVR
 "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino"
 "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\mega"
 "-Ih:\\Arduino\\libraries\\DallasTemperature"
 "-Ih:\\Arduino\\libraries\\OneWire"
 "-Ih:\\Arduino\\libraries\\ModbusMaster\\src"
 "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\libraries\\SPI\\src"
 "-Ih:\\Arduino\\libraries\\Ethernet3\\src"
 "-Ih:\\Arduino\\libraries\\PubSubClient3\\src" "h:\\Arduino\\libraries\\OneWire\\OneWire.cpp"
 -o "C:\\Users\\mfulw\\AppData\\Local\\arduino\\sketches\\8A1D56E9C7DA08E9F03591F926327E8A\\libraries\\OneWire\\OneWire.cpp.o"

All the quoted -I arguments near the end are for each of the discovered libraries. Compiling the bare-bones sketch, as in your original screenshot

#include <OneWire.h>

void setup() {}

void loop() {}

I get -- with no errors

PS E:\> (Get-Clipboard -Raw) -replace ' (")?-', "`n `$1-"
Compiling library "OneWire"
"E:\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
 -c
 -g
 -Os
 -std=gnu++11
 -fpermissive
 -fno-exceptions
 -ffunction-sections
 -fdata-sections
 -fno-threadsafe-statics
 -Wno-error=narrowing
 -MMD
 -flto
 -mmcu=atmega328p
 -DF_CPU=16000000L
 -DARDUINO=10607
 -DARDUINO_AVR_UNO
 -DARDUINO_ARCH_AVR
 "-IE:\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino"
 "-IE:\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\standard"
 "-Ie:\\Sketchbook\\libraries\\OneWire" "e:\\Sketchbook\\libraries\\OneWire\\OneWire.cpp"
 -o "C:\\Users\\kenb4\\AppData\\Local\\arduino\\sketches\\8F878A94A3E5D2DFB05FBC29BBC878B4\\libraries\\OneWire\\OneWire.cpp.o"

The differences include you turning off warnings with -w (not recommended, but unlikely the issue)

 Compiling library "OneWire"
-"C:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
+"E:\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
  -c
  -g
  -Os
- -w
  -std=gnu++11
  -fpermissive
  -fno-exceptions
@@ -19,12 +18,7 @@
  -DARDUINO=10607
  -DARDUINO_AVR_MEGA2560
  -DARDUINO_ARCH_AVR
- "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino"
- "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\mega"
- "-Ih:\\Arduino\\libraries\\DallasTemperature"
- "-Ih:\\Arduino\\libraries\\OneWire"
- "-Ih:\\Arduino\\libraries\\ModbusMaster\\src"
- "-IC:\\Users\\mfulw\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\libraries\\SPI\\src"
- "-Ih:\\Arduino\\libraries\\Ethernet3\\src"
- "-Ih:\\Arduino\\libraries\\PubSubClient3\\src" "h:\\Arduino\\libraries\\OneWire\\OneWire.cpp"
- -o "C:\\Users\\mfulw\\AppData\\Local\\arduino\\sketches\\8A1D56E9C7DA08E9F03591F926327E8A\\libraries\\OneWire\\OneWire.cpp.o"
+ "-IE:\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino"
+ "-IE:\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\mega"
+ "-Ie:\\Sketchbook\\libraries\\OneWire" "e:\\Sketchbook\\libraries\\OneWire\\OneWire.cpp"
+ -o "C:\\Users\\kenb4\\AppData\\Local\\arduino\\sketches\\8F878A94A3E5D2DFB05FBC29BBC878B4\\libraries\\OneWire\\OneWire.cpp.o"

And all the differences in the end look OK. Stripping out the drive paths, so they start with packages for the board, and libraries

  -DARDUINO_ARCH_AVR
  "-I\\packages\\arduino\\hardware\\avr\\1.8.8\\cores\\arduino"
  "-I\\packages\\arduino\\hardware\\avr\\1.8.8\\variants\\mega"
- "-I\\libraries\\DallasTemperature"
- "-I\\libraries\\OneWire"
- "-I\\libraries\\ModbusMaster\\src"
- "-I\\packages\\arduino\\hardware\\avr\\1.8.8\\libraries\\SPI\\src"
- "-I\\libraries\\Ethernet3\\src"
- "-I\\libraries\\PubSubClient3\\src" "h:\\Arduino\\libraries\\OneWire\\OneWire.cpp"
- -o "C:\\Users\\mfulw\\AppData\\Local\\arduino\\sketches\\8A1D56E9C7DA08E9F03591F926327E8A\\libraries\\OneWire\\OneWire.cpp.o"
+ "-I\\libraries\\OneWire" "e:\\Sketchbook\\libraries\\OneWire\\OneWire.cpp"
+ -o "C:\\Users\\kenb4\\AppData\\Local\\arduino\\sketches\\8F878A94A3E5D2DFB05FBC29BBC878B4\\libraries\\OneWire\\OneWire.cpp.o"

Note that OneWire.cpp, the file actually being compiled, is the second "word" on the line above the last, which starts -o. The difference is also in the order of the libraries. Again, with a bare-bones sketch, those differences should disappear. If it continues to fail as you showed originally, then what?

I'm not sure how well it will work if the compile fails. But for my working bare-bones sketch, right-clicking on the #include line and choosing Go to Definition, it opens OneWire.h, which starts with

#ifndef OneWire_h
#define OneWire_h

#ifdef __cplusplus

#include <stdint.h>

#if defined(__AVR__)
#include <util/crc16.h>
#endif

Hovering over that <util/crc16.h> shows the full path in a tooltip

This is not under one of the listed optional paths with -I; it's a built-in automatic one. That 7.3.0-atmel3.6.1-arduino7 directory also contains the avr-g++ "compiler driver", which is the executable file at the beginning of those giant commands. Go to Definition may open it; if not, you can find the file. The part we're interested in starts at line 112

static __inline__ uint16_t
_crc16_update(uint16_t __crc, uint8_t __data)
{

The declared function name starts with an underscore. When you got the error, the compiler suggested the same name without the first underscore.

So if you get that error again, what does that file actually say at that moment? Finally, you can try an even simpler sketch with no libraries to call that function directly

#include <util/crc16.h>

void setup() {
  uint16_t crc = 11;
  uint8_t data = 22;
  _crc16_update(crc, data);
}

void loop() {}

Does that compile?

Thank you for your time. The sketch

#include <util/crc16.h>

void setup() {
  uint16_t crc = 11;
  uint8_t data = 22;
  _crc16_update(crc, data);
}

void loop() {}

compiles successfully. I found the file

crc16.h

which for me is located at

C:\Users\mfulw\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\util\crc16.h

I'm not sure what you meant when you wrote:

The function you referred to in that file looks like this:

static __inline__ uint16_t
_crc16_update(uint16_t __crc, uint8_t __data)
{
	uint8_t __tmp;
	uint16_t __ret;

	__asm__ __volatile__ (
		"eor %A0,%2" "\n\t"
		"mov %1,%A0" "\n\t"
		"swap %1" "\n\t"
		"eor %1,%A0" "\n\t"
		"mov __tmp_reg__,%1" "\n\t"
		"lsr %1" "\n\t"
		"lsr %1" "\n\t"
		"eor %1,__tmp_reg__" "\n\t"
		"mov __tmp_reg__,%1" "\n\t"
		"lsr %1" "\n\t"
		"eor %1,__tmp_reg__" "\n\t"
		"andi %1,0x07" "\n\t"
		"mov __tmp_reg__,%A0" "\n\t"
		"mov %A0,%B0" "\n\t"
		"lsr %1" "\n\t"
		"ror __tmp_reg__" "\n\t"
		"ror %1" "\n\t"
		"mov %B0,__tmp_reg__" "\n\t"
		"eor %A0,%1" "\n\t"
		"lsr __tmp_reg__" "\n\t"
		"ror %1" "\n\t"
		"eor %B0,__tmp_reg__" "\n\t"
		"eor %A0,%1"
		: "=r" (__ret), "=d" (__tmp)
		: "r" (__data), "0" (__crc)
		: "r0"
	);
	return __ret;
}

Thank you again.

If you modify /libraries/ModbusMaster/src/util/crc16.h to

/**
@file
CRC Computations

@defgroup util_crc16 "util/crc16.h": CRC Computations
@code#include "util/crc16.h"@endcode

This header file provides functions for calculating
cyclic redundancy checks (CRC) using common polynomials.
Modified by Doc Walker to be processor-independent (removed inline
assembler to allow it to compile on SAM3X8E processors).

@par References:
Jack Crenshaw's "Implementing CRCs" article in the January 1992 issue of @e
Embedded @e Systems @e Programming. This may be difficult to find, but it
explains CRC's in very clear and concise terms. Well worth the effort to
obtain a copy.

*/
/* Copyright (c) 2002, 2003, 2004  Marek Michalkiewicz
   Copyright (c) 2005, 2007 Joerg Wunsch
   Copyright (c) 2013 Dave Hylands
   Copyright (c) 2013 Frederic Nadeau
   Copyright (c) 2015 Doc Walker
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.

   * Neither the name of the copyright holders nor the names of
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE. */


#ifndef _UTIL_CRC16_H_
#define _UTIL_CRC16_H_


/** @ingroup util_crc16
    Processor-independent CRC-16 calculation.

    Polynomial: x^16 + x^15 + x^2 + 1 (0xA001)<br>
    Initial value: 0xFFFF

    This CRC is normally used in disk-drive controllers.

    @param uint16_t crc (0x0000..0xFFFF)
    @param uint8_t a (0x00..0xFF)
    @return calculated CRC (0x0000..0xFFFF)
*/
static uint16_t crc16_update(uint16_t crc, uint8_t a)
{
  int i;

  crc ^= a;
  for (i = 0; i < 8; ++i)
  {
    if (crc & 1)
      crc = (crc >> 1) ^ 0xA001;
    else
      crc = (crc >> 1);
  }

  return crc;
}
////////////////////////////////////////////////////////////////////////
static __inline__ uint16_t
_crc16_update(uint16_t __crc, uint8_t __data)
{
	uint8_t __tmp;
	uint16_t __ret;

	__asm__ __volatile__ (
		"eor %A0,%2" "\n\t"
		"mov %1,%A0" "\n\t"
		"swap %1" "\n\t"
		"eor %1,%A0" "\n\t"
		"mov __tmp_reg__,%1" "\n\t"
		"lsr %1" "\n\t"
		"lsr %1" "\n\t"
		"eor %1,__tmp_reg__" "\n\t"
		"mov __tmp_reg__,%1" "\n\t"
		"lsr %1" "\n\t"
		"eor %1,__tmp_reg__" "\n\t"
		"andi %1,0x07" "\n\t"
		"mov __tmp_reg__,%A0" "\n\t"
		"mov %A0,%B0" "\n\t"
		"lsr %1" "\n\t"
		"ror __tmp_reg__" "\n\t"
		"ror %1" "\n\t"
		"mov %B0,__tmp_reg__" "\n\t"
		"eor %A0,%1" "\n\t"
		"lsr __tmp_reg__" "\n\t"
		"ror %1" "\n\t"
		"eor %B0,__tmp_reg__" "\n\t"
		"eor %A0,%1"
		: "=r" (__ret), "=d" (__tmp)
		: "r" (__data), "0" (__crc)
		: "r0"
	);
	return __ret;
}
////////////////////////////////////////////////////////////////////////
#endif /* _UTIL_CRC16_H_ */

would be another option.

If the two mostly-empty sketches I posted previously don't pass/fail consistently in the same way, that points toward some kind of hardware issue, as you said originally. You had a fix that worked briefly until it didn't.

Including OneWire.h causes OneWire.cpp to be compiled, which includes util/crc16.h and calls the function, just as the other sketch does. If you look directly at the file and saw that the initial underscore was missing somehow, that would explain it. But maybe there's a flaky bit in the memory that points to the second character of the function name instead; or something like that.

For example, compiling

void xyz_update(); // declaration

void setup() {
  _xyz_update(); // not quite the right name
}

void loop() {}

fails the same way:

  • error: '_xyz_update' was not declared in this scope
  • note: suggested alternative: 'xyz_update'

because a function with a very similar name was declared -- the compiler is trying to be helpful. That's just as if the declaration in crc16.h got misread in the same way.