Question on digitalWrite, on SPI bus (T3.5)

Status
Not open for further replies.

tonton81

Well-known member
On teensy 3.5 (5v tolerant) I'm using SPI devices on the spi bus that are 5V. Everything is working fine

The devices themself have their own pullup, especially the GPIO expanders, to ensure their state is always HIGH whenever the mcu is powered down or rebooted.
^---------- CS line


during SPI transactions, we write HIGH and LOW to the pin to assert/deassert the chips, however, wouldn't that make the 3.3V and 5V share the same power?
Not having any issues currently for several months but...

Which would be preferable?

switching during transactions by:

pinMode(CS, OUTPUT) and pinMode(CS, INPUT)
( asserting to LOW then deasserting to floating pin so the external pullup will take over? )

or

1K resistor in series?

I would gather the pinMode is not as fast as digitalWriteFast method, any pointers?
 
thanks i tried OUTPUT_OPENDRAIN just now, unfortunately the expanders were not responding when i triggered their GPIOS, weird
i went back to OUTPUT mode and its normal

perhaps its a bug with digitWrite?(Fast?) and opendrain mode?
 
Last edited:
For pins in open drain mode: Data sheet specifies the min and max pull up voltage with VDD (3.3V).
 
For pins in open drain mode: Data sheet specifies the min and max pull up voltage with VDD (3.3V).
I didn't realize that the Kinetis devices have such strange hardware, the K20 datasheet doesn't have that note.

Anyway, I did a search on the NXP web site and the pins aren't really 5V tolerant in output mode. Switching between input mode and LOW output seems to be supported with 5V pullup:
https://community.nxp.com/thread/441777
 
I wonder how fast pinMode switching is compared to digitalWriteFast?

will this decrease the speed of the SPI activity when going from "pinMode(pin , INPUT)" to "pinMode(pin, OUTPUT);" ?

wouldn't a series resistor prevent the 2 voltages from clashing?

writing a HIGH as an output puts 3.3v on an already 5V pulled CS line, and is working fine for the past year, im guessing because it's being accessed by polling
 
Last edited:
Can you measure the voltage in high state? I think there is an internal leakage path to VDD in the mcu and you can't pull the pin voltage higher than ~4V.
 
your telling me, when the line is deasserted (HIGH @ 3.3v) the output line (which has a pullup at 5V) will report less than ~ 4v?

even still, with a DMM, the code is polling the devices on that port every loop, the DMM wouldn't be accurate as the line is transitioning constantly, and I have no scope on me
 
Last edited:
Yes this is what I meant.

But I've never tested it with OUTPUT, only with OUTPUT_OPENDRAIN, and on Teensy 3.2 - don't have a 3.5.
 
i tried the output opendrain, however, the spi bus completely stopped working, so its running still with 5v pullup in output mode with the usual HIGH/LOW writes
 
I have a Teensy 3.1 here with a 1k pull up @ pin 1.

Code:
pinMode(1, OUTPUT);
digitalWrite(1, HIGH);

pull up connected tomeasured voltage @ pin 1
3.3V3.3V
5V (Teensy VIN)3.3V

It looks like the measured pin voltage can't get higher than VDD. Maybe it's the same with Teensy 3.5 and your real world application and you don't have to care about the different voltage levels. Connect the pull up to 3.3V and everything is fine?

Code:
pinMode(1, OUTPUT_OPENDRAIN);
digitalWrite(1, HIGH);

pull up connected tomeasured voltage @ pin 1
3.3V3.3V
5V (Teensy VIN)4V
 
Status
Not open for further replies.
Back
Top