3

I am building a hobby project using a GSM module and would like to be able to switch between multiple SIM cards, in case one stops working or I have poor reception on one provider (the project will be quite inaccessible once deployed).

Would there be any issues doing this with a CPLD? I can supply the SIM cards with 3V always. I was thinking I could switch them on / off with MOSFETs and just multiplex the CLK, IO and RST connections for each SIM.

Would it be easy/possible given that the IO line needs to be bi-directional?

Would the propagation delay of the CLK be an issue at all?

Anything else that might prevent this from working?

I don't have any experience with CPLDs

  • 2
    ICs exist for this which may save you work: http://www.ti.com/lit/ds/symlink/txs02326a.pdf – pjc50 Jul 03 '15 at 10:56
  • Thanks, but I'm looking at using more than 2 SIM cards – user5077257 Jul 03 '15 at 11:28
  • Quick fix will be to use multiple ICs similar to one mentioned by @pjc50 since you say you are new to CPLD too – User323693 Jul 03 '15 at 11:35
  • 2
    You could take the IC as a starting point. That datasheet has reminded me that there are two different SIM voltages: http://electronics.stackexchange.com/questions/35358/determine-the-operating-voltage-of-a-sim-card - which makes it a huge pain to drive. You might be better off with high-speed bidirectional analog switches in the data and clock lines. – pjc50 Jul 03 '15 at 11:47
  • Thanks for the suggestion, pjc50! Multiplexers seem the way to go. – user5077257 Jul 03 '15 at 14:49

1 Answers1

4

Would it be easy/possible given that the IO line needs to be bi-directional?

Possible? Yes. Easy? Not so. You would have to detect the direction within the CPLD and switch the pins between input and output accordingly. It is a lot easier to just use an analog multiplexer chip like the 74HC4051 and control the address bits from a CPLD or microprocessor.

Would the propagation delay of the CLK be an issue at all?

In practice there is no phase relationship between CLK and IO, so it is not an issue. CLK is only used to define the baud rate of the IO line and runs at a much higher speed than the duration on a bit over the IO line. The initial speed of the IO line is one bit per 372 clock ticks. Your GSM modem may negotiate a higher speed transfer later on but lag on the CLK will never be a problem.

Anything else that might prevent this from working?

If you want to switch the VCC of the SIM cards via the CPLD check the maximum current that the CPLD can drive. You may need an additional driver to provide enough power.

I don't have any experience with CPLDs

A good opportunity to start lerning how to use them. They're fun!

On the other hand if you want to finish your project fast it is probably easier to just use four analog multiplexers like the 74HC4051 and switch all signals in parallel from a microprocessor. All you need are 3 GPIO pins to control up to 8 SIM cards. You won't have to deal with different voltage levels that way either.

Oh, one last thing: In practice all SIM cards nowadays support 1.8V and 3V so you don't really have to follow the power up sequence of starting with 1.8V and then switching up to higher voltages. For a commercial project I would not recommend this, but for a hobby project I think it's fine to simplify here.

Nils Pipenbrinck
  • 5,087
  • 1
  • 19
  • 28
  • Thank you for the detailed answer, Nils. This is all very helpful. It sounds like analog multiplexers are the way to go in this instance! – user5077257 Jul 03 '15 at 14:48
  • Hypothetically, how would one resolve the issue of knowing if the SIM or GSM module is sending data on the IO line and then "forward" that bit? (in the case of using a CPLD) – user5077257 Jul 03 '15 at 14:58
  • 2
    @user5077257 The IO line is on high level while it is idle. Each byte starts with a low bit (the stop bit). To detect the direction you just wait until one side sends this start bit. Once this happens you know that exactly one byte will gets transmitted. You can route the received data to the output and keep doing so until the stop bits gets transferred (will always be high level). At this point you can switch back both sides to input and wait for the next start bit. As you can see it's not *that* difficult. – Nils Pipenbrinck Jul 03 '15 at 15:14
  • 1
    @user5077257 You need access to the CLK line to derive the baud rate from it. Otherwise you won't be able to count the transfered bits. You'll also have to keep an eye on the data-stream and look for PTS requests. These are used to negotiate different baud rates (aka CLK division ratios). – Nils Pipenbrinck Jul 03 '15 at 15:20
  • That's super interesting, thanks! A bit complex for now, especially given the possibility of variable baud rates, but very interesting! – user5077257 Jul 03 '15 at 17:13
  • There is also the TXS02326A chip that can do this. [From this answer](http://electronics.stackexchange.com/a/292587/36283). – not2qubit Mar 15 '17 at 18:36
  • @not2qubit seems like it's not able to translate to class-a (5V) supply. Not that there are much SIMs around that won't work with 1.8v, but still... – Nils Pipenbrinck Mar 15 '17 at 20:49
  • @sim2qubit nice find though! – Nils Pipenbrinck Mar 15 '17 at 20:49