Can the Pin to Port Mapping be changed?

Status
Not open for further replies.

kiwi64ajs

Member
Hi Guys,

The Teensy 3.x boards have heaps of Arduino pins but I'm trying to figure out if I can arrange to have 2 x native 8-bit ports come out and go to some 2x5 headers (8 bits + GND and VCC) so you can do tidy and fast whole port type operations to each 2x5 header. In the AVR world these would be bits 0..7 of the A, B, C, D, E ports say depending on the chip.

I've been staring at the pinout diagram here: https://forum.pjrc.com/threads/25643-Combined-Pin-Assignments-card and it's not looking very encouraging to me.... :(

I need access to the CAN 2.0B interface and I'd like to also have access to the I2C and SPI ports as well as well as the 2x8-bit registers output to the 2x5 headers but I don't think it will be possible. So that leaves me with doing things like allocate the I2C and SPI port pins and then form the 8-bits of the 2x5 headers with scattered I/O pins and do bit manipulations to get them into tidy 8-bit type I/O operations, which will not be very efficient.

I have read a bit about the Port Mux and have dabbled with the Port Mux on the nRF51822 chips and they seem to have a great deal of flexibility as to which pin a peripheral is connected so I'm wondering if the equivalent flexibility exists with the chips on the Teensy 3.x boards?

Any suggestions or comments?

Regards

Alex Shepherd

PS For the curious - this would be used on Model Railroad Layouts as part of the Control System. The Layout Bus is CAN based and would interface to various I2C peripherals and also 1-2 flexible 8-bit port oriented interface modules like the ones listed under the heading Input/Output Modules for Tower Controller, TowerMan, SSB Aux ports, and LNCP on this page here: http://www.rr-cirkits.com/description/index.html
 
Firstly, yes, I think you can do what you want with a Teensy 3.5 or 3.6. I think maybe you're right about not having enough consecutively numbered pins available on the 3.1.

Secondly, for a model railway, I really don't think you need to. You're asking for the ability to do atomic writes to 8 pins of the same port, because you are worried about either performance, or the pin states changing a few nano seconds apart?

I can't imagine there is any need to be that worried about either. I think these micros will be more than adequate from a performance perspective, and if your signals or points change at up to tens of milliseconds difference, its still too quick for a user to ever notice.

Anyhow, for info: the kinetis devices' ports are labelled A, B, C, D and E. Each are 32 bits wide (although some pins are used for special purposes (debug etc.).

So if you see PTB0, this means port B pin 0.

Get one of the larger Teensys as they have almost all pins available, there are many options for consecutive runs of pin numbers. A quick check shows that on Teensy 3.5, ports C and D both have all the pins 0 through 7 available.
 
On Teensy 3.2 you can get close, but not with SPI. PTC and PTD are the two native 8 bit ports you can get. CAN is on PTA and I2C on on PTB, so you can access those without any conflict.

But the default SPI pins are on PTC, and the alternate SPI pins are on PTD. With 3.2, you just can't have SPI while also using the 2 available 8 bit ports.

Teensy 3.6 could give you all this (and quite a lot more). The main SPI port (the only one with the 4 word FIFO) can be reassigned to another set of pins (27, 28, 39) which are on PTA. If you're willing to access the less convenient bottom side pages, you can also get another 8 bit port from PTB16-PTB23. These are on the same PTB, but the hardware allows independent access to each group of 8 bits in the 32 bit register. If you use PTB16-PTB23 as a third 8-bit port, it would conflict with the default I2C pins, but they can be reassigned to 33,34 which are on PTE. So Teensy 3.6 can give you all the I/O you wanted, and even a third simultaneously writable set of 8 pins. Of course, if you're planning to use the SPI for a SD card, you get that too on 3.6 with dedicated fast 4-bit SDIO, leaving the SPI pins free.

I am curious what aspect of model railroad control requires two 8 bit ports? Every model railroad I've ever seen did things at a slow speed my own eyes could easily observe.
 
Last edited:
Firstly, yes, I think you can do what you want with a Teensy 3.5 or 3.6. I think maybe you're right about not having enough consecutively numbered pins available on the 3.1.

Secondly, for a model railway, I really don't think you need to. You're asking for the ability to do atomic writes to 8 pins of the same port, because you are worried about either performance, or the pin states changing a few nano seconds apart?

I can't imagine there is any need to be that worried about either. I think these micros will be more than adequate from a performance perspective, and if your signals or points change at up to tens of milliseconds difference, its still too quick for a user to ever notice.

Anyhow, for info: the kinetis devices' ports are labelled A, B, C, D and E. Each are 32 bits wide (although some pins are used for special purposes (debug etc.).

So if you see PTB0, this means port B pin 0.

Get one of the larger Teensys as they have almost all pins available, there are many options for consecutive runs of pin numbers. A quick check shows that on Teensy 3.5, ports C and D both have all the pins 0 through 7 available.

Thanks for the feedback.

So to use the 3.2 I'm going to have to gather pin status values from the various native port registers and Bit Shift, AND, OR them together into a single 32-bit word and DeBounce them (using these Vertical Counters (http://www.compuphase.com/electronics/debouncing.htm) that I found years ago. The 3.5/3.6 has more choices...

I was just hoping there might have been some magic here to make it really easy... ;)
 
