Hello my first ever post, so hopefully in the right category for this at least!.
I have just purchased some LGT8F328P LQFP32 MiniEVB drop in alternative to the standard 'nano', the main reason it has a more stable external crystal than the normal resonator fitted.
I have installed in 'boards manager' version 1.06 of LGT8fx by dbuezas, this gives the options of internal oscillator OR external (but adds a note assumes 32MHZ)
I can load and run existing sketches perfectly when the 'internal' oscillator is selected.
When external is selected i can see on the processor pins 16MHz is being passed through but the s/w is expecting 32MHz so it is running at half speed. The project has a time clock on an oled display it can be seen its incrementing every two seconds not one. Also serial port no longer functions.
Please could someone advise where the 32MHz external frequency is actually defined and could be changed to 16MHz? The data sheet says it can support 1 MHz - 40MHz so i am missing where this can be set. There is very little documentation on these devices so any help would be appreciated.
If you can bear to, see this video: #156 LGT8F328P Replacement for ATMEGA328P (at 32MHz 😲) - YouTube he gets eventually to the issue of 16/32 MHz switching.
Thank you for the response, Unfortunately this video is concerned with making the internal oscillator run the processor at 32MHz
The issue i am trying to address is how to use the external crystal @ 16MHz.
Most videos only refer to older models that do not have an external crystal
Please see the actual part on AliExpress https://a.aliexpress.com/_ms5hKvW
OK. Sorry. WIth the standard AVR devices (ATMEGA328P etc.) the selection between the internal oscillator and the external crystal is made by changing a fuse setting (say by running AVRDUDE).
Here, it would appear that he has found some way of doing it through boards.txt.
If you can't find any help, then you could raise an issue on the github site: GitHub - dbuezas/lgt8fx: Board Package for Logic Green LGT8F328P LGT8F328D and LGT8F88D but it does look as if, when there is a crystal installed, it is assumed to be a 32MHz one.
Thanks again, i did try the boards.txt route with no joy, as its the 'assumption' that needs to be changed or items related to it.
I have just browsed through the english datasheet and a couple of things to try appeared which i will post here if it works.
Not ever placed a question on github, but there's always a first time!
I managed to work it out. The clock pre-scaler assumes 32MHz as its source, so with 16MHz it needs less division. The pre-scaler is defined in main.h of the lgt8fx core. I tried adding in some 'ifs' etc so it still worked on internal as well, but it all has to be programmed within 4 clock cycles which I couldn't achieve. Therefore I just edited the one scenario I was interested in. Probably there are other ways, but hopefully this will help if others use these variant boards.
Code snippet from main.h:
'''
// select clock prescaler
#if defined(F_CPU)
CLKPR = 0x80;
#if F_CPU == 32000000L
CLKPR = 0x00;
#elif F_CPU == 16000000L
// CLKPR = 0x01; // assumes 32MHz Crystal so divider is set to 2.
CLKPR = 0x00; // changed to divide by 1 for 16MHz external Crystal
// all other clock rates will stay working on 'internal', if needed on 'external' 16MHz, reduce divider number by 1.
'''
I have this board:
It has External 16Mhz crystal.
I have downloaded the boards.txt from
But I get errors compiling when choosing the external crystal?
What I'm doing wrong?
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\util\delay.h: In function 'void _delay_ms(double)':
<command-line>:0:8: error: 'build' was not declared in this scope
In file included from C:\Users\user\AppData\Local\Arduino15\packages\LGT8fx Boards\hardware\avr\1.0.6\cores\lgt8f/USBAPI.h:27:0,
from C:\Users\user\AppData\Local\Arduino15\packages\LGT8fx Boards\hardware\avr\1.0.6\cores\lgt8f/Arduino.h:243,
from sketch\Blink.ino.cpp:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\util\delay.h:174:19: error: invalid operands of types 'void' and 'double' to binary 'operator/'
__tmp = ((F_CPU) / 1e3) * __ms;
~~~~~~~~^~~~~
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\util\delay.h: In function 'void _delay_us(double)':
<command-line>:0:8: error: 'build' was not declared in this scope
In file included from C:\Users\user\AppData\Local\Arduino15\packages\LGT8fx Boards\hardware\avr\1.0.6\cores\lgt8f/USBAPI.h:27:0,
from C:\Users\user\AppData\Local\Arduino15\packages\LGT8fx Boards\hardware\avr\1.0.6\cores\lgt8f/Arduino.h:243,
from sketch\Blink.ino.cpp:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\util\delay.h:263:19: error: invalid operands of types 'void' and 'double' to binary 'operator/'
__tmp = ((F_CPU) / 1e6) * __us;
~~~~~~~~^~~~~
exit status 1
Error compiling for board LGT8F328.
Hi
I'm no expert but i will try and help.
I notice the version of boards is different to the one i used. I used version 1.0.6.
I do not see all those options for external crystal setting in the version i used.
Suggest maybe using version 1.0.6 and edit as i show above?
How did you get option for 16Mhz Crystal? My version has 32Mhz only?
The one I tried is lgt8fx/lgt8f at fb4f06a097e6a225a20d1b78d7e70eac160a6d5b · dbuezas/lgt8fx · GitHub
I downloaded original chinese driver now it works
my settings
driver
The CPU must be set at 16Mhz, crystal external 16Mhz.
That’s good you found the correct driver.
I had edited the file, although it says 32MHz if forced the code to 16MHz.
Thanks for your better solution
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.