Teensy 3.0 Hardware Serial Port tips

Status
Not open for further replies.

linuxgeek

Well-known member
I'd like to use the hardware serial ports on the teensy 3.0.

Any suggestions on how to go about this?

Can I plug directly into the com port of the PC and test it this way? I was reading that the PC uses 12v and that's probably too high for teensy 3.

Is using the hardware serial fairly straightforward or will it be considerably more difficult than the softserial?

I'd like to do something basic that works, and then move on from there.
 
Yes, RS-232 uses a much higher voltage, +12 to -12 volts, vs 3.3 to 0 volts. Actually, RS-232 says the transmitter must send at least -5 volts or +5 volts. The MAX232 chip will transmit approx -10 to +10 volts. The polarity is also opposite. When idle, Teensy 3.0 will be at 3.3 volts on the pins, RS-232 will be at -5 to -12 volts.

RS-232 also has some special specs regarding impedance and slew rate limiting, which allow it to drive longer wires than normal digital signals.

Software-wise, using hardware serial is easy. From Arduino, just use Serial1, Serial2 or Serial3. All 3 can work at the same time. They can all transmit and receive simultaneously. There's no need to make one active, as is done with the SoftwareSerial library.

When you use Serial1.print() or Serial1.write(), the transmitting is buffered (unlike SoftwareSerial), so if your output fits within the buffer, your program does not stall waiting for the actual bits to transmit. If you want to wait, call Serial1.flush().

Hardware serial can receive much more reliably that software serial. It's much less susceptible to interference from other libraries using interrupts. One Teensy 3.0, Serial1 has an 8 byte FIFO built into the hardware (no Arduino brand board has this) which allows it to be more efficient and reliable at higher speeds.
 
I like the idea of the hardware serial (esp. for hopefully more complicated projects in the future), I'm just wondering if I'm biting off more than I can chew right now. Can I do any real damage if I'm accidentally mismatch the voltage levels? I'm guessing the MAX3232 breakout is the way to go for me.
 
Hi

I use the hardware serial and I bought these from Amazon and have found they work fine:

http://www.amazon.co.uk/gp/product/B008AGDTA4/ref=oh_details_o05_s00_i00

As you can see I am in the UK but if you search for the description "super9shop PL2303HX USB to TTL to UART RS232 COM Cable module Converter" I am sure you can find something if you are not in the UK.

No need for the black and red cores since it is powered from the same USB hub so I only use the white and green cores only.

The green core is connected to Teensy 3.0 pin 0 (RX1) and the white core to pin 1 (TX1)

The simplest test code:

Code:
#include "Arduino.h"

HardwareSerial Uart = HardwareSerial();

void setup() 
{
	Uart.begin(38400);
	Uart.println("That's hardware serial !!!");
}

void loop() 
{
}

Hope it helps
Ex.
 
Can I do any real damage if I'm accidentally mismatch the voltage levels?

Yes, so be careful. At least 4 things can damage Teensy, or most other chips.

1: Applying more than the maximum voltage to the power pin.
2: Applying power in reverse polarity.
3: Applying more voltage than the power's voltage to any pin.
4: Applying negative voltage to any pin.

The easiest way to be safe on #1 and #2 is using the USB cable for power, and not using any other power sources in your project.

For #3 and #4, something you can do that will greatly reduce the odds of permanent damage is connecting a resistor directly at the pin, and then connecting your signal to the other side of the resistor. For pins you use as digital inputs, a 10K resistor is a good choice. For digital outputs, a 220 ohm resistor is probably good. For analog inputs, a 1K resistor is probably ok. If you do apply too much voltage, or a negative voltage... it's still bad, but the resistor will help limit the damaging current that can flow into the pin of the chip. Damage could still occur, having a resistor between the pin and the too-high or negative voltage will greatly improve the odds Teensy will survive.
 
I think at least you will need the black wire to provide a ground reference.

FYI I am getting the ground reference by using the same USB host power source, it is actually a USB hub but guess this would be needed otherwise. Anyway it isn't connected but is working fine :)
 
Ok, this is great info.

I'm pretty sure I've already done some things that I shouldn't have but I don't think there wasn't enough current to cause problems. I already received my 2nd batch of teensy 3.0's, in preparation for doing something stupid. But I'm pretty sure my current T3 is fine.

One of the things I'm trying to do first, is to communicate over SPI to a module that does 0-5V SPI. Would I be safe just using a MAX232 and a 10k ohm resistor to the digital pins?

Then for transferring data to computer, I'll probably just use the USB port initially, until I get more familiarity.

OR, am I fine just using a 10k ohm resistor & not needing the MAX232?
 
Last edited:
No - MAX232 is used to convert from T3's 3.3 V levels to +/- 15 for RS232 (e.g. into a PC's serial port). If you use a PL2303 or FTDI type USB COM port, then the RS232 levels don't physically exist (the whole COM port is emulated over USB), '1' and '0' are represented by 3.3 (or 5) and 0 V levels.

