View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
Serial num in EEPROM & FLASH |
Posted: Mon Dec 17, 2018 8:19 am |
|
|
Hello All,
I have one project with pic12F1840 mcu. I'm searching easy method to store int32 serial number in EEPROM, when program MCU. I saw this one : #SERIALIZE(....). Can be used, or something else?
Thanks for your attention!
Last edited by kmp84 on Fri Dec 28, 2018 4:34 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Dec 17, 2018 8:39 am |
|
|
It really depends what programmer you are using?.
#SERIALIZE, works with the CCS programmers, and their CCSLoad/ICD units.
It allows you to write a number that extracted from a file that you create.
If you are not using the CCS programmers, then you would have to look to
see if your unit offered any similar sort of ability... |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Dec 17, 2018 9:58 am |
|
|
Hi mr.Ttelmah,
I'm using CCS ICD64. How to use this option with auto increment serial number? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Mon Dec 17, 2018 10:42 am |
|
|
Code: | #SERIALIZE(dataee=0, binary=4, file="serial_number.txt", log="serial_number_record.txt") |
This tells the programmer software (ccsload.exe) to open a file named "serial_number.txt". That file contains one item: an ascii number. If you create serial_number.txt, and put "1" on the first line, save & exit, then program your PIC using CCSLoad, it will reserve the first 4 bytes of the PIC's EEPROM to contain the serial number, and it will "burn" 1 into that reserved memory area. CCSLoad then erases the "1" in "serial_number.txt", replaces it with "2", and saves the file. Everything is logged in a separate text file, "serial_number_record.txt".
The next PIC you program with that same hex file will automatically get a serial number of 2.
The serial number is burned into the EEPROM LSB first. That is, the LSB of the int32 serial number will be at EEPROM address 0, and the MSB will be at EEPROM address 3. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Mon Dec 17, 2018 2:49 pm |
|
|
I know it was asked a million times before. Any way to do it directly from CCS IDE? My tool chain is CCS IDE, import to MPLAB (hex or coff), program or debug with ICD3. What was required in one project was a different seed for a random generator for every unit. The goal was to delay startup and wait for the light show to end after a very frequent power outage and to do the same after a badly synchronized generator switches back to mains. And than turn on every one of the 200+ slot machines at a different time, with zero crossing to prevent the fuses (or 500+$ monitors) from blowing. It would be nice to have a feature in CCS to generate some kind of number after every build and burn it to EEPROM at program time. It is not hard to do it manually for 200 units, but it is boring. And computers are made to do the boring stuff quickly :-) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Dec 17, 2018 2:53 pm |
|
|
The IDE uses CCSLoad to do the actual programming, so will accept the
SERIALIZE command. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Mon Dec 17, 2018 3:23 pm |
|
|
Unfortunately I don't own any CCS supported programmer (not expensive, but too expensive for a one-off project). I was "raised" on Microchip tools and one of the main reasons for choosing CCS was the level of integration between the CCS and Mplab. I believe I'm not the only one doing the programming in CCS and using ICD or Pickit to do the actual programming and debugging. That is why I have a semi secret wish for CCS to support something like this directly from the IDE, regardless of the programmer. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Mon Dec 17, 2018 3:24 pm |
|
|
PrinceNai wrote: | I know it was asked a million times before. Any way to do it directly from CCS IDE? My tool chain is CCS IDE, import to MPLAB (hex or coff), program or debug with ICD3. What was required in one project was a different seed for a random generator for every unit. The goal was to delay startup and wait for the light show to end after a very frequent power outage and to do the same after a badly synchronized generator switches back to mains. And than turn on every one of the 200+ slot machines at a different time, with zero crossing to prevent the fuses (or 500+$ monitors) from blowing. It would be nice to have a feature in CCS to generate some kind of number after every build and burn it to EEPROM at program time. It is not hard to do it manually for 200 units, but it is boring. And computers are made to do the boring stuff quickly :-) |
Easy.
1. Shelve your ICD3.
2. Purchase an ICD-U64.
Done. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 478 Location: Montenegro
|
|
Posted: Mon Dec 17, 2018 3:27 pm |
|
|
Very likely a much faster way to have what I want. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Dec 18, 2018 12:17 am |
|
|
Yes.
If you think about it, making serialize work, requires the programmer
code to do this. For the MicroChip programmer, the code is MicroChip's
so it'd require them to add support for this. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Tue Dec 18, 2018 5:53 am |
|
|
Thank you All and mr.newguy! You saved my time for test and check!
Best Wishes! |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Tue Dec 18, 2018 6:16 am |
|
|
Is this possible with PICKIT3? |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Tue Dec 18, 2018 8:31 am |
|
|
P.S this is function to get back serial num from EEPROM:
Code: |
#include <12F1840.h>
#device *=16
#device WRITE_EEPROM = NOINT
#fuses INTRC_IO,PROTECT,MCLR,PUT,BROWNOUT,NOWDT,CPD
#use delay(clock=32MHz)
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors)
#SERIALIZE(dataee=0, binary=2, file="serial_number.txt", log="serial_number_record.txt")
unsigned int16 SnNumU16;
unsigned int16 READ_U16_EEPROM(unsigned int8 n) {
int i;
unsigned int16 data;
for (i = 0; i < 2; i++)
*((int8*)&data + i) = read_eeprom(i + n);
return(data);
}
void main(void){
delay_ms(100);
SnNumU16 = READ_U16_EEPROM(0);
printf("\r\n Sn:%LU", SnNumU16);
for(;;){
; // User Code
}
} |
|
|
|
mdemuth
Joined: 16 Apr 2007 Posts: 71 Location: Stuttgart, Germany
|
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Thu Dec 27, 2018 6:36 am |
|
|
Hello,
I want to ask you is it possible to use "#serialize" directive with mcu without eeprom? Also can be stored serial number with format like this: "ABCD0000001" and auto increment? (ABCD const string + string number)
Thanks! |
|
|
|