teensy 3 MAC address

Status
Not open for further replies.
thats great

I guessed that, and can modify my copy of said,

but its an example bundled with arduino / teensy,

so if the example needs to be modified,
who needs to know so the release can be fixed ?
 
So

I have modified my copy of T3Mac.h.
this was originally in the zip file in post #14


this is what I now have , that compiles without error

#ifndef T3Mac_h
#define T3Mac_h

#include <Arduino.h>

extern uint8_t mac[6];

void read_mac();
void print_mac();

#endif

hope that helps someone
 
This begs the question of what has changed in the compiler to now throw this as an error, I am not running on the latest arduino IDE.
 
Very helpful to have MAC address in Teensy3

This is great for use with the WIZ820io. I just learned today this existed. Someone needs to write a book about Teensy3, there is a lot there! Maybe we could all collaborate in a wiki!

It would be nice if some mention of this MAC address was made in the Ethernet examples, for example in DhcpAddressPrinter where mac is hardcoded
Code:
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
this does not conform to the guide for locallyadministered MAC addresses in which the second-least-significant bit of the most significant byte of the address, also referred to as the U/L bit, short for Universal/Local, should be a 1. If the bit is 0, the address is universally administered. If it is 1, the address is locally administered. I had to brush up on these nuances myself, wikipedia is a good reference: https://en.wikipedia.org/wiki/MAC_address. The organizational unique identifier (OUI) is just the most significant three bytes, the lower three bytes are the NIC portion and are assigned by the organization who licensed the OUI from the IEEE.

