Does Teensy have a processor ID?

Status
Not open for further replies.

taskman

Well-known member
I am planning on using the RadioBlock for my RF communication, but I need to give it a unique number. Does the Teeny 3 have a processor ID or a way to produce one?

If not, I am thinking of getting this temp sensor https://www.adafruit.com/products/374
It seems to have a unique ID and I can use it to determine the temperature of my laser tag weapons in the sun and play a warning sound if the weapons get too hot
 
If I have the read and print in the loop() the Teensy 3 crashes. What does the read do that could cause that? I will just keep the read in setup(), but it does make me worry since the C code is more than what I can understand
 
@taskman: I seem to crash my teensy at the FTFL_FSTAT = FTFL_FSTAT_CCIF; line in the setup()->read() code below. If I comment out the initiation of the flash command in read(), it produces the full (but boring) output and loops, but if i leave it in, I only see a variable number of iterations of the 15w, 14w, 13w,... output before I lose communication.

I was curious if the 0x41 READ_ONCE command meant that it would only read the data once per reset cycle and then error, or if it meant something more like "read the Program-Once-read-many" data register, and also curious about what else was in the READ_ONCE area.

Code:
/* READ_ONCE on the PROGRAM_ONCE area of the Teensy 3.0's mk20dx128 FLASH IFR 

Following http://forum.pjrc.com/threads/91-teensy-3-MAC-address

K20 Sub-Family Reference Manual, Rev. 2, Feb 2012 section 28.4.11.10

Kinetis Quick Reference User Guide, Rev. 2, 08/2012 page 85

Also, look at the SIM_UIDH SIM_UIDMH SIM_UIDML SIM_UIDL registers


*/

#include <Arduino.h>

#define LENGTH_ONCE_AREA 64

uint8_t buff[LENGTH_ONCE_AREA]; 

uint8_t base;  


void read_once(uint8_t word, uint8_t buf[], uint8_t offset) {
  while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF)){Serial.println('.');}
//  return;
  FTFL_FCCOB0 = 0x41;             // Selects the READONCE command
//    Serial.print("FTFL_FCCOB0:");Serial.println(FTFL_FCCOB0,HEX);
//  return;
  FTFL_FCCOB1 = word;             // read the given word of read once area
//  Serial.println(FTFL_FCCOB1,HEX);
//    Serial.print("FTFL_FCCOB1:");Serial.println(FTFL_FCCOB1,HEX);
 //   Serial.print("FTFL_FCCOB2:");Serial.println(FTFL_FCCOB2,HEX);
//    Serial.print("FTFL_FCCOB3:");Serial.println(FTFL_FCCOB3,HEX);

//  Serial.print("STAT:");Serial.println(FTFL_FSTAT,HEX);
//  return;

while(!( FTFL_FCNFG & FTFL_FCNFG)) ; // wait for flash
//  Serial.print("FTLFL_FCNFG:");Serial.println(FTFL_FCNFG,HEX);
//return;
// launch command and wait until complete
 FTFL_FSTAT = FTFL_FSTAT_CCIF;
//  Serial.print("STAT:");Serial.println(FTFL_FSTAT,HEX);
return;

  while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF)){
//  Serial.print("STATwait:");Serial.println(FTFL_FSTAT,HEX);
  }
//return;
  if (FTFL_FSTAT & FTFL_FSTAT_ACCERR){
//    Serial.print("ReadOnce FTFL_FSTAT_ACCERR at record ");
//    Serial.print(word);
//    Serial.println("Recorded data may not be reliable");
  }
  
  if (FTFL_FSTAT & FTFL_FSTAT_FPVIOL){
//    Serial.print("ReadOnce FTFL_FSTAT_FPVIO at record ");
//    Serial.print(word);
//    Serial.println("Recorded data may not be reliable");
  }  
//  Serial.print("STAT:");Serial.println(FTFL_FSTAT,HEX);
//  Serial.print("offset:");Serial.println(offset);

  
  buf[offset+0]   = FTFL_FCCOB4;      
  *(buf+offset+1) = FTFL_FCCOB5;      
  *(buf+offset+2) = FTFL_FCCOB6;    
  *(buf+offset+3) = FTFL_FCCOB7;    
}





// http://forum.pjrc.com/threads/91-teensy-3-MAC-address
void read(uint8_t word, uint8_t* mac, uint8_t offset) {
  FTFL_FCCOB0 = 0x41;             // Selects the READONCE command
  FTFL_FCCOB1 = word;             // read the given word of read once area

  // launch command and wait until complete
    FTFL_FSTAT = FTFL_FSTAT_CCIF;
 //   FTFL_FSTAT = FTFL_FSTAT_CCIF | 0xf0;
 // FTFL_FSTAT = 0xf0;
  while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) FTFL_FSTAT = 0x70;

   *(mac+offset) = FTFL_FCCOB5;       // collect only the top three bytes,
   *(mac+offset+1) = FTFL_FCCOB6;       // in the right orientation (big endian).
   *(mac+offset+2) = FTFL_FCCOB7;       // Skip FTFL_FCCOB4 as it's always 0.
}







void setup(void){
   Serial.begin(9600);
   while(!Serial);
   
   
    Serial.println("Waiting 2s...");
  delay(1000);

  Serial.println("Reading...");
  for (base = 0x0f << 2 ; base < LENGTH_ONCE_AREA ; base -=4){
      Serial.print(base>>2);
      Serial.print("w ");
      Serial.flush();
     // read_once((uint8_t)(base >> 2), buffer,base);             
   }

   read(0xe,buff,0);
   read(0xf,buff+3,0);

 
  
   
}