For SPI-SPI, you just need to ensure that 3.3 is read as a '1' by the circuits operating a 5 V (probably, but not 100 % robust), and that when the 5 V circuits drive Teensy 3, they don't overdrive it -- they will if directly connected, so you need to limit the current to protect the T3. A 10k resistor will be sufficient, but might limit the SPI speed to << 1 MHz. In theory you would be safe with 1 kohm.
 
Ok. I think it might work out alright. It'll probably be only at 9600 bps, and the communication is almost all one way with a slow data stream coming into the t3.

If it has trouble transmitting commands to the module, I'll then worry about a level shifter in only that direction. If I talk to anything else at high rates it'll probably be another T3 so that should be easy... easier.
 
just use Serial1, Serial2 or Serial3

Paul

I have tried:

Code:
#include "Arduino.h"

HardwareSerial Uart = HardwareSerial();
HardwareSerial2 Uart2 = HardwareSerial2();
HardwareSerial3 Uart3 = HardwareSerial3();

void setup() 
{
	Uart.begin(38400);
	Uart2.begin(38400);
	Uart3.begin(38400);
}

void loop() 
{
	Uart.println("From Port 1");
	delay(1000);
	Uart2.println("From Port 2");
	delay(1000);
	Uart3.println("From Port 3");
	delay(1000);

Port 1 works as expected, port2 message comes out port 3 pins (7, 8) and port 3 message not working.

Any ideas?
 
do I need a MAX232 when I use an ftdi basic for the T3?

Could you be more specific about "ftdi basic", like a datasheet or a link to a product page with technical spec. Maybe you mean a Sparkfun product? Or maybe one of the many products FTDI sells? Some have RS-232 level signals where you would require a MAX232 chip, others have TTL level signals, and some of those are 3.3 volt which can connect directly to Teensy 3.0, others are 5 volt signals that would require a resistor but not a chip.

Details matter. You can't get a good answer to a technical question unless you provide enough detail.
 
Yes, that one can connect directly to Teensy 3.0. Connect the grounds together, the FTDI TXD to Teensy 3.0's RX1 pin, and the FTDI RXD to Teensy3's TX1 pin. Use Serial1 to communicate with it.

Of course, uploading new programs only works over Teensy's USB. You can't upload using the FTDI, but once your program is running, you can use Serial1.
 
I've finally got around to trying this out, and indeed I can receive from this 5V SPI device on Serial1. It works great with a 1k ohm resistor. I realize I should go higher, and I will when my resistor kit arrives.

I don't see how I am going to get transmitting to the 5V SPI device working though.
The RX line on the 5V device seems to be sitting at 4.8 volts. Shouldn't it typically be 0 volts?
I imagine that I can't send a 3.3V TTL spike while the RX line is sitting at 4.8V.
And even if I was to put a resistor to protect the T3, I'd imagine it might make it harder for the 3.3V spike to be detected on the 5V SPI device.

I can live w/o transmitting to the 5V SPI device, but am perplexed on why an RX line would be sitting at 4.8V.
There's not much to be gleamed from the manual.
 
It works great with a 1k ohm resistor. I realize I should go higher, and I will when my resistor kit arrives.


1K is on the low end, but probably fine.

I don't see how I am going to get transmitting to the 5V SPI device working though.
The RX line on the 5V device seems to be sitting at 4.8 volts. Shouldn't it typically be 0 volts?

With TTL level serial, the idle condition is logic high. That device probably has a weak pullup resistor to hold the pin at a logic high when nothing is connected.

I imagine that I can't send a 3.3V TTL spike while the RX line is sitting at 4.8V.
And even if I was to put a resistor to protect the T3, I'd imagine it might make it harder for the 3.3V spike to be detected on the 5V SPI device.

I'd try a 1K resistor as see if it works. Odds are good the weak pullup is a fairly high value resistor, so the 1K can probably overcome it (and get the voltage low enough to be detected as a zero). You'll probably see the pin go from 4.8 volts to something close (but slightly more) than 3.3 which the Teensy 3.0 is transmitting when idle.

I can live w/o transmitting to the 5V SPI device, but am perplexed on why an RX line would be sitting at 4.8V.
There's not much to be gleamed from the manual.

It's pretty common practice to use weak pullups to keep the line at a proper idle voltage when nothing is connected.
 
Ok, that explains a lot. Thanks for taking the time for an explanation.

In thinking that the RX line on the 5v SPI device should be at zero (and my bad for not actually measuring it initially), I hooked it up straight to the t3 TX. But then it wouldn't upload a sketch, so I stopped futzing with the RX until I understood better what was going on.

Is it any safer hooking this up to Serial1 rather than Serial2 or Serial3, because of the buffer? I'm starting with Serial1, but I'd like to move it to Serial2 or Serial3 once I figure stuff out.

Actually I have an Arduino Mega, so I'll make sure everything works on that before trying it on the t3, which is what I did for the TX.
 
Status
Not open for further replies.
Back
Top