UART connection between ATSAMD20 and ATtiny4313

Technically, you are correct. In reality, the term "RS-485" is usually used to mean "UART signalling on an RS-485 bus" - any other kind of signalling (such as Manchester encoding) would be specified explicitly. It's good to be technically accurate, but also good to consider less accurate common usage of terms.

Not all microcontroller UARTs have synchronous modes. Receiving or sending Manchester encoded data with a UART is fiddly because of the start and stop bits of UART, so it is often done by bit-banging. Whether or not that suits the OP, only he can say.

Reply to
David Brown
Loading thread data ...

The H1 bus is an industrial fieldbus and technical information about it has been notoriously difficult to access.

The Manchester coding in the H1 bus is sent as current variations, which are converted into voltage variations for receiving.

I'll show the more positive voltage with a plus sign and the less positive voltage with a minus sign.

A state pair takes one bit time (32 us) with the change at the middle.

A data bit of '1' is sent as +- A data bit of '0' is sent as -+

There are two intentional miscodings for delimiters:

A coding N+ is sent as ++ A coding N- is sent as --

A frame starts with a preamble of alternating 0's and 1's:

1 0 1 0 1 0 1 0 1 0

After preamble a start delimiter is sent:

1 N+ N- 1 0 N- N+ 0

The packet content follows, with most significant bit first.

After last data octet an end delimiter is sent:

1 N+ N- N+ N- 1 0 1

After the packet the transmitter is switched off, so the line will stay halfway between the + and - states.

The processor chip Manchester coders could not be twisted to handle the start end end delimiters correctly.

Reply to
Tauno Voipio

Not technically, actually. "Wouldn't be true RS485" is a very clear statement, which happens to also be wrong, no matter how hands are waved.

I never said anything different.

It is simply not practical to send Manchester encoding with a UART... but Manchester is not the only encoding scheme that embeds a clock. Or you can roll your own. The point is, clock encoding with the data is a viable method of overcoming the lack of precision in the clock rate, which does not require bit banging an I/O pin. The encoding scheme of IRIG is a real possibility. The data bits are PWM encoded, with three values; 0.2, 0.5 and 0.8 widths for 0, 1 and a sync marker. This would fit a UART very nicely. With a distinction of symbols of 0.3 bit times, it can tolerate a lot more clock error than a typical async data stream with a start and stop bit on each character. It would also be pretty easy to decode. Align to the rising edge, and count the bits in the received data to find the falling edge. 0.1, 0.2 and 0.3 are all a zero bit. 0.4, 0.5 and 0.6 are all one bits. 0.7, 0.8 and 0.9 are all sync markers. To prevent the UART from missing anything important, set it for 7 data bits and no parity on receive. Then it always stops one bit early. Then if the timing is off by 10%, you still don't lose any data. This can be better than using a USART, actually. It does the alignment in the hardware, making the decoding simpler. It also includes a sync marker.

Yeah, I think this is a much better scheme than Manchester encoding.

Reply to
Rick C

If the bus speed is known, this packet seems overkill. It can be used to detect the BAUD rate.

The Atmel USART is designed to use a 9-bit mode for packet data, with the 9th bit set for addresses.

/Ulf.

Reply to
Ulf Samuelsson

Yes, my point is you can run the USART at a higher rate and send data as x0F, xF0, x00 or xFF. You can use the hardware without a hardware Manchester encoder.

Actually, I think Manchester encoding is inferior to the scheme they use in the IRIG signal (also the WWVB time broadcast). I don't know if that PWM scheme has a particular name, but it is very robust and can be implemented with a UART, so no USART required. The UART aligns to the start of the bit frame, so less work in the software. It becomes a matter of recognizing which of the 7 bit patterns are received. You really only need to look at two bit positions to distinguish the three values.

Reply to
Rick C

Sorry, two points to distinguish the three values encoded in the eight possible received bit patterns using a 7 bit character.

Reply to
Rick C

You certainly /can/ do this kind of thing in software on a Tiny. However, it might be a challenge depending on other factors. If the device already has high-precision timing requirements for another task, doing two of them can get complicated. If you need to deal with a lot of noise on the lines, that too is messy.

Reply to
David Brown

Perhaps he already has the boards produced - adding a crystal is then a rather difficult task! Even if the design is not completed, the Tiny is a very small, cheap and low power family. Adding a crystal makes the design bigger, more expensive and uses more power - assuming there are suitable pins free for connecting a crystal. Now, a small, cheap crystal might be $0.50 and just a few square millimetres, but so is a small AVR Tiny. I don't know why the OP is using a a Tiny, but if it is for good technical or economic reasons, adding a crystal would work against it.