void loop(void){
 
     for (base = 0 ; base < LENGTH_ONCE_AREA ; base++){
     if (! base & 0x3) {
        Serial.print("\nONCE_PROGRAM record "); 
        Serial.print(base >> 2, HEX);
        Serial.print(" : "); 
     }
     Serial.print(buff[base],HEX);
     Serial.print(" ");
    }
    Serial.print("\n"); 
    delay(1000);
   
    
}

My apologies for the sloppy, commented out code. I tried lots of different things & tried to figure out where it was dying. Maybe the USB output interferes with the ReadOnce?
 
There seems be one in (SIM_UIDH,SIM_UIDMH, SIM_UIDML, SIM_UIDL).

Note that this sketch sometimes seems to hang/or kill the USB serial on my teensy3 after powerup or reload after the '...'. I'm not sure why. With repeated closing-openings of the Serial monitor, sometimes it picks up and goes on.

Code:
/* READ_ONCE on the PROGRAM_ONCE area of the Teensy 3.0's mk20dx128 FLASH IFR 

Following http://forum.pjrc.com/threads/91-teensy-3-MAC-address

K20 Sub-Family Reference Manual, Rev. 2, Feb 2012 section 28.4.11.10

Kinetis Quick Reference User Guide, Rev. 2, 08/2012 page 85

Also, look at the SIM_UIDH SIM_UIDMH SIM_UIDML SIM_UIDL registers


*/

#include <Arduino.h>

#define LENGTH_ONCE_AREA 64

uint8_t buff[LENGTH_ONCE_AREA]; 

uint8_t base;  




// http://forum.pjrc.com/threads/91-teensy-3-MAC-address
void read(uint8_t word, uint8_t* mac, uint8_t offset) {
  FTFL_FCCOB0 = 0x41;             // Selects the READONCE command
  FTFL_FCCOB1 = word;             // read the given word of read once area

  // launch command and wait until complete
    FTFL_FSTAT = FTFL_FSTAT_CCIF;
 //   FTFL_FSTAT = FTFL_FSTAT_CCIF | 0xf0;
 // FTFL_FSTAT = 0xf0;
  while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) FTFL_FSTAT = 0x70;

   *(mac+offset) = FTFL_FCCOB4;         // 
   *(mac+offset+1) = FTFL_FCCOB5;       // 
   *(mac+offset+2) = FTFL_FCCOB6;       // 
   *(mac+offset+3) = FTFL_FCCOB7;       // 

}




void setup(void){
   Serial.begin(9600);
   while(!Serial);
   
   
    Serial.println("...");
  delay(2000);

  //Serial.println("Reading...");
  for (base = 0x00  ; base < LENGTH_ONCE_AREA ; base +=4){
  //    Serial.print(base>>2);
 //     Serial.print("w "); 
 //     Serial.flush();
        read(base>>2,buff+base,0);
   }

  // read(0xe,buff,0); // test to see if you can read many with Read Once
   // read(0xf,buff+3,0); // you can, so commented out.

}

void loop(void){
 
   // while(1) yield(); // loop forever
    
     for (base = 0 ; base < LENGTH_ONCE_AREA ; base++){
     if (! (base & 0x3)) {
        Serial.print("\nONCE_PROGRAM record "); 
        Serial.print(base >> 2, HEX);
        Serial.print(" : "); 
     }
     Serial.print(buff[base],HEX);
     Serial.print(" ");
    }
    Serial.print("\n");
   
    Serial.print("SIM_UIDH:");
    Serial.println(SIM_UIDH,HEX);
    Serial.print("SIM_UIDMH:");
    Serial.println(SIM_UIDMH,HEX);
    Serial.print("SIM_UIDML:");
    Serial.println(SIM_UIDML,HEX);
    Serial.print("SIM_UIDL:");
    Serial.println(SIM_UIDL,HEX);

    delay(10000);
   
    
}

Output:
Code:
...

ONCE_PROGRAM record 0 : FF FF FF FF 
ONCE_PROGRAM record 1 : FF FF FF FF 
ONCE_PROGRAM record 2 : FF FF FF FF 
ONCE_PROGRAM record 3 : FF FF FF FF 
ONCE_PROGRAM record 4 : FF FF FF FF 
ONCE_PROGRAM record 5 : FF FF FF FF 
ONCE_PROGRAM record 6 : FF FF FF FF 
ONCE_PROGRAM record 7 : FF FF FF FF 
ONCE_PROGRAM record 8 : FF FF FF FF 
ONCE_PROGRAM record 9 : FF FF FF FF 
ONCE_PROGRAM record A : FF FF FF FF 
ONCE_PROGRAM record B : FF FF FF FF 
ONCE_PROGRAM record C : FF FF FF FF 
ONCE_PROGRAM record D : FF FF FF FF 
ONCE_PROGRAM record E : 0 4 E9 E5 
ONCE_PROGRAM record F : 0 0 8 FC 
SIM_UIDH:FFFFFFFF
SIM_UIDMH:FFFF0002
SIM_UIDML:3A2002
SIM_UIDL:14134D44
 
Status
Not open for further replies.
Back
Top