Help please to convert ATTiny registers to Pro-Mini equivalent (Chirp sensor)

Hi Folks, I am a bit of a hack and this one is above my pay grade so I am looking for some help to migrate this code from an ATTiny44 to a pro mini.

Summary: Get chirp code running on a Pro Mini. Code is in the src directory on github https://github.com/Miceuz/i2c-moisture-sensor/tree/master/src

Reason: I have 5 of the i2c chirp moistire sensor boards (i2c version) and I want to use them as sensors in my MySensors wireless network. I have the pro-mini's running on AA batteries and sleeping at just a few uA's but it does not play nice with the I2C. I want to integrate the code over to run on the pro-mini and desolder the ATTiny on the chirp boards and solder directly onto the chirp board sensors from the pro-mini.

When I try and compile the source for the pro mini I get the following errors. I have googled but I have myself in a spin and am not making much progress. ie. main.c:58: error: 'ADMUXB' undeclared - I have no idea what to do with this!

Hopefully someone familiar with the registers can provide the equiv mapping off the top of their heads :)

Once I get it working I will of course post the code and details as I think this will make a really interesting and accurate wireless sensor.

THANKYOU!

Build options changed, rebuilding all sketch\main.c: In function 'ledSetup':

main.c:15: error: 'DDRA' undeclared (first use in this function)

define LED_DDR DDRA

^

sketch\main.c:38:5: note: in expansion of macro 'LED_DDR'

LED_DDR |= _BV(LED_A) | _BV(LED_K);

^

sketch\main.c:15:17: note: each undeclared identifier is reported only once for each function it appears in

define LED_DDR DDRA

^

sketch\main.c:38:5: note: in expansion of macro 'LED_DDR'

LED_DDR |= _BV(LED_A) | _BV(LED_K);

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:14: error: 'PA0' undeclared (first use in this function)

define LED_A PA0

^

sketch\main.c:38:20: note: in expansion of macro 'LED_A'

LED_DDR |= _BV(LED_A) | _BV(LED_K);

^

main.c:13: error: 'PA1' undeclared (first use in this function)

define LED_K PA1

^

sketch\main.c:38:33: note: in expansion of macro 'LED_K'

LED_DDR |= _BV(LED_A) | _BV(LED_K);

^

main.c:16: error: 'PORTA' undeclared (first use in this function)

define LED_PORT PORTA

^

sketch\main.c:39:5: note: in expansion of macro 'LED_PORT'

LED_PORT &= ~_BV(LED_A);

^

sketch\main.c: In function 'ledOn':

main.c:16: error: 'PORTA' undeclared (first use in this function)

define LED_PORT PORTA

^

sketch\main.c:44:5: note: in expansion of macro 'LED_PORT'

LED_PORT |= _BV(LED_A);

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:14: error: 'PA0' undeclared (first use in this function)

define LED_A PA0

^

sketch\main.c:44:21: note: in expansion of macro 'LED_A'

LED_PORT |= _BV(LED_A);

^

sketch\main.c: In function 'ledOff':

main.c:16: error: 'PORTA' undeclared (first use in this function)

define LED_PORT PORTA

^

sketch\main.c:48:5: note: in expansion of macro 'LED_PORT'

LED_PORT &= ~_BV(LED_A);

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:14: error: 'PA0' undeclared (first use in this function)

define LED_A PA0

^

sketch\main.c:48:22: note: in expansion of macro 'LED_A'

LED_PORT &= ~_BV(LED_A);

^

sketch\main.c: In function 'ledToggle':

main.c:16: error: 'PORTA' undeclared (first use in this function)

define LED_PORT PORTA

^

sketch\main.c:52:5: note: in expansion of macro 'LED_PORT'

LED_PORT ^= _BV(LED_A);

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:14: error: 'PA0' undeclared (first use in this function)

define LED_A PA0

^

sketch\main.c:52:21: note: in expansion of macro 'LED_A'

LED_PORT ^= _BV(LED_A);

^

sketch\main.c: In function 'adcSetup':

main.c:58: error: 'ADMUXB' undeclared (first use in this function)

ADMUXB = 0;

^

sketch\main.c: In function 'adcReadChannel':

main.c:71: error: 'ADMUXA' undeclared (first use in this function)

ADMUXA = channel;

^

sketch\main.c: In function 'stopLightMeaseurement':

main.c:111: error: 'GIMSK' undeclared (first use in this function)

GIMSK &= ~_BV(PCIE0);

^

sketch\main.c: In function '__vector_3':

main.c:120: error: 'GIMSK' undeclared (first use in this function)

GIMSK &= ~_BV(PCIE0);//disable pin change interrupts

^

sketch\main.c: In function 'getLight':

main.c:15: error: 'DDRA' undeclared (first use in this function)

define LED_DDR DDRA

^

sketch\main.c:139:5: note: in expansion of macro 'LED_DDR'

LED_DDR |= _BV(LED_A) | _BV(LED_K); //forward bias the LED

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:14: error: 'PA0' undeclared (first use in this function)

define LED_A PA0

^

sketch\main.c:139:20: note: in expansion of macro 'LED_A'

LED_DDR |= _BV(LED_A) | _BV(LED_K); //forward bias the LED

^

main.c:13: error: 'PA1' undeclared (first use in this function)

define LED_K PA1

^

sketch\main.c:139:33: note: in expansion of macro 'LED_K'

LED_DDR |= _BV(LED_A) | _BV(LED_K); //forward bias the LED

^

main.c:16: error: 'PORTA' undeclared (first use in this function)

define LED_PORT PORTA

^

sketch\main.c:140:5: note: in expansion of macro 'LED_PORT'

LED_PORT &= ~_BV(LED_K); //flash it to discharge the PN junction capacitance

^

main.c:154: error: 'GIMSK' undeclared (first use in this function)

GIMSK |= _BV(PCIE0);

^

sketch\main.c: In function 'wdt_disable':

main.c:169: error: 'CCP' undeclared (first use in this function)

CCP = 0xD8;

^

sketch\main.c: In function 'wdt_enable':

main.c:174: error: 'CCP' undeclared (first use in this function)

CCP = 0xD8;

^

sketch\main.c: In function 'loopSensorMode':

main.c:208: error: 'GIMSK' undeclared (first use in this function)

GIMSK &= ~_BV(PCIE0);//disable pin change interrupts

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

sketch\main.c: In function 'setupPowerSaving':

main.c:238: error: 'PRUSART1' undeclared (first use in this function)

PRR = _BV(PRTIM0) | _BV(PRTIM1) | _BV(PRTIM2) | _BV(PRSPI) | _BV(PRUSART0) | _BV(PRUSART1); //shut down everything we don't use

^

main.c:239: error: 'ACSR0A' undeclared (first use in this function)

ACSR0A = _BV(ACD0); //disable comparators

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:239: error: 'ACD0' undeclared (first use in this function)

ACSR0A = _BV(ACD0); //disable comparators

^

main.c:240: error: 'ACSR1A' undeclared (first use in this function)

ACSR1A = _BV(ACD1);

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from sketch\main.c:2:

main.c:240: error: 'ACD1' undeclared (first use in this function)

ACSR1A = _BV(ACD1);

^

main.c:241: error: 'ADC7D' undeclared (first use in this function)

DIDR0 = _BV(ADC3D) | _BV(ADC5D) | _BV(ADC7D);//disable input buffers for analog pins

^

exit status 1 'DDRA' undeclared (first use in this function)

Are you looking to port this “directly” to an ATmega328p in the mini, or would you rather port it to “Arduino”?
The latter might be a bit more work, but you’d end up with code that would probably be easier for you to understand…

ATmega328 does not have PORTA. It has PORTB, PORTC (normally the analog), and PORTD. Pick two pins (probably on the same port.) The code does something funky to read light levels using the LED (LEDs can measure light input, as well as glow), so I’m not sure whether you’d be able to replace it with digitalWrite()/etc.

PINMUXB controls ATtiny441 features that are not present on the ATmega328. Fortunately, it’s not using any of those features (PINMUXB=0), so you should be able to just delete that line. ADMUX should be replaced (approximately, anyway) by just ADMUX. You might be able to use analogRead() instead of manipulating the ADC registers directly.

GIMSK is replaced by multiple registers on the 328. Since it seems to be using only Pin Change interrupts, you want PCICR.

CCP is a protection mechanism for the clock control and other registers. I don’t think the 328 has this.

PRUSART1 and PRR are power-control things; you said you already had low power working, and the 328 doesn’t have a 2nd USART anyway…

DIDR9 is for disabling the digital input buffers (more power saving.) I don’t know if there’s an equiv for 328

ACSRx are for the analog comparators. Since the 328 only has one, it only has ACSR… instead of ACSR0… and ACSR1…

THANKYOU westfw! Some great info to get me started there.

I would love to port this to "Arduino" as I want to incorporate it into existing arduino MySensors code.