Trial-and-error, as I suggested earlier, is another workable choice.

Reply to
David Brown

The packet structure and coding is set in the standard. An USART cannot create the bit patterns, even with fictive data, as there are fixed start and stop bit patterns.

Reply to
Tauno Voipio

I don't think you understand the issues. If there is a lot of noise, the project is dead in the water regardless. Fix your noise problems.

This does not impose "high-precision timing requirements" on the CPU. The only requirements are to handle the data without dropping. It's NOT bit banging, so there is lots of time to handle the data.

If the CPU is overloaded, then you picked the wrong CPU. Get a faster one.

Why are you bringing in all this silliness? It's almost as if you've never done design work.

Reply to
Rick C

Yes, trial and error. I believe that's the design process recommended by NASA.

WTF are you talking about? If he's designed the board without considering the requirements, that's a failure of the first order. If someone imposed new requirements on the design, that's a perfect justification to respin the board.

Once again, not rocket science.

Reply to
Rick C

Feel free to try /reading/ posts before making comments about them that show you up your ignorance.

Reply to
David Brown

Have you heard the saying that it is better to keep quite and be thought a fool, rather than opening your mouth and proving it? Do you think the OP would have started this discussion if "just use a better microcontroller" were a viable option?

Reply to
David Brown

David, that wasn't a reply to the OP, that was to your silly speculation.

Reply to
Rick C

Il 26/04/2023 16:56, pozz ha scritto:

I want to thank all the ones that spent some time to reply and give suggestions. As usual, they are valuable for me.

I'm working on a board that is already in production. It was chosen a tiny for its low cost. The possibility to mount and use an external ceramic resonator is available. Moreover it has been really mounted on around 1k boards that are working now.

However a few customers reported a problem in a few installations: the tiny blocks and only a power cycle is able to restart.

After some tests, we found that the problem is radiated noise on the pins of the tiny oscillator. When power cables are near the board and some specific load are connected to these cables, the noise generated is capable to block the tiny.

We tried to replace the ceramic resonator with a quartz crystal without success. We tried to strenghten the GND connection between the resonator/quartz and the single GND pin of the SOIC20, without success.

The only change that seems effective in avoiding blocks is using the internal oscillator.

This is the story.

Reply to
pozz

So I assume there is a reason why you can't route the power wires away from the ATtiny board?

I think you have been provided with all the possibilities for how to use the internal oscillator. It rather comes down to "pick one". Are any more appealing than the others? If you tell us what you don't like about it, maybe we can help refine the solution?

Reply to
Rick C

It depends. In some cases it is possible, in other cases it isn't. The installer isn't usually competent, so it routes cables as he wants. In some cases, too near my board. After some weeks or months, he complains the board has blocked. And he is my customer...

At the moment we are deciding what could be the best solution.

Reply to
pozz

Do you do EMC testing for radiation emission and susceptibility? I don't know what the rules and regulations are like where you are, but any finished product (as distinct from prototype or test systems) made here in Europe should be EMC certified. If radiated noise from "normal" power cables killed a card, that would be a failure in the certification.

Or is it the surrounding system that is bad? Maybe there is something truly terrible connected to these power cables?

Reply to
David Brown

Perhaps you can add an enclosure to your board so cables can not be so near? You could make it look like an EMI shield. Heck, a simple piece of plexiglass mounted a half inch from your board should do the job. Also, it is perfectly acceptable to specify that nothing be within some distance of your board. That is not an unusual thing for sensitive circuits.

BTW, do you get the same sort of hang condition if you bring other metal near the oscillators? It may not be an EMI issue at all, but rather a capacitive effect on the oscillator circuit. They often are sensitive to the details of the parasitic values. If you have a resistor in series with the crystal, this might need to be reduced in value, or increased. What circuit does the manufacturer recommend for the oscillator?

Can you provide more detail on the nature of the hang? Does the oscillator stop working? Does the frequency shift? Can you measure any of this? Just saying "without success" isn't much to go on.

Reply to
Rick C

Yes, of course. This problem happens only on the field in a few installations where cables are routed near my product, that is small and in a plastic enclosure.

The critical installations often have cables that gives mains power (230Vac) to coils, for example relays or door ring bell.

Reply to
pozz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.