View previous topic :: View next topic |
Author |
Message |
tinley
Joined: 09 May 2006 Posts: 67
|
read_configuration_memory for User ID |
Posted: Fri May 04, 2018 10:05 am |
|
|
I am trying to read the User ID on a PIC18F2685.
According to the manuals...
Code: |
read_configuration_memory([offset], ramPtr, n); |
should read User ID if using the correct offset. But I can't get this to work.
Can anyone help me with this please?
I can't find the offset to use anywhere, but after preloading the User ID, I did try this to no avail:
Code: |
int8 array[8];
int32 i32;
for(i32=0;i32<0x0400000;i32++)
{
read_configuration_memory(i32,array,8);
restart_wdt();
if(array[0]==0x31 && array[1]==0x32 && array[2]==0x33 && array[3]==0x34 && array[4]==0x35 && array[5]==0x36 && array[6]==0x37 && array[7]==0x38)
{
prinftf("FOUND IT");
}
} |
User ID is located at 0x0200000. I can confirm the data is there with PICkit.
Cheers, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19488
|
|
Posted: Fri May 04, 2018 12:09 pm |
|
|
The offset, is the offset _inside the configuration memory area_. Not the offset from the base of memory.
The configuration memory internally is read by a separate operation to a normal memory read, and it is the offset in this that the operation expects.
You need to be using the getenv function that reads the devID area, not the read_configuration_memory function.
It's worth understanding that the memory layout seen by the programmer is _not_ how the PIC internally sees it's memory. It's like EEPROM, which internally has to be read by separate code to access the EEPROM, but the programmer writes to it at an address in the main memory range. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed May 09, 2018 2:53 am |
|
|
Thank you for this further insight, but even after searching the manual for the function you suggest, I am none the wiser! Another case of very poor CCS documentation!
The documentation clearly says that:
read_configuration_memory([offset], ramPtr, n);
should read User ID if using the correct offset. But it doesn't? And no indication of what the offset should be is given?
I was looking for the string I stored in the user ID, using the huge 'for loop' in desperation!
I can't find any reference to the devID in the manual? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19488
|
|
Posted: Wed May 09, 2018 3:24 am |
|
|
getenv("ID")
Returns the device user ID
Look at #ID (which sets this).
Remember the preprocessor can only 'see' what is set in the code.
The reason the manual can't tell you the locations for anything is it is always device specific. However as I already said the locations for read_configuration_memory are 'configuration memory' relative.
If you just want to do a direct 'read' from the actual chip, in code, then use the read_program_eeprom instruction, not the read_configuration_memory instruction. The latter is built specifically to talk to the configuration memory (which needs a different bit set in the read operation). The ID locations are not actually in this part of this memory space.
Code: |
char dev1, dev2;
dev1 = read_program_eeprom(0x3FFFFEL);
dev2 = read_program_eeprom(0x3FFFFFL);
|
Returns the hardware device ID.
Use 0x200000 for the User ID. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed May 09, 2018 3:52 am |
|
|
Thank you for your continued help. Sorry if I am being a bit thick!
char array[8];
array=getenv("ID");
returns error 'lvalue is read only'? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19488
|
|
Posted: Wed May 09, 2018 5:16 am |
|
|
You can't just move strings with =. You have to use strcpy. This accepts constant values. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed May 09, 2018 6:58 am |
|
|
So, I have finally sorted this out. For anyone else wanting to do the same thing, this works.
I want to manually type the ID into the IPE User ID, but you can test it with the following line in code, which puts the characters 1,2,3,4,5,6,7,8 into the user ID:
Code: | #id 0x3231,0x3433,0x3635,0x3837 |
Then to extract the user ID, simple to understand/read code is:
Code: |
char serialNO[8];
serialNO[0]=read_program_eeprom(0x200000);
serialNO[1]=read_program_eeprom(0x200001);
serialNO[2]=read_program_eeprom(0x200002);
serialNO[3]=read_program_eeprom(0x200003);
serialNO[4]=read_program_eeprom(0x200004);
serialNO[5]=read_program_eeprom(0x200005);
serialNO[6]=read_program_eeprom(0x200006);
serialNO[7]=read_program_eeprom(0x200007);
serialNO now equals "12345678"
|
0x200000 was obtained from the ID Location: 200000 in the device file.
I trust this is useful to others who are frustrated with the CCS documentation! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19488
|
|
Posted: Wed May 09, 2018 7:28 am |
|
|
As I said:
Use 0x200000 for the User ID. |
|
|
tinley
Joined: 09 May 2006 Posts: 67
|
|
Posted: Wed May 09, 2018 9:02 am |
|
|
Thank you, yes, agreed. And I had already said that in my original question!
What I needed, as others may need, is how to read the User ID from configuration memory!!!
Hopefully I have given them that now! |
|
|
|