After further investigation, it looks to be an issue with the mac address code.
I hooked up an FTDI USB TTL Serial cable and used the UART example code on this page: https://www.pjrc.com/teensy/td_uart.html . This works perfectly, through both the regular USB cable (using Serial) and through the UART (using Serial1/HWSerial in that code).
However, when I try to combine the Serial1 functionality with the mac address code, I see the same issue, where the Teensy seems to disappear and fails to respond.
I am stepping through the mac code now, but would appreciate other people taking a look. I attached it above, but here it is again, in case you don't feel like downloading it. It's from this post: http://forum.pjrc.com/threads/91-teensy-3-MAC-address
mac_query.ino:
Code:
#include "mac.h"
int SWVersion = 1020;
void setup() {
delay(1000);
Serial.begin(9600);
// Serial.println("Reading MAC from hardware...");
// read_mac();
//
// Serial.print("MAC: ");
// print_mac();
// Serial.println();
//
// Serial.print("Finished.");
}
void loop() {
if (Serial.available()){
int inbyte;
inbyte = Serial.read();
if (inbyte == '?'){
Serial.println(SWVersion);
read_mac();
print_mac();
Serial.println();
}
}
}
mac.cpp:
Code:
#include "mac.h"
uint8_t mac[6];
// 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;
while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF));
*(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 read_mac() {
read(0xe,mac,0);
read(0xf,mac,3);
}
void print_mac() {
size_t count = 0;
for(uint8_t i = 0; i < 6; ++i) {
if (i!=0) count += Serial.print(":");
count += Serial.print((*(mac+i) & 0xF0) >> 4, 16);
count += Serial.print(*(mac+i) & 0x0F, 16);
}
}
mac.h:
Code:
#include <Arduino.h>;
extern uint8_t mac[6];
void read_mac();
void print_mac();
To use a USB to Serial cable like mine, change Serial to Serial1 (or whichever port you're using) in the code.
I've also tried baud rates of 9600 and 115200, with the same results all around.
Thanks for your help!