LGT8F328P Arduino 'clones'

Arduino projects on the go
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: LGT8F328P Arduino 'clones'

Post by Martin »

PhilG's frequency-hopping code uses a bit of EEPROM to store configuration values (fewer than 30 bytes). The LGT8F328P doesn't have EEPROM, but it can emulate it by using a bit of its FLASH memory. Here's a sketch to test if it works. I used the Nulllab board manager, with EEROM Size: [sic] in the Tools menu set to 1KB.

It seemed to work, but not on the very first time of writing. A more severe test may be needed if the EEPROM implementation has bugs, but this will do for a start.
Attachments
eepromTest.zip
(1.1 KiB) Downloaded 78 times
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: LGT8F328P Arduino 'clones'

Post by Martin »

Here are two of the LGT8F RF-NANOs running PhilG's "lockdown project" code. No modifications other than setting the correct pins for CE and CSN:

RF24 radio(9, 10);

You have to set the EEROM SIze to 1KB, because PhilG's sketch uses a handful of EEPROM bytes to store settings.

User avatar
Flynn
Posts: 64
Joined: 17 Feb 2018, 14:48

Re: LGT8F328P Arduino 'clones'

Post by Flynn »

I watched the video.......Who cares about being responsible!... should make a good wifi disrupter! I couldn't get your eeprom test sketch to save anything in the pseudo eeprom, just reported being empty after the power down. Using DIY board,32MHz,32MHz, LQFP32, 1k, 115200, not sure what I am doing wrong. I also have a problem getting this board to receive a valid Tx signal too....but that is on another thread. I thought setting the 1K eeprom buffer might fix it but as it doesn't work on the eepromtest.ino its little wonder it hasn't (yet) fixed the Receive problem. Any pointers? :)
You only ever need two tools....WD40 and duct tape.
If it doesn't move when it should use the WD40 and if it moves and it shouldn't use the tape.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: LGT8F328P Arduino 'clones'

Post by Martin »

I'm not sure why the EEPROM test isn't working on your LGT8F RF-NANO. You're using the same settings as me. Try altering the EEROM size down to 0KB, upload reset, power down, then back to 1KB, upload, reset, power down again. Maybe try 2KB size too. I remember mine behaved a bit weird the first time I tried it, but I can't replicate that weirdness now.

I was upset by the lack of crystal too. I spent a long time getting my ISP SWD programmer working, thinking that would allow me to use it, and then I realized that the only 16MHz crystal on the board is the one fitted to the nRF24L01+ :x

Besides the EEPROM thing, then the other issue with using one "ordinary" Nano, and one LGT8F could be timing. The ordinary Nano will be spot on, by definition, and it has a crystal. The LGT8F will be a percent or two fast or slow - and anyway it's running at roughly twice the clock speed and also executes many instructions in a single cycle that the Atmel MCUs take two cycles to execute.

I don't know how sensitive Phil's sketch is to a slight mismatch in timing between the transmitter and receiver hopping rates. It uses timer2 interrupts set to fire every 5ms. I assume those will still be right even when the MCU is running at 32MHz, but there will still be the slight mismatch due to the lack of a crystal.

I'll investigate the timer interrupts next to see if they're in the right ballpark, then try one of my own vanilla Atmel Nanos for the transmit and/or receive side and check for compatibility.
User avatar
Flynn
Posts: 64
Joined: 17 Feb 2018, 14:48

Re: LGT8F328P Arduino 'clones'

Post by Flynn »

Thanks for that Martin. I have tried the examples eeprom_write, eeprom_read and eeprom_clear. The write seems to indicate it is writing (at least in the serial monitor) but the read sketch just returns zeros in all locations and the clear sketch doesn't seem to complete because it is supposed to light the led when it finishes but it never does.

I will try your suggestion about setting the eeprom size back to zero and starting again...

I did see something about setting a flag to disable the eeprom to return the memory to flash program space but I've lost it at the moment... more perseverance needed!
You only ever need two tools....WD40 and duct tape.
If it doesn't move when it should use the WD40 and if it moves and it shouldn't use the tape.
User avatar
Flynn
Posts: 64
Joined: 17 Feb 2018, 14:48

Re: LGT8F328P Arduino 'clones'

Post by Flynn »

Martin, what version of EEPROM.h do you have?

I have version 2.0

