Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Teensy 4.1 MAC Address

  1. #1
    Member
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    22

    Teensy 4.1 MAC Address

    I have my Teensy 4.1 working (for the most part...) but it does not seem to have a MAC address. If I feed NativeEthernet a legitimate MAC address for another device, DHCP serves up a nice ip address and my Teensy uses it to connect to my Flex SDR radio. If I want two devices on the same network segment, it only works for the last device added as the local ip is the same for both devices (I think because the MAC address is the same). Is there a trick to NativeEthernet that will give me a different ip for a second device connection? Am I approaching this problem all wrong? Is there a get MAC address function or something that will help me? I am not a network guy, so I am fumbling around with this...

    Thanks,
    Len

  2. #2
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Posts
    641
    They do come preprogrammed with a unique MAC address, this is the code that retrieves it for a Teensy 4.x, just supply it with your MAC address array that's 6 bytes long and it'll set it accordingly:
    Code:
    void teensyMAC(uint8_t *mac) {
        for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
        for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
        Serial.printf("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    }

  3. #3
    Senior Member
    Join Date
    Mar 2016
    Posts
    213
    vj answered the MAC question. I can confirm each one is unique (or at least the 4 I have are).

    To the IP addr question, if you select DHCP, you get unique IP addrs. (I think that's the default...) You can also specify a static IP addr but probably better to use DHCP and then reserve those addrs on your router. It plays a lot nicer with your network. You may need the MAC for that on some routers.

  4. #4
    Member
    Join Date
    May 2019
    Location
    Colorado, USA
    Posts
    22
    AH! Thanks VJ, I really appreciate that. I included your code in my program, and it worked! I now have two devices connected to the same SDR radio and communicating properly. I really appreciate all that you have done with the NativeEthernet library. Using it I have made huge strides in my project. Without it, I never would have gotten off the starting line.

    Thanks,
    Len

Posting Permissions

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