LGT8F328P - sleep mode and WDT interrupt

Hi,

when trying to save some money and buy some really cheep pro mini clones from Ali, I noticed that there seems to be ATMEGA328P "compatible" chips. After some research, I'm almost sure I got one called LGT8F328P.

I did not really wanted to have them, but as I don't want to throw it away (sending back is not an option at all) I'm now trying my best to get them to work.

I hope my question is placed right here.

Here is my problem: I don't get WDT in interrupt mode running, neither power down sleep mode.

The following code works well on ATMEGA328P but not on LGT8F328P, so if anyone here knows how to get it working, please let me know.

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

volatile int mWDTCounter = 0;

ISR(WDT_vect)
{
    sleep_disable();
    mWDTCounter++;
}

void setup_watchdog(uint8_t aPrescalar)
{
    uint8_t wdtcsr = aPrescalar & 7;
  
    if ( aPrescalar & 8 )
    {
        wdtcsr |= _BV(WDP3);
    }

    MCUSR &= ~_BV(WDRF);
    WDTCSR = _BV(WDCE) | _BV(WDE);
    WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE);

}

void do_sleep(void)
{
    // send system to sleep
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    
    sleep_enable();

    // ensure WDT is enabled
    WDTCSR |= _BV(WDIE);

    // sleep the CPU (WDT will wake up)
    sleep_cpu();
    
    // disable sleep mode
    sleep_disable();
    
    // disable WDT while running
    WDTCSR &= ~_BV(WDIE);
    
}

void setup()
{
    Serial.begin(9600);
    Serial.println("Will setup WDT ");
    setup_watchdog(WDTO_4S);
}

void loop()
{
    Serial.print("mWDTCounter=");
    Serial.println(mWDTCounter, DEC);
    Serial.flush();

    do_sleep();
}

Thanks in advance for any tips.

MichaW:
when trying to save some money and buy some really cheep pro mini clones from Ali

That link doesn't work for me. Here is the product listing:
https://www.aliexpress.com/item/WAVGAT-Pro-Mini-ATMEGA328P-328-Mini-ATMEGA328-5V-16MHz-for-arduino-Nano-Microcontrol-Micro-Control-Board/32954774902.html

MichaW:
The following code works well on ATMEGA328P but not on LGT8F328P

Please explain exactly what you mean by "works well on ATMEGA328P but not on LGT8F328P". Do you mean that it doesn't compile, or that it compiles but doesn't give the expected behavior?

Neither link above works for me, but I guess it is this (WAVGAT pro mini):

which appears to be one of a number of arduino clones which also feature a clone ATmega328P chip.

The most professional looking one I have seen on sale using the Logic Green LGT8F328P is from Lolin. The information page is here. I've no idea if it works, but they have taken the trouble to produce a schematic and a software pack. There is provision for an optional crystal. I have in the past bough items from the Lolin Aliexpress shop (ESP32 and ESP 8266) and have been impressed by the quality, the quick delivery, that they supply a working tracking number and the customs valuation on the packet was more or less accurate.

However, for the LGT8F328P, although there seems to be some community interest in this and the spec appears to be better than the real ATMega328P, I'll wait until the support environment is a bit more mature before spending any time on this.

Wow, I really managed to mess up that link. I have now fixed it. The link you found is slightly different, but seems to point to the same listing.

I haven't looked for a while, but the last time I checked I was very much not impressed by the hardware package supplied by WAVGAT for these boards. I notice that at least they are no longer recommending that it be installed to the Arduino IDE installation folder, but the instructions assume that that the user is using Windows, that their user name is "Administrator", and that the default sketchbook path is being used. They also haven't figured out that you can bundle libraries with hardware packages, and want you to install their customized libraries to the libraries folder of the sketchbook, where they will likely cause problems for other boards. There is also no actual link to download these files. It's really sad to me that the people making products with the intent of selling them to the Arduino community don't take just a little bit of time to learn how to do the most basic things correctly. It's all very well documented and there are lots of good hardware packages out there to use as a reference. Surely the investment would pay off many times over in decreased support requests, improved feedback from customers, and increased sales. My understanding is that people work pretty cheap in China so even if they have to pay some complete dunce to spend a few dozen hours to figure it out, it's still insignificant.

The WeMos hardware package is a bit promising, but then they give instructions to install it to the Arduino IDE installation folder. If they can't even get that right, what kind of quality can you expect from the actual difficult parts? It's just depressing.

I guess part of the reason there is only limited professional integration in to the Arduino development environment is that the suppliers optimize the price so low that they can't pay for a even a few hours of consultancy. The manufacturer of the chip, Logic Green?, probably is looking only at the Chinese market and the "hobby market" part of that may not be so important so does not sponsor this activity.