Hi Paul,
On Teensy 3.2 you can get close, but not with SPI. PTC and PTD are the two native 8 bit ports you can get. CAN is on PTA and I2C on on PTB, so you can access those without any conflict.

But the default SPI pins are on PTC, and the alternate SPI pins are on PTD. With 3.2, you just can't have SPI while also using the 2 available 8 bit ports.

Teensy 3.6 could give you all this (and quite a lot more). The main SPI port (the only one with the 4 word FIFO) can be reassigned to another set of pins (27, 28, 39) which are on PTA. If you're willing to access the less convenient bottom side pages, you can also get another 8 bit port from PTB16-PTB23. These are on the same PTB, but the hardware allows independent access to each group of 8 bits in the 32 bit register. If you use PTB16-PTB23 as a third 8-bit port, it would conflict with the default I2C pins, but they can be reassigned to 33,34 which are on PTE. So Teensy 3.6 can give you all the I/O you wanted, and even a third simultaneously writable set of 8 pins. Of course, if you're planning to use the SPI for a SD card, you get that too on 3.6 with dedicated fast 4-bit SDIO, leaving the SPI pins free.

Ok so with the 3.2 (that I've had waiting for a job for a while) there's no tidy or simple solution - I'm going to have to live with merging bit fields over several port registers - ok its not that hard.

But with the 3.6 (that I got recently) the choices are a lot better.

I am curious what aspect of model railroad control requires two 8 bit ports? Every model railroad I've ever seen did things at a slow speed my own eyes could easily observe.

As I mentioned above one of uses is to monitor blocks of track for occupancy and I've done this previously using the Vertical Counters to debounce whole bytes at a time instead of the commonly used Arduino debounce bit at a time approach and I was scanning those inputs quite fast and dealing with the noise in the firmware to simplify the electronics - hardware / software trade-off...

Regards

Alex Shepherd
 
I was just hoping there might have been some magic here to make it really easy... ;)

I highly recommend the Bounce library. It's very reliable and fits your "really easy" wish perfectly.

Take a look at some of the examples, like File > Examples > Teensy > USB_Keyboard > Buttons.
 
On Teensy 3.2 you can get close, but not with SPI. PTC and PTD are the two native 8 bit ports you can get. CAN is on PTA and I2C on on PTB, so you can access those without any conflict.

But the default SPI pins are on PTC, and the alternate SPI pins are on PTD. With 3.2, you just can't have SPI while also using the 2 available 8 bit ports.

Teensy 3.6 could give you all this (and quite a lot more). The main SPI port (the only one with the 4 word FIFO) can be reassigned to another set of pins (27, 28, 39) which are on PTA. If you're willing to access the less convenient bottom side pages, you can also get another 8 bit port from PTB16-PTB23. These are on the same PTB, but the hardware allows independent access to each group of 8 bits in the 32 bit register. If you use PTB16-PTB23 as a third 8-bit port, it would conflict with the default I2C pins, but they can be reassigned to 33,34 which are on PTE. So Teensy 3.6 can give you all the I/O you wanted, and even a third simultaneously writable set of 8 pins. Of course, if you're planning to use the SPI for a SD card, you get that too on 3.6 with dedicated fast 4-bit SDIO, leaving the SPI pins free.

hm, so what about 3.5 - the spi pins block the two 8 bit ports as well ...

and what is the syntax to access PTB16-PTB23 as a third 8-bit port, something along 0xffffffff ?
did not find any defines for the upper quarters yet.
 
why dont you get a mcp23017 and call it a day
you will have 2x8 port input/output, 8 on each register(x2)

gpio bank A @ 0x12
gpio bank B @ 0x13
 
and what is the syntax to access PTB16-PTB23 as a third 8-bit port, something along 0xffffffff ?
did not find any defines for the upper quarters yet.

I believe the hardware supports byte wide access to all 4 bytes of this 32 bit register.

So, you would take the address of the 32 bit register, cast that to a byte pointer, then add 2 and reference, or use array syntax for offset of 2.
 
Status
Not open for further replies.
Back
Top