So in this example the mac address should more properly be
Code:
byte mac[] = {  
  [B]0x02[/B], 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
which would prevent any possible conflict with a manufacturered device. I'll submit a fix for that to Arduino at Github
The PJRC OUI seems to be 04:E9:E5, confirmed by this OUI lookup tool https://www.wireshark.org/tools/oui-lookup.html

Thanks so much to Paul for putting this MAC address in Teensy 3!
 
Hi
I'm new to this ....
The T3Mac library provides functionality to print MAC address.
I need to extract it so I can write it to my ethernet module. I don't know how to do that.
Any one help?
 
What Ethernet module do you have ?
Some come with their own mac address and this would not work
The WIZ830io does not have it's own mac address and you can use the Teensy mac address for that.

I am off to work now but can post code tonight.
 
Hi
My module is WIZ820. I have several and I want to get a unique MAC address from the Teensy in my sketch and then start an Ethernet session using it.
thanks
John
 
Hi thanks
I tried that but I'm not sure if I'm doing the right thing but..
I have put code (class) in my sketch and made a request for mac in setup. I get:

C:\JMstuff\ROBIN\JM-Robin-Servo\JM-Robin-Teensy8\JMvarious.ino: In constructor 'mac_addr::mac_addr()':
C:\JMstuff\ROBIN\JM-Robin-Servo\JM-Robin-Teensy8\JMvarious.ino:197:23: warning: list-initializer for non-class type must not be parenthesized [enabled by default]
mac_addr() : m({0}) {
^
exit status 1
call of overloaded 'println(byte [6])' is ambiguous
 
Hi thanks
I tried that but I'm not sure if I'm doing the right thing but..
I have put code (class) in my sketch and made a request for mac in setup. I get:

C:\JMstuff\ROBIN\JM-Robin-Servo\JM-Robin-Teensy8\JMvarious.ino: In constructor 'mac_addr::mac_addr()':
C:\JMstuff\ROBIN\JM-Robin-Servo\JM-Robin-Teensy8\JMvarious.ino:197:23: warning: list-initializer for non-class type must not be parenthesized [enabled by default]
mac_addr() : m({0}) {
^
exit status 1
call of overloaded 'println(byte [6])' is ambiguous


OK.

step back a bit.

this might help. not certain where / when I got it but it works as an example

#include "T3Mac.h"


void setup()
{
delay( 2000);

Serial.begin(115200);

read_mac();

Serial.print(" Chip ID =: ");
Serial.print( ( mac[0] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[0] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[1] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[1] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[2] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[2] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[3] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[3] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[4] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[4] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[5] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[5] & 0x0F ) ,HEX );

Serial.println();

}
}

void loop() {
}
 
OK I'll try messing picking the bones of that. thanks

to give you a quick heads up

you include the T3mac library ,

you call read_mac

read_mac returns a variable called mac , which is an array of 6 bytes ( 0 to 5 ) of the mac address,

the print stuff is just so you can see it on a terminal,
 
If anyone else is trying to get this to work this may help:

Download the library from post #14

Delete the ";" from the end of #include <Arduino.h>; in T3Mac.h

Use the sketch from post 38 but remove the extra closing bracket and add a delay after serial begin. This works with Teensy 3.2 on Arduino 1.6.5 r5.

#include "T3Mac.h"


void setup()
{
delay( 2000);
Serial.begin(115200);
delay( 2000);
read_mac();

Serial.print(" Chip ID =: ");
Serial.print( ( mac[0] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[0] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[1] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[1] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[2] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[2] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[3] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[3] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[4] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[4] & 0x0F ) ,HEX );
Serial.print( " : " ) ;
Serial.print( ( mac[5] & 0xF0 ) >> 4 ,HEX );
Serial.print( ( mac[5] & 0x0F ) ,HEX );

Serial.println();

}


void loop() {
}
 
I decided it would be nice to have the Teensy Serial number to display - it is derived from the bottom 3 MAC bytes (24 bits if I read a PJRC post correctly - though TYQT uses four).

While looking I saw the posted t3Mac code didn't have the recommended interrupt disable for MAC read.

While I was there I put in the code I saw to read the processor CHIP_ID [T3 and T_LC] (I noticed that code putting 36 bytes into 32 reserved bytes for the MAC ID string, now in 36.)

Here is the version as I see it working: View attachment T3Mac.zip

Sample Output from the Example sketch:
Chip MAC ID == 04: E9: E5: 01: E6: 65
Teensy Serial# 1245170
Reading 128-bit UniqueID from Teensy AA310000 716C002A 000E5016 31604E45

PROBLEM 1: (this may deserve a new thread?)
> On custom "Teensy programmer chip" T_3.2 compatible hardware the Serial # write once area is uninitialized. Does anyone have tested code to write to that area? that read pulls with:
FTFL_FCCOB0 = 0x41; // Selects the READONCE command
On this unit - since uninitialized flash is all 1's I get the following:
Chip MAC ID == FF: FF: FF: FF: FF: FF
Teensy Serial# 167772150
Reading 128-bit UniqueID from Teensy B3610000 8330002D 00093018 32204E45

PROBLEM 2:
> if I compile in the 1.6.8 IDE without re-saving the T3mac.cpp source file I get this error - that PAUL fixed in the TimeLib library he maintains:
GetFileAttributesEx C:\tCode\libraries\T3Mac\T3Mac.cpp C:\tCode\libraries\T3Mac\T3MacLib.h: The filename, directory name, or volume label syntax is incorrect.
Error compiling for board Teensy 3.2 / 3.1.
Does anyone else see this?
Paul: I tried to emulate what I thought your fix was - and missed something or found a new way to orphan an open file in the IDE.

<Minor edit> the zipped version of T3Mac.h doesn't look like this - it was not saved first - but it works that same with this intended code (if anyone sees other issues I'll update):
#include "T3MacLib.h"
 
Last edited:
RE Problem #1 - the read part of those bytes is exemplified in above code. I find the K20 manual (K20P64M72SF1RM.pdf) on page 579 discusses that - but it doesn't speak to me how to start - PJRC must do this write offline as I only find read code similar to what is in T3Mac in the installed Teensy libraries - and I only have one device on hand to try a write once operation. Must be further reading on doing register writes - which FrankB and others probably understand.

28.34.5 Flash Common Command Object Registers (FTFL_FCCOBn)
The FCCOB register group provides 12 bytes for command codes and parameters. The individual bytes within the set append a 0-B hex identifier to the FCCOB register name: FCCOB0, FCCOB1, ..., FCCOBB.
 
As a quick followup to this old but useful thread, on the new Teensy 3.6 board when running faster than 120 MHz, you need to temporarily drop down to a slower speed and disable HSRUN mode. The flash controller locks out all commands when HSRUN mode is active. Yes, that's silly since this command only reads the flash, but that's the way Freescale designed the chip.

Also, in Teensy 3.5 and 3.6, this special memory is organized as 64 bit words, not 32 bits as on Teensy LC, 3.0, 3.1 & 3.2. You need to perform a single read at location 0x07, not a pair at 0x0E & 0x0F. The low 32 bits are the IEEE-assigned OUI and the high 32 bits have the serial number.
 
It may be useful to have a Teensy official library function to return the unique number (and of course update the library page), so that most users don't have to delve into the Freescale data sheets.
 
Yup, and it could be read before switchig to hsrun!
If you want, I can do this on sunday..
 
Last edited:
@Paul, can you pls. confirm, that this prints the correct serial ?
Thank you!

Code:
uint64_t readMAC() {
  uint64_t mac;

  FTFL_FCCOB0 = 0x41;
  FTFL_FCCOB1 = 0x07;

  noInterrupts();
  FTFL_FSTAT = FTFL_FSTAT_CCIF;
  while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) {}
  interrupts();

  mac = (uint64_t)FTFL_FCCOB5 << 40;
  mac |= (uint64_t)FTFL_FCCOB6 << 32;
  mac |= (uint64_t)FTFL_FCCOB7 << 24;
  mac |= FTFL_FCCOB9 << 16;
  mac |= FTFL_FCCOBA << 8;
  mac |= FTFL_FCCOBB;

  return mac;
}


void setup() {
  delay(1000);
  Serial.printf("MAC: 0x%012llX\n", readMAC());
  Serial.printf("Serial: %u\n", readMAC() & 0xFFFFFF);
}
void loop() {}

(must run without HSRUN)

Edit: The code above is for T3.5/3.6 only
 
Last edited:
Status
Not open for further replies.
Back
Top