4
\$\begingroup\$

Ok, this might be a silly question, but i'm kind of new to STM32 development.

I am designing a custom board that, among other things, it communicates with eight array of sixteen independent boards, each with some sensors mounted, through a sort of custom RS485. Communication must be in parallel and, hence, every sensor is connected to a UART block of the microcontroller.

In total, we need to readout 16 x 8 = 128 sets of data, and for every array we need to keep one board powered on for other reasons (e.g. voltages actuation). These boards are sending out data as soon as they are turned on. Therefore, we'd like to read the data coming from these eight board "simultaneously".

(16 boards) Array 1 Data --> Transceiver --> UART1
(16 boards) Array 2 Data --> Transceiver --> UART2
(16 boards) Array 3 Data --> Transceiver --> UART3
(16 boards) Array 4 Data --> Transceiver --> UART4
(16 boards) Array 5 Data --> Transceiver --> UART5
(16 boards) Array 6 Data --> Transceiver --> UART6
(16 boards) Array 7 Data --> Transceiver --> UART7
(16 boards) Array 8 Data --> Transceiver --> UART8

The interface between the microcontroller and the sensors' world is isolated through the use of ISO77xx digital isolators by TI.

Now, the issue is that i don't have eight UART blocks available from the microcontroller (for debug purposes, i'm using a STM32F756ZG Nucleo Board). I know bit banging is a thing, but i'd like to avoid this method for deadline reasons.

My proposed alternative is to use four UART multiplexed into two channels each: this would break the parallel communication requisite but we are good by polling four sensors each, and then switching to the other four sensors. In this way, every transceiver is associated to an array of sixteen sensor boards.

I've sketched a (very stupid) schematic to visualize the system:

from left to right: RS485-UART converter, MUX, isolation, STM32

The thing is: i don't know which kind of problem would arise by using this architecture, and i see this as a problem. I can choose a MUX depending on communication speed (115200 bits/s), while the switching logic would be very slow (few seconds of polling per group of sensors). Voltage levels are okay.

Is this architecture okay, stupid or does it have some flows? Please let me know everything i should take into account.

Kindly thanks for your answer.

\$\endgroup\$
9
  • \$\begingroup\$ The STM32F756ZG datasheet shows the device contains USART1/2/3/6 and UART4/5/7/8. From a quick read of the datasheet the four USART and four UART modules support Full-duplex asynchronous communications. Doesn't that allow eight full-duplex asynchronous interfaces to be used? Or have I misunderstood? \$\endgroup\$ Commented Jul 5 at 12:30
  • \$\begingroup\$ It doesn't sound like you need a lot of bandwidth. Why not use just a single RS-485 connection for all 8 sensors? \$\endgroup\$ Commented Jul 5 at 12:35
  • \$\begingroup\$ @ChesterGillon The MCU does have 8 U(S)ARTs. The Nucleo board has other stuff connected to MCU so not all 8 are available through the board. \$\endgroup\$ Commented Jul 5 at 12:39
  • \$\begingroup\$ @ChesterGillon , yes you are correct that nucleo board has 8 uart channels, but two other uarts are used for another set of sensors. Therefore, it leaves me with only 6 uarts free (5 considering the one used by the st-link). \$\endgroup\$ Commented Jul 5 at 12:53
  • \$\begingroup\$ @DaveTweed let's say i generalized the "sensor" stuff, while actually it is a set of sensors. Imagine reading data from 8 different boards providing different sets of data. I need to read the same set of data simultaneously from these 8 boards. This architecture would allow me to receive the data with a few seconds of delay. \$\endgroup\$ Commented Jul 5 at 12:56

5 Answers 5

4
\$\begingroup\$

Thank you for all the clarification. I think you're still overcomplicating things (it sounds like you could just let all 8 sensor complexes send data continuously, no problem, and only listen to each one in turn. The 7 others don't seem to care whether you're listening or not).

But if that's not the case, the usual solution is to have an actual bus where you can have multiple data streams, or packets, or whatever, transported in a non-conflicting manner.

