Go Down

Topic: ATmega328P targeted at low-power battery use: help needed with baby steps! (Read 3822 times) previous topic - next topic


I'm working on the OpenTRV project (I expect I can't post links initially and so I won't even try, but you can find it with your favourite search engine if you wish) for saving energy in heating systems with a smart retrofit Thermostatic Radiator Valve and some stuff to call for heat from a boiler centrally.

I already have a PICAXE prototype up and running at my house across multiple nodes each controlling wireless valves via RFM22/RFM23, etc.

I want to build a parallel ATmega/Arduino stack which I expect to be able to do more sophisticated things, and more power-efficiently.

In some configurations our hardware will be powered by a couple of AA rechargeables so operation down to around 2V is needed, but operation at 3.3V (or 5V) may also happen, eg at mains-powered nodes.

I have so far succeeded in using my UNO as ISP to get a (8MHzRC/8, see below) bootloader into a couple of blank ATmega328P chips (so far as I can tell), but moving on to program them a TTL-232R-3V3 has me foxed so far.

I am running IDE 1.0.3 on a Mac.

I have added this to the end of the boards.txt file:

Code: [Select]
atmega328bb2AA.name=ATmega328 on a breadboard (8 MHz internal clock / 8), 2xAA supply 1.8V BOD




Note in particular the fuses (so the CPU clock is 1MHz, and BOD is set at 1.8V) and the f_cpu (set to 1MHz correctly) I hope.

Attempting to load the blink sketch spits out, after a pause:

avrdude: stk500_recv(): programmer is not responding

My best guess was that I probably also had to reduce "upload.speed" to 7200, but no luck so far.

I have automatic reset *apparently* working (reset tied high with 10K, via 100nF to RTS, so a LED on digital pin 13 (PB5) blinks when the IDE opens the connection and slowly thereafter).

I'm pretty familiar with electronics and computing, but have no AVR-specific test gear.  I have a couple of these 328Ps, an UNO and a Leonardo.

Any other clues?




Would need to review your fuse settings with a fuse calculator, make sure they make sense.

I have not tried to download a sketch via serial into a slow running part; serial speed lkely needs to be reduced as you noted (to 57600/8, or 115200/8).
Might also just have to download via ICSP (no bootloader) using File:Upload Using Programmer option.

Should change your descriptions to say 1 MHz also, not 8.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Coding Badly

...but moving on to program them a TTL-232R-3V3 has me foxed so far.

Why bother?  You have a method to program the target.  Why do you also need a bootloader?

Because if possible I want for me, and others playing with OpenTRV, to be able to be able to reprogram in situ (frequently during development) without levering chips in and out, as I do with the PICAXE for example, and without buying expensive or non-main-line hardware.  IE I want the development cycle to be cheap and fast and easy.

And I didn't find out how to get anything other than the bootloader into my ATmega32Ps via my UNO, but if someone could point me at the generic way to do that I'd be interested.

But note that it may simply be impractical given that 5V from the UNO would be toxic to some of the main components on my target system, and other in-situ users of the SPI bus in particular.

Fuse settings: I have run them back and forth through a calculator, and the brain of someone fairly experienced in AVR stuff, so I may have got them wrong still, but not for want of cross-checking!

Yes, probably I should change the name!



PS. But I likely need to be educated about what the best way to do things is in this AVR/Arduino environment: every dev ecosystem is different.


The new optiboot build says:
make atmega328 AVR_FREQ=1000000 BAUD_RATE=57600
BAUD RATE CHECK: Desired: 57600, Real: 62500, UBRRL = 1, Error=-8.5%
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=1000000  -DBAUD_RATE=57600 -DLED_START_FLASHES=3       -c -o optiboot.o optiboot.c
optiboot.c:252:2: error: #error BAUD_RATE error greater than -5%
optiboot.c:277:2: error: #error Unachievable baud rate (too fast) BAUD_RATE
make: *** [optiboot.o] Error 1

A bit of research suggests that 9600 should work OK.
Also 31250 (MIDI bitrate; it might be widely implemented.)

Does the bootloader on the AVR auto-detect the baud of the incoming data, eg can I just set 9600 in the stuff in boards.txt now?

Or does that value get baked into the boatloader itself from the boards.txt file so I'll have to change it and reload the ATmegas?



OK, used the settings from the tutorial (with the core/variant adjustment) in the IDE's boards.txt:

Code: [Select]
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)




to burn a new bootloader, and that all works fine.  I can upload the blink sketch via my FDTI cable, and adjust it and re-upload, just fine.

So my USB and auto-reset and so on is fine by the looks of it.

So I think that nominally, using a baud of 7200 with the 1MHz clock should work.  Maybe I have to adjust some of the delays in the ArduinoISP, or get myself a new bootloader .hex file with the F_CPU set for 1MHz and baud set for 9600 at that clock speed?  (If the latter, I don't yet know how to do that.)




as I do with the PICAXE for example

Why? If you jut put in a minijack and down load circuit, you can program a PicAxe in circuit.

I don't understand your point, sorry!

That is what I *do* with my PICAXE, eg here, with jack plugged in:


I would like a load/test of new code to be as easy for the AVR version, even when the chip *cannot* be removed and has <5V peripherals as on the board above.




Just put this circuit on your board with a mini-jack - though that is optional - and you can program in circuit:

And use the serial monitor for debugging.

I'm really not following.

That *is* how I use the PICAXE already.




Then why can't you program and debug in circuit? Why do you pull the chip out to reprogram?

I don't.

What I'm trying to achieve with the ATmega is the same ease of reprogramming as I already have with the PICAXE.




Oops, when you mentioned the PicAxe it was an example of what you want to do with the AT chips. Sorry I misunderstood.

Anyone got a precompiled 1MHz-friendly ATmega328P bootloader.hex file?

I've tried a few others without success.

I do fine at 8MHz, and have been working on the low power 'scheduler' core for my code instead, with rather more progress!



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131