I found the flag.. it is in the optiboot bootloader -
// enable 1KB E2PROM (for LGT8F328P)
ECCR = 0x80;
ECCR = 0x4C;

But seeing as I don't have the requisite programmer I don't think I will mess with that. I assume there is no way to read the flags without a suitable programmer?

I tried resetting the eeprom size to many different values.. no change

I'm off for a beer!
You only ever need two tools....WD40 and duct tape.
If it doesn't move when it should use the WD40 and if it moves and it shouldn't use the tape.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: LGT8F328P Arduino 'clones'

Post by Martin »

I'm using version 2.0.0 On Linux Mint with Arduino 1.8.19 the file that gets included is at:

~/.arduino15/packages/nulllab avr compatible boards/hardware/avr/2.0.0/libraries/E2PROM/EEPROM.h

first few lines look like this

Code: Select all

/*
  EEPROM.h - EEPROM library
  Original Copyright (c) 2006 David A. Mellis.  All right reserved.
  New version by Christopher Andrews 2015.
  Modifications from https://github.com/LGTMCU/Larduino_HSP
  New Modifications 20201106 by https://github.com/SuperUserNameMan/ :
I just tried rigging up a regular Keywish RF Nano V3.0 (genuine Atmel ATmega328) as the transmitter, staying with the LGT8F RF-NANO for the receiver. Had to swap the CE and CSN pins over on the transmitter sketch but otherwise identical code.

RF24 radio(10, 9);

It works, but the servos attached to the (LGT8F) receiver seem a bit jerky, as though lots of packets are being missed.

Also tried an LGT8F transmitter with an Atmel receiver. That works too, and better than the opposite combination.

I'll do some more tests. I have some ideas of how to fix any timing issues so that Atmel and Logic Green MCUs will play nice together.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: LGT8F328P Arduino 'clones'

Post by Martin »

Did the timer test. As you'd expect, the timers are running at roughly double speed on the 32MHz chip (the one I'm currently testing is actually about 1.2% slower than 32MHz). millis() micros(), delay(), delaymicroseconds() and the baud rate for the Serial() do run at (approximately) the right speeds because the Arduino "operating system" knows the MCU clock speed. The compiler sets the value of F_CPU to the target clock speed at compile time, so it's possible to write code that checks that speed and calcuates the correct timer settings to allow for any (reasonable) clock speeds.

Phil's transmitter code just directly sets the timer registers and doesn't take account of F_CPU (a very reasonable thing to do, as he was writing it specifically to run on 16MHz Arduinos). So the 5ms interrupt his code sets up for sending packets is actually trying to send them every (roughly) 2.5ms. It's an easy change to alter his code to compile to give correct timer settings for both F_CPU = 32000000 and F_CPU = 16000000, but there may be a better way of getting crystal-accurate timing from the nRF24L01 chip, which I'll investigate first.

Edit: as far as I can see, there's no obvious way to get accurate clock data from the nRF24L01+.

I've now done some modified versions of Phil's Enc_v5... rx and tx sketches that automatically adjust to run with the right timer interrupt rates on any of the usual clock speeds. "Arduinos" run at - 8MHz, 12MHz (rare), 16MHz, 20MHz (also rare), and now 32-(ish)MHz. The tx code needs 5ms interrupts. The rx code switches between 5ms and 6ms depending on how 'synced' it thinks it currently is. I've posted them in Phil's Frequency hopping experiments on the NRF24 thread (top of page 22).
User avatar
Flynn
Posts: 64
Joined: 17 Feb 2018, 14:48

Re: LGT8F328P Arduino 'clones'

Post by Flynn »

Impressive work Martin.

I have got my combo working. I am a windows man.. mainly because I can never remember all the commands you need to troubleshoot a Linux build. There is something screwy in my windows Arduino IDE installation. I do have a linux box, a minisforum mini pc with both Ubuntu and Zorin installed. I cannot get the CH340 driver to install in Ubuntu but it works straight out of the box in Zorin and if I program the LGT in linux it works, both in the eeprom test programs and in the Rx sketch... so..... I removed and cold re-installed arduino ide in windows but it is no better, but it is my installation because I have just installed the IDE on a brand new win11 installation and that works....ho hum..... more scrabbling around in the dark needed! :roll:
You only ever need two tools....WD40 and duct tape.
If it doesn't move when it should use the WD40 and if it moves and it shouldn't use the tape.
Post Reply