Now, there's mature solutions to the problem of connecting 128 sensors to one controller – CAN bus comes to mind; it's meant for pretty much the use case of one electronic control unit query dozens to hundreds of sensors. It's robust as RS-485, because that's what it's been invented to replace, by the automotive industry. That would solve this all at once.
Alas, it seems you're stuck with a sensor model that plain can't do CAN; bummer.

Now, the usual solution to your problem "I need to interface a large number of nodes to a single controller" is still: give the controller a single, fast interface, with which it can talk to all the sensors, while these work autonomously. This helps a lot with your isolation problem: now you only need to isolate that single bus, instead of 8 (or 4 at reduced functionality).

So, here's how I approach it, given the info you've given in response to my previous answer:

  1. Use a simpler microcontroller that speaks, unisolatedly, to exactly one sensor array. A microcontroller with a single UART is easy and cheap to find – ST's STM32G0 low-cost series would totally do!
  2. Aside from attaching the sensor array to the UART side of the microcontroller, use its SPI peripheral on the other side: That allows you to exchange data at very high speeds, very low effort, and best of all: daisy-chained
  3. For simplicity's sake (you could do this in software, but why be complicated?), dedicate one input pin to be a "now read a command from the SPI buffer, and put your sensor data in the buffer".

The core idea here is that the communication with the continuously sending device (sensor array) can well be handled by a "simple" device, which becomes easy to develop and test, and that you then build a secondary arbitrarily extensible bus onto that, which in itself should also be easy. That way, you get "infinite" extensibility, at low component cost, and ease of isolation.

System as a whole would look like this:

                               ┌──────┐     ┌──────┐          ┌──────┐      
                               │Sensor│     │Sensor│          │Sensor│      
                               │Array │     │Array │          │Array │      
                               │  1   │     │  2   │          │  8   │      
                               └──┬───┘     └──┬───┘          └──┬───┘      
                                  │            │                 │          
                               ┌──┴────┐    ┌──┴────┐         ┌──┴────┐     
                               │ UART  │    │ UART  │         │ UART  │     
                               │       │    │       │         │       │     
                               │  MCU  │    │  MCU  │         │  MCU  │     
                           │   │   1   │    │   2   │         │   8   │     
                           │   │       │    │       │         │       │     
                           │   │ SPI   │    │ SPI   │         │ SPI   │     
 ┌──────────────────────┐  │   │       │    │       │         │       │     
 │Main Controller   MOSI│──│──►│IN  OUT│───►│IN  OUT│───► … ─►│IN  OUT│───┐ 
 │                      │  │   └clk trg┘    └clk trg┘         └clk trg┘   │ 
 │                      │  │    ▲    ▲       ▲    ▲            ▲    ▲     │ 
 │                  SCLK│──│────┴────│───────┴────│─────► … ───┘    │     │
 │                      │  │         │            │                 │     │ 
 │          trigger GPIO│──│─────────┴────────────┴─────► … ────────┘     │ 
 │                      │  │                                              │
 │                  MISO│◄─│──────────────────────────────────────────────┘
 └──────────────────────┘  │
                           │
                  isolation boundary

Note that you can, no problem, instead of having 1 isolation barrier between the Main Controller and all MCUs, being a simple 4 optocouplers, have 8 isolation barriers instead, being isolated RS-485 transceivers (e.g., TI ISO3086), isolating each Sensor Array individually.

