0
\$\begingroup\$

I'm creating a board using an ATSAMS70 microcontroller, and found out in the datasheet that the I2S data out pin (which I'll be using) was multiplexed with another pin I wanna use, which is the SD card interface data 0 pin. I'm familiar with the concept of multiplexing, but I don't really understand how the MCU handles it with pins :

Will it switch very fast at something like twice the peripherals's speed to swap the pin function everytime and let each peripheral do its stuff ? Does that mean I'll have to take additional safety measures when designing my PCB since both my SD card connector's data pin 0 and my DAC's I2S data pin will share the same MCU pin and therefore have linked traces ? Does pin multiplexing somehow decrease efficiency of both multiplexed peripherals on the pin ?

Thanks

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You get to choose what peripheral uses that pin. That is the limit of multiplexing. It won’t swap between sdcard and i2s - you choose 1 and that is what you get. No other magic. \$\endgroup\$
    – Kartman
    Commented Sep 26, 2021 at 12:36
  • 1
    \$\begingroup\$ Most likely you will have to pick one function or the other (you certainly can only use one at a time). There may be an "alternative function" available for some of the pins that allow you to have both simultaneously. Reading the datasheet carefully will tell you. \$\endgroup\$ Commented Sep 26, 2021 at 17:27

4 Answers 4

0
\$\begingroup\$

Will it switch very fast at something like twice the peripherals's speed to swap the pin function everytime and let each peripheral do its stuff ?

No. One of the functions is connected to the pin at a given time. You get to decide which one. You can switch back and forth between them, but it's up to you to write the code to so, it's up to you to do it in a way that makes your connected devices happy (for example by adding an external multiplexer so that only one sees the signal at a time, or by enabling/disabling their chip select pins so that only one of them cares about its input at a time), and it's up to you to make sure that your libraries aren't trying to access the "wrong" function at any given time. You can't do two things at once, you can only time-share.

If this doesn't sound like something you want to do, then your other choice is to look for a different MCU that has all of the functions you need on different pins, so that no switching is required.

\$\endgroup\$
2
\$\begingroup\$

You did not get the concept of multiplexing quit right. Think of it as 'custom' routing within the IC itself. You can decide what function to use on which pins during runtime. Sure, you can switch very fast too - but where is the point of having an ADC and an SD card on the same lanes? I guess your data flow looks like: ADC -> Logic in Controller -> SD card. So you effectively cut your bandwidth in half here by using the same pins. But not only that. You go from dead simple to pain in the ass really fast.

Multiplexing is designed to ease up the PCB routing and allow for special needs. But your intention will afaik not work as desired. A classic use case would be: Oh, I need two I2C busses in the somewhat same region of the board. Sets switch pins in a way, that I can route them in parallel and not mess up my whole PCB layout. Or another: You have an extension bus where you can either use I2C or SPI for some sort of management. The slave card signals what type of interface to use - thereby you choose pins which can be I2C or SPI. Or you have only two I2C 'peripherals in your controller, but want to use four different devices on individual busses. You hook up the devices on separate lanes and switch the internal workings as needed - where is the point of the 'bus' at all in this case i hear you ask? Well, you could reduce track length, ease up rounting and other stuff this way.

You can for sure make your usecase work with some carefull consideration on some logic gaes and stuff. But it will not work out of the box.

But my advice: Use two different peripherials for this job.

\$\endgroup\$
2
  • \$\begingroup\$ Just to be clear, multiplexing can, in other uses, mean sharing of one medium by several flows of information in parallel, as in TDMA, CDMA and more. However not here. \$\endgroup\$
    – jcaron
    Commented Sep 26, 2021 at 16:48
  • 1
    \$\begingroup\$ @jcaron Just what I was thinking about. "You did not get the concept of multiplexing quit right" is not really the case. OP seems to understand multiplexing just fine. It is the use of it in MCU that is confusing, but only because the peripheral multiplexing is rather special case, appropriating the common term for its limited function \$\endgroup\$
    – Maple
    Commented Sep 26, 2021 at 17:21
1
\$\begingroup\$

I'm familiar with the concept of multiplexing, but I don't really understand how the MCU handles it with pins

If you know how standalone multiplexing chips work, then think of similar device sitting on each MCU pin, with its selector lines connected to bits in some MCU register. By writing correct values into corresponding registers (often called "GPIO configuration registers") you can select which periphery is connected to what pin.

Some MCUs have same periphery signals connected to muxes on several pins. Some have fully multiplexed pins, with all internal signals available on all I/O pins.

It is technically possible to switch the mapping on the fly and use same pin for different purposes. However this often requires additional external components and complicates schematics unnecessarily, not to mention the bandwidth limits of shared line.

So, the typical first step in the design process is to select MCU where all required periphery is available on separate pins. Then the multiplexing can be configured once during startup.

Sometimes this step turns into a real tap dance: "if I use this pin as UART1 tx then I cannot use SPI2 clock, so I have to use SPI1, but then SPI1 will steal one of ADC inputs for its MOSI... so lets go back and try to use UART2 instead". And so on.

\$\endgroup\$
0
\$\begingroup\$

Multiplexing can have different meanings.

You are probably familiar with the concept of multiplexing several data streams over a single link, like what happens in TDMA, time-division multiplexing, where the overall data stream in split into timeslots, and each individual stream is mapped to one or more timeslots, like in G.703 (oh f*ck I’m old), SONET/SDH or GSM, for instance.

You have likewise CDMA (in wireless) or DWDM (on fibers) which are frequency-based, and many other similar schemes.

But on MCUs multiplexing has a completely different meaning. Yes, different signals can be routed though the same pin, but just not at the same time.

Depending on the chip, it may be very limited (pin X can use function A or B), or be a lot more flexible with a multiplexing matrix (you can assign functions A, B, C, etc. trough any of the pins X, Y, Z, etc.), and anything in between (matrix with restrictions on which combinations are possible or whatever).

In some cases you may be able to actually use both functions on the same pin (at different times), but that would require logic to make sure only the right peripheral is connected to that pin at the right time (so you need your own multiplexing on the outside of the chip). This is similar to the “chip select” used on some buses for instance.

What you do and how you do it may vary a lot based on the chip and your requirements. Maybe you can assign the two functions you need to two different pins (or sets of pins), which is the easiest. In some cases this just means switching from one bus/interface to another (e.g. you have multiple SPI or I2C interfaces, and you just switch to another one). In other cases you just have a conflict, and either you can resolve it through selection, or you just need to switch to a different chip.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.