For the OP's question, I can't suggest much apart from attempting to achieve the WDT configuration using purely native commands/registers (ie not dependent on the avr libraries) then refer to the (translated) datasheet for the LGT8F328P specific equivalents. The translated data sheets are not pretty and the illustrations are often missing but here is one example: https://www.electrodragon.com/w/images/b/b6/LGT8F88P_LGT8F168P_LGT8F328P_translated.pdf . It is precisely in the area of peripherals where differences between "near" clones and the original tend to show up.

There other attempts (possibly more readable) mentioned in or attached to this (long) thread: https://www.avrfreaks.net/forum/forbiden-tech-china-has-arrived?page=all

pert:
Please explain exactly what you mean by "works well on ATMEGA328P but not on LGT8F328P".

What I wanted to say is, that it compiled, can be uploaded and simply does not provide the expected behavior. It's neither going into sleep mode, nor is the WDT jumping into the ISR.

6v6gt:
Neither link above works for me, but I guess it is this (WAVGAT pro mini):

https://www.aliexpress.com/store/product/WAVGAT-Pro-Mini-ATMEGA328P-328-Mini-ATMEGA328-5V-16MHz-for-arduino-Nano-Microcontrol-Micro-Control-Board/1962508_32954774902.html

Yes, you are right. Not sure what messed up the link.

6v6gt:
The most professional looking one I have seen on sale using the Logic Green LGT8F328P is from Lolin. The information page is here. I've no idea if it works ...

That was great. They have an up to date Github page linked that contains the board libraries and headers in a more actual version than I was geting from the seller. And an example about PMU autowakeup that is exactly what I wanted to do.

For all who are interested in power saving, by using something simmilar to SLEEP_MODE_PWR_DOWN (and after removal of the power LED and step down converter) I got the board down to 0.025mA @3.3V. This is a bit more than original AVR requires, but still good enought for some battery powered sensors.

So thanks a lot for the help.

6v6gt:
the suppliers optimize the price so low that they can't pay for a even a few hours of consultancy.

I don't buy that argument. These boards are clearly marketed to the Arduino market. It's crucial to provide a beginner friendly experience for success in that market. A tiny investment to provide that will certainly pay off many times over. I don't expect them to do the right thing for moral reasons, but I do expect them to do it for economic reasons.

The OP seems to be happy which is good and seems to confirm that the software supplied by lolin/wemos appears to work under the circumstances tested.

Just to continue on the theme of proper support.
Using the Aliexpress claimed sales/orders figures for the boards known to use the LGT8F328P

wavgat pro mini ($1.50) 2666
wavgat nano ($2.00) 2700
lolin X1 LGT nano ($1.20) 90
electrodragon EDMI dev board ($1.40) unknown

There are surely many others but even if the total number of boards is 10,000 and the $ margin on each board must be tiny, so I guess there really isn't much in it for a commercial project even if you assume that volume would increase with better support.

When "non-standard" arduino chips (ATTinyXXX, ATmega328PB, etc. etc. ) are integrated into the Arduino eco-system most of the integration work is done by enthusiasts/volunteers, resulting in cores such as ( DrAzzy, Minicore, ESP8266(initially) etc. etc.) and not by Arduino, Microchip or the board retailers (with some exceptions like Digispark). So I guess the proper integration of these devices will be left as a community project, but I do agree that it is a pity that the activities by lolin, electrodragon etc. etc. to attempt to make these devices useable did not more closely follow the standards defined for Arduino addons.

Did you ever solve this? I do battery powered designs with extremely long sleep periods, this chip theoretically uses less power in deep sleep (1 vs 4.5 μA @3V) so it looked worth a second look?

Mattzzz:
this chip theoretically uses less power in deep sleep (1 vs 4.5 μA @3V) so it looked worth a second look?

Less power than what ?

Has anybody generaly tested the LGT8F328P Board in the Arduino IDE ?

  • Does it compile as an Arduino MIni / Pro ?

  • Do the Port IOs still work the same etc ?

  • Can you run it at the Double Clock 32MHz ?

I like the extra Pins E0-E3
I want to try using the 32MHz clock also.

Waiting on the Boards ordered.

Well I installed and Compiled for the LGT8F328P

I compiled :
FastIO
PWM Solo

Installed from here:

One problem, you need to set Board as:

LGT8F328P-LQFP32 MiniEVB

Not as: Board = Landuino w/ LGT8F328P - this generates loads of errors !

Figured out how to Program the Mini Board version :

Need to :
Download OCROBOT :
http://www.ocrobot.com/doku.php?id=downloads

Ocrobot Update :
http://www.ocrobot.com/doku.php?id=learing:alpha:2016042501

Also, the LED is on MISO / D12 , not on standard D13 / SCK as from schematic.

  • look at the board image below - LED ties to DI / MISO / D12.