ATMEGA328P SET UNIQUE SERIAL NUMBER

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I'm working with LoRaWAN, each device need to have a unique ID called Device EUI, so I need to assign each device with a unique address. Well I could always change the code that writes to the flash and place a diffent EUI every time, but i would have to compile again de source code and that woul take time since i´m proggraming about 6000 devices, besides that, the source code is secret and we don´t want that the technincal group that would do this job in our company see it. Is there a way using the production file? I would like to do this without altering the source code every time. By the way, we are using Atmel Studio, Atmel ICE, and the microcontroller is a atmega328p, since this is the Arduino microcontroller i would like to clarify that we are not using arduino.

 

Thanks in Advance

Sebastian Arboleda.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not store an ID in the EEPROM?  Then you can adjust it after the programming is finished?  Have some external serial command that can set it to whatever you want. Then nobody needs to see the code at all.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Fri. Jul 31, 2020 - 10:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The app should run for about 8 years without human intervention, it has plenty of external WDT circuits and is battery (no rechargable) powered to acomplish this, so power consumption is minimal. In a previous development we tried to do it through the EEPROM by modifying the .eep file, however we saw in stress tests that this consumed us additional battery, also sometimes the function of reading the EEPROM blocked the system, for this reason we decided to stop to use this option.

 

 

typedef struct{
    char edevaddr[9];
    char edeveui[17];
} keys ;

keys KEYS;

/************************************************************************/
/*			READ THE EEPROM	                                */
/************************************************************************/
   cli();
   eeprom_busy_wait();
		
   if (eeprom_is_ready()){
      eeprom_read_block((void*)&KEYS	,(const void*)ADR0	,sizeof(KEYS));
   }
sei();

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You only need to read the eeprom on startup, so how could this cause ongoing extra power consumption and ‘blocking’?

You would also want to put a crc check on the stored data to ensure the data is not corrupt.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
so how could this cause ongoing extra power consumption and ‘blocking’?

 

ok, maybe i could try it. Can i run it just when PORF flag is HIGH and store the EUI in the .noinit section?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That seems a little excessive for something that takes microseconds to execute once on powerup.besides, if you rely on the ram contents being correct on a reset other than power on, then expect problems. Eg: if you had a watchdog reset, then a crash may have scrambled the ram.

Possible solutions are:
1. Have a script that generates the eui in the source file then compile
2. Have a script that modifies the hex file
3. Use ISP to program eui in specific address in flash
4. Store eui in eeprom. Use ISP to program eeprom.
5. Eui in eeprom. Have code to load eeprom through various means.
6. If you have a bootloader, have app code call flash write function to write eui into flash

Whatever you do, you want a crc or other means to validate the eui. You want to detect if the eui is not programmed or corrupt. You can then decide a fallback strategy - default the eui?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
1. Have a script that generates the eui in the source file then compile

 

I want to try this option, but how can i compile from a script? Can you guide my a little bit to find the correct answer?

 

Thank you for your help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to try this option, but how can i compile from a script? Can you guide my a little bit to find the correct answer?

How do you normally compile? If you use Atmel Studio 7, it generates a makefile methinks. You should be able to Google how to do this. Something like Atmel Studio7 compile commandline 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You can buy serial number chips from people like Dallas/Maxim.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doesn't the ATMEGA328P have a unique serial number burned into the chip ? At least unique amongst all 328s.

 

https://www.thethingsnetwork.org... and many more links.

 

Some Arduino code: https://gist.github.com/speters/...

Last Edited: Sat. Aug 1, 2020 - 01:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
You can buy serial number chips from people like Dallas/Maxim.

+1

 

But, for a LoRaWAN node, you are also going to need secure key storage. You'll likely also need that for your "cloud" connection.

 

For this, Microchip have various products available ...

 

other manufacturers are available 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Just created an script that modifies main.c source file, then build and compile the proyect and finally upload the .elf file to the microcontroller. It saves me a lot of time.

 

obdevel wrote:
Doesn't the ATMEGA328P have a unique serial number burned into the chip ? At least unique amongst all 328s.

 

Yes, it has it, but i can´t use. Since we develop de IoT LoRaWAN network we have an special EUI codification where this ID is associated with a water metter code.

 

awneil wrote:

But, for a LoRaWAN node, you are also going to need secure key storage. You'll likely also need that for your "cloud" connection.

 

For this, Microchip have various products available ...

 

We are worink with microchip technology, the other LoRaWAN keys are mannaged internally by the code. We just need to program the Device EUI in each device.