The communication would then look like this:

  • Main controller sends out command (typically "give sensor value!") for MCU 8 by putting command in its SPI buffer, and telling its SPI interface to send 1 byte
    • this causes the Main Controller's SPI peripheral to automatically toggle SCLK 8 times, sending one bit of the byte at each rising edge through its MOSI pin
    • this byte is now in the SPI input buffer of MCU 1
    • the MCUs' processors don't ever deal with the fact that something is happening on SPI. The "shift register logic" is all baked in hardware in a MCU's SPI peripheral!
  • Main controller sends out command (typically "read sensor!") for MCU 7
    • this shifts the contents of MCU 1's buffer into MCU 2's buffer, and puts the command for MCU 7 into MCU 1's buffer
  • Main controller sends out command (typically "read sensor!") for MCU 6
    • this shifts the content of MCU 2's buffer into MCU 3, the contents of MCU 1 into MCU 2, and the new command into MCU 1
  • Main controller sends out command (typically "read sensor!") for MCU 1
    • now, every MCU has "its" command in its buffer
  • Main controller pulls up the Trigger output
  • In reaction to the Trigger getting pulled high, each of the 8 MCUs reads its SPI buffer. It interprets the command.
    • typically, that command would instruct the microcontroller to put a reading received from its sensor array into the SPI buffer
    • So, the microcontroller, which has been interfacing with its sensor array via UART all the time,
  • After a while, the Main Controller sends 8 new commands. This time, however, it observes what gets put into its SPI buffer through the MISO pin
    • the first byte comes from MCU 8, the second byte from MCU 7, and so on
  • The Main Controller now has the values from all the Sensor Arrays, through a single interface
\$\endgroup\$
13
  • \$\begingroup\$ Good approach. I just don't think that the "shift register logic" is a common feature on many MCUs. But it can of course be implemented in software. \$\endgroup\$ Commented Jul 6 at 13:55
  • \$\begingroup\$ @user930473 it absolutely is a common feature. It's literally what every single SPI peripheral I've encountered is (at least on STM32)! A shift register. It's baked into the design of SPI. \$\endgroup\$ Commented Jul 6 at 13:58
  • \$\begingroup\$ @user930473 take the STM32G0x0 reference manual, Figure 288 on page 865. See that shift register between MOSI and MISO! That figure has been the same since at least my first STM32F1 experiments, like, 2008-ish. You can still find it in the reference manuals of these old chips! And that's not surprising at all: SPI is based on shift registers, from start to finish! \$\endgroup\$ Commented Jul 6 at 14:02
  • \$\begingroup\$ @user930473 to confirm: When you look up Motorola's AN 0991 from 1987, and check the section on "Communication Considerations": yep, they speak of shifting bits! And so does the assembler at the end of the document :) In 1987, SPI was new and you needed to emulate that behaviour in software on most microprocessors. When you buy an arm, or RISC-V, or Attiny, or really any other modern commercially available MCU, it usually has at least one SPI peripheral that does this in hardware :) \$\endgroup\$ Commented Jul 6 at 14:16
  • \$\begingroup\$ Ah I think the 1984 Motorola Single-Chip Microcomputer Data book is the original source; p. 3-415: The SPI consists of: a) an 8-bit shift register (MSB out first; MSB in first) which may also be used as an SPI data register,…. Yep! Motorola designed SPI to allow exactly what I described in the answer. Anything that doesn't have that "shift register mode" should probably not be called "SPI", and really, all commercial microcontroller do have such an SPI peripheral. \$\endgroup\$ Commented Jul 6 at 14:25
2
\$\begingroup\$

The RS-485 transceivers need also trasmit/receive control from each UART, in addition to TX and RX. That means for 4 UARTs you need 8 channels of transmit and 4 channels of receive isolation, in addition to one bit for selecting between bank of 4 transceivers out of the 8.

This means you need more muxes and/or isolators depending on how you want to do that.

If you are anyway using cheap Nucleo or other boards, use one suitable cheap board on the isolated side to handle sensors as a whole, and let it communicate with only one high speed isolated link with the F7.

\$\endgroup\$
1
  • \$\begingroup\$ I thought of using another STM32; the problem is that only F7 onwards have 8 UARTS. Moreover, being kind of a learner in the STM32 world, i would like to avoid using two microcontrollers and have everything centralized. UART communication will be half-duplex, and adding another isolator won't be a problem. \$\endgroup\$ Commented Jul 5 at 15:11
2
\$\begingroup\$

Frame challenge: You're going about this in a way that is complicated and expensive; and you actually seem to have realized that:

I want to measure the temepature of 8 remote sensors, ideally all at the same time (simultaneously)

Well, that sounds to me like it makes no sense. I don't know your sensors, but reading a temperature sensor takes milliseconds, at most. Thermal systems are typically slow compared to that. I'd be interested in the thermal mass of the system you're observing if reading the 8th sensor, say, 80ms later makes a large difference.

If i measure the temperature from 4 sensors only, and after a few second i sample the temperature of the other 4 sensors, this is "simultaneous enough" to me since i don't expect temperature to change inside this time frame.

You've answered your own question there: single-UART, round-robin sensors will totally suffice. "after a few seconds" is eternity in terms of digital communications. You're really not solving a problem here.

In your situation,

 isolation barrier

    (3×octocoupler)
  ,——|–——————————————.
 /   |     s1,s2,s3   \
 |   |                 \
 |   |                  v       |A1–,==> Sensor 1
 |   | A                  2×    |B1/
MCU<>|===============[multiplex]|A2–,==> Sensor 2
     | B  RS-485       (analog) |A3/
     |                          |…         …
(isolated RS-    (analog        |A8–,==> Sensor 8
 485 transcei-    multiplexing  |B8/
 ver, e.g.,       can be imple-
 ISO3086 or       mented easily
 ISOW1432 if      with 8:1 bus
 power for lo-    switches,
 gic on isola-    e.g., 2×
 ted side is      SN74CBT3251)
 required)   
                 

Don't forget to terminate at each sensor.

\$\endgroup\$
7
  • \$\begingroup\$ Really thanks for your answer. I need to highlight that temperature is not the only data we need to read, as every "sensor" is actually a set of "independet boards", each with its own data transmitted and received. Temperature was just an example. Now, the idea to use multiple transceivers comes from controlling every "set of boards" independently, because we will have one board turned on for each channel. This means that using only one transceiver is not possible, since data from two sensors is being sent on the same bus. I don't know if this is now clearer, though. \$\endgroup\$ Commented Jul 5 at 17:23
  • 1
    \$\begingroup\$ no, it's not, sadly. The actual nature of the sensors doesn't matter here at all. The only question that matters is how fast it takes to interact with a single sensor in total, and whether 8× that time is still acceptably fast. And you, in your own comment, confirmed that "a few seconds" is enough. So, no problem here? \$\endgroup\$ Commented Jul 5 at 17:26
  • \$\begingroup\$ could you edit your question and actually say why you think that talking to each sensor in sequence is not an option, based on actual timing? because, so far, that does not arise from what you told me :) Thank you! \$\endgroup\$ Commented Jul 5 at 17:32
  • \$\begingroup\$ I edited the question, and hope it is now clearer. The thing is that timing is not an issue, as we can receive data from each board in sequence (and accept this data as "simultaneous" even in a time frame of a second). The problem is that if eight boards are continuously sending data to the STM32, i cannot use only one transceiver as these data sets are all on the same bus. \$\endgroup\$ Commented Jul 5 at 17:52
  • \$\begingroup\$ Can you not send a data request signal to each board rather than letting them just keep blasting data at the STM? \$\endgroup\$ Commented Jul 5 at 18:12
2
\$\begingroup\$

Based on comments your total needs are 8 UARTS for the sensors and 3 UARTs for other purposes, total 11.

There are a few STM32s that have this many. For example STM32H723VE has 5 USART, 5 UART and 1 LPUART. The H7 series is among the most powerful and complex of the STM32 processors, but is not that different from the F7 you are already using. STM32F413 and STM32F423 have 4 USART and 6 UART available. You can consider replacing the debug UART with SWO functionality.

STMCUFinder is a good tool for searching through the options.

There are also premade solutions for software emulation of UARTs using DMA functionality. For example see ST application note AN4457 Implementing an emulated UART on STM32F4 microcontrollers.

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

Can you use the USB? The STM32F756ZG has USB ports, so you could attach a 4-channel USB->serial device on that (e.g. FT4232HQ). You now have 4 on-board serial ports and 4 more serial ports via USB, so everything can be directly connected. This would make your life much easier because you have constant communication to each sensor board.

\$\endgroup\$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.