Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 26 to 50 of 113

Thread: teensy 3 MAC address

  1. #26
    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 ?

  2. #27
    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

  3. #28
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    763
    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.

  4. #29
    thats all way above my simple head,
    give us an ASIC and a simple language like VHDL any day...

  5. #30
    Senior Member
    Join Date
    Nov 2012
    Location
    Salt Lake City, UT, USA
    Posts
    234

    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[] = {  
      0x02, 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!

  6. #31
    Senior Member
    Join Date
    Jan 2013
    Posts
    964
    That WiKi is in the works and there is already a thread on it that collects different topics.
    Here is a link to another sticky thread with tips and tricks

    Not a book but very helpful!

  7. #32
    Senior Member
    Join Date
    Nov 2012
    Location
    Salt Lake City, UT, USA
    Posts
    234
    Happy to contribute to the Wiki when it is up!
    Thanks for all the support you provide too!

  8. #33
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    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?

  9. #34
    Senior Member
    Join Date
    Jan 2013
    Posts
    964
    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.

  10. #35
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    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

  11. #36
    Quote Originally Posted by muggins View Post
    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
    As per this thread

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


    the variable mac in this thread has the mac address from each teensy

  12. #37
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    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

  13. #38
    Quote Originally Posted by muggins View Post
    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() {
    }

  14. #39
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    OK I'll try messing picking the bones of that. thanks

  15. #40
    Quote Originally Posted by muggins View Post
    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,

  16. #41
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    That's great, got it now..thanks

  17. #42
    Junior Member
    Join Date
    Oct 2015
    Posts
    18
    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() {
    }

  18. #43
    Senior Member defragster's Avatar
    Join Date
    Feb 2015
    Posts
    4,538
    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: 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 by defragster; 05-03-2016 at 09:24 AM. Reason: t3Mac.h zip copy misqueue

  19. #44
    Senior Member defragster's Avatar
    Join Date
    Feb 2015
    Posts
    4,538
    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.

  20. #45
    Junior Member
    Join Date
    Oct 2015
    Posts
    18
    I incorporated your new library and it works well to pull the MAC and the Chip ID on Arduino 1.6.5 r5. Example sketch here: https://github.com/onlykey/OnlyKey-F...AC/Get-MAC.ino

  21. #46
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    14,878
    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.

  22. #47
    Senior Member MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,379
    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.

  23. #48
    Senior Member Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    3,941
    Yup, and it could be read before switchig to hsrun!
    If you want, I can do this on sunday..
    Last edited by Frank B; 08-26-2016 at 02:27 PM.

  24. #49
    Senior Member Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    3,941
    @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 by Frank B; 08-27-2016 at 04:16 PM.

  25. #50
    Senior Member KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    2,696
    Quote Originally Posted by Frank B View Post
    Yup, and it could be read before switchig to hsrun!
    If you want, I can do this on sunday..
    I have a pull request pending in Core that did this, that I issued 10 days ago:
    https://github.com/PaulStoffregen/cores/pull/166

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •