OneWireHub icon indicating copy to clipboard operation
OneWireHub copied to clipboard

Compile errors with new ATTiny chips

Open picsil opened this issue 5 years ago • 8 comments

This code works great on an ATTiny85. However I need to use the newer ATTiny 1-series chips in my design. I am trying to use the ATTiny1614, but the code will not compile. Many errors, but most similar to this: In file included from /Users/reidforrest/software/picsil-i2c-bridge/picsil-i2c-bridge.ino:22:0: /Users/reidforrest/Documents/Arduino/libraries/OneWireHub/src/OneWireHub.h: In function 'constexpr timeOW_t operator""_us(long long unsigned int)': /Users/reidforrest/Documents/Arduino/libraries/OneWireHub/src/OneWireHub.h:11:56: error: call to non-constexpr function 'long unsigned int microsecondsToClockCycles(long unsigned int)' return timeOW_t(time_us * microsecondsToClockCycles(1) / VALUE_IPL); // note: microsecondsToClockCycles == speed in MHz.... ~~~~~~~~~~~~~~~~~~~~~~~~~^~~ In file included from /Users/reidforrest/software/picsil-i2c-bridge/picsil-i2c-bridge.ino:22:0: /Users/reidforrest/Documents/Arduino/libraries/OneWireHub/src/OneWireHub.h: In function 'constexpr timeOW_t timeUsToLoops(uint16_t)': /Users/reidforrest/Documents/Arduino/libraries/OneWireHub/src/OneWireHub.h:19:48: error: call to non-constexpr function 'long unsigned int microsecondsToClockCycles(long unsigned int)' return (time_us * microsecondsToClockCycles(1) / VALUE_IPL); // note: microsecondsToClockCycles == speed in MHz.... ~~~~~~~~~~~~~~~~~~~~~~~~~^~~

I can get the code to compile if I replace microsecondsToClockCycles(1) with a constant of 10 or 20 (MHz I can run the ATTiny1614 at) but it does not work. When the 1-Wire master sends a reset pulse (checked on scope) with duration within specs, OneWireHub does not respond to it at all. I get no further than that.

P.S. I am open to using another chip. My requirement is for both reliable 1-Wire slave emulation and I2C master. I have not been able to achieve the I2C master communication using an ATTiny85.

picsil avatar May 21 '20 17:05 picsil

@picsil Did you find a resolution for this or pivot to another emulator library? I would like to use the ATTiny214 but have the same issue as you describe above.

kiowadriver avatar Jul 13 '22 14:07 kiowadriver

Getting the same thing. I see that #102 suggests the following:

\Arduino15\packages\esp32\hardware\esp32\2.0.6\cores\esp32\Arduino.h
change
#define clockCyclesPerMicrosecond() ( (long int)getCpuFrequencyMhz() )
to
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )

But I see that in framework-arduino-megaavr-megatinycore/cores/megatinycore/wiring.c, it is defined as:

inline uint16_t clockCyclesPerMicrosecond() {
  return ((F_CPU) / 1000000L);
}

My C++ is horrible, should that uint16_t perhaps be marked as constexpr somehow?

RoganDawes avatar Mar 18 '23 07:03 RoganDawes

My thanks to SpenceKonde, who provided a fix for this almost immediately! See https://github.com/SpenceKonde/megaTinyCore/issues/925

Having eliminated all of the Serial calls from the example, it even fits within the available 4kB of flash available in the ATtiny412!

RoganDawes avatar Mar 20 '23 08:03 RoganDawes

As an aside, I'll note that because of a collossal blunder on my part I don't think the release that has the fix (and two other criticals), release 2.6.6, is available. In fact I forgot to release it before I disassembled PWM which I haven't finished reassembling (there's going to be a menu in future mTC releases that lets you choose the mapping for the PWM pins, so you can say more the second have of TCA0 onto port C on larger pincount parts, as those pins aren't very useful otherwise). But thee shoudl be a decent release of mTC soon

Personally I think that it's kinda silly to have macros like that at all but nobody asked me (is it that hard to do (F_CPU/1000000) - both are compile time constant and are optmized away to a single value. This is just a way to put a wrapper around it!) But that's far from the worst thing i've seen in the official core, and I'm the one responsible for breaking it by changing it from a #define to a always inline function (IIRC) but now changed it back to make things like this work

SpenceKonde avatar Apr 11 '23 00:04 SpenceKonde