UART connection between ATSAMD20 and ATtiny4313

I'd like to use async UART to let these MCUs communicate. The protocol will be request-response with the request generated by the SAM MCU. The baudrate will be 38400bps.

I'd like to use internal oscillator of ATtiny4313, while the SAM will use an external 32.768kHz crystal (that is multiplied by internal PLL to reach 48MHz).

I'm not sure if this scenario can work well. My concerns are related to the internal oscillator of ATtiny4313 that hasn't a good accuracy over temperature and life.

The tiny MCU will be supplied by 3.3V and its temperature will be in the range 0-80°C.

Reply to
pozz
Loading thread data ...

The rule of thumb is a maximum of 5% total mismatch in baud rates between the two sides. One side has a crystal and PLL, so it will be quite close - that means you can have most of the error margin on the other side. If the internal oscillator is within 2%, you should be fine. If it is 5% or more, you will want to do some automatic measurement of the rate.

Reply to
David Brown

I don't get what your question is. You seem to understand the concepts. You don't tell us the relevant data however. What does the data sheet say about the frequency variability of the internal clock over PVT (process, voltage and temperature)? I assume you are aware that the 3.3V supply will have an accuracy and an RC clock rate can be voltage dependent. It depends on how they designed the circuit. There are techniques for removing most of the voltage dependency, if they used them.

You can always use the bit times of the SAM to adjust the bit rate on the ATtiny. That used to be part of the protocol for low data rate modems. The first characters sent were AT if I recall, which give good edges to time to measure the bit rate. At 38400 bps this might be a bit tricker, it depends on your instruction rate. A bit time is just 26 us. Will this be a software UART, or a hardware unit?

Reply to
Rick C

ATtiny4313 datasheet[1] says the internal oscillator is factory calibrated with an accuracy of +/-10% at Vcc=3V and 25°C temperature. This accuracy can be reduced to +/-2% at a fixed voltage and a fixed temperature with a user calibration.

I could calibrate for a fixed voltage (3.3V), but I can't fix a temperature, because it can vary in the real application.

I tried to heat the ATtiny4313 with a heat gun and the communication between SAM and tiny didn't stopped, but I know this isn't an exaustive test.

[1]
formatting link
Reply to
pozz

ATtiny4313 datasheet[1] says the internal oscillator is factory calibrated with an accuracy of ±10% at Vcc=3V and 25°C temperature. This accuracy can be reduced to ±2% at a fixed voltage and a fixed temperature with a user calibration.

I will use the interal UART peripheral of ATtiny4313. I can't add too much code, the Flash memory is almost full. I wanted to know if the figures shown on the datasheet guarantee good communication between the the MCUs. It seems this isn't the case.

[1]
formatting link
Reply to
pozz

10% total error (combination of both ends) is pretty much right at the limit according to the usual rule of thumb for UART receivers that sync only on the start bit. IIRC, there used to be UART receivers that would sync on every edge within the data "word" as well, but I don't think that was ever very common -- and to take advantage of it, you had to make sure your data had edges. :)

Can you spare a line for a clock and go synchronous? (Or are they really UARTs and not USARTs?).

2% is no problem at all. With a crystal on the other end, you should be able to easily tolerate +/-5%. The requirement for a fixed temperature, OTOH, is usually a problem.

Does the ATtiny have an on-die temp sensor? If yes, you could try characterizing the oscillator over temperature at 3.3V and adjusting the baud rate divisor as the temperature changes. That get's expensive if you have to do it on every unit during production, but if the T/F curve is consistent enough between units, then maybe...

Reply to
Grant Edwards

Ok, that is information. Do you have a question?

You point me to a data sheet. I am not reading the data sheet to do your work for you. I'm happy to discuss the information and offer advice and opinion. The info you provide above with the 2% stability if temperature and voltage are maintained and the clock calibrated, is not enough to know if this will work.

When you write, "It seems this isn't the case.", what do you base this on? What is your reasoning?

I don't think the software UART is a lot of code, but you don't need that. You need to write a routine to measure a bit time on the input to calibrate your clock to the incoming bit times. That should not be a lot of code. Translating a loop count into a bit clock setting for the UART should be a simple linear relationship, although it may involve a divide. You only need to work over a small range, so a small table lookup should be pretty close to optimal solution.

I don't see where you have a choice, unless you want to add a crystal to the ATtiny. Can the SAM chip send a clock? You can use an SPI port instead of a UART, or just send a clock to use for the bit rate clock in the UART?

Reply to
Rick C

I think you are not doing the calculation right. The limit is based on the UART trying to sample in the middle of a bit. If it gets out by a half a bit time, either way, it will sample the wrong bit. With 10 bits in the character, including start and stop bits, that puts the total error limit at about 5%. This is actually closer to 5.5% (because while it is 10 bits, it's only 9 bit times between start and stop bits), but then you need to subtract a fraction of a bit for the internal Nx clock used to sample the bit stream. So round off to 5%. That's the total error allowed, including both ends. Then there's distortion in the pulse edges. With 26 us bit times, there may be issues with asymmetric edge distortion. There has been no mention of the electrical interface.

Calibration, in general is expensive. But yes, a calibration curve is worse, since you need to wait for temperature to adjust.

Reply to
Rick C

That's definitely one way to do it, yes.

Have the master side send a couple of 0x00 bytes before the data, and use an interrupt on the Rx pin falling edge - when that comes in, count the time until a rising edge is seen. If that time works out to within

10% of the nominal expected time, you are calibrated and can turn off the interrupt. Alternatively, send 0x55 bytes first and measure multiple short periods. There will be some details to work out, depending on the what you are sending, the type of noise you expect, how often you need to re-calibrate, etc. You are making a software equivalent to a PLL.

There's no need for a lookup table here (unless I've got my calculations upside down!). The more cycles you count for the incoming trainer characters, the bigger the UART divider value you need. That means your divisions will be done with constant values, and the compiler will turn those into multiplies.

An alternative is trial and error. If your clock source is ±10%, and you need to get within ±2%, start your UART at the nominally correct baud rate. If you don't receive error-free telegrams within a timeout, go 2% faster. Keep adding 2%, stepping from +10% to -10%, until you hit a baud rate that works.

You can get even fancier here by figuring out the lowest and highest rates that work, then picking their average to get the best value.

Reply to
David Brown

No, I can't. The MCUs are not on the same board and they are really connected through RS485 half-duplex transceivers.

Thank you for this suggestion, but I can't use this trick.

Reply to
pozz

And I don't want you do it if you don't want. The datasheet link is there if someone WANTS to look at it with a single click of the mouse.

Because internal oscillator has an accuracy of 10% and I read that UART receivers are usually able to decode the input signal with an error of

2-5% order.

However I tested one sample at high temperature, but the MCUs continued communicating well.

Ok, thanks for suggestion.

No, this isn't an option.

Reply to
pozz

The other option would be to adopt a Manchester-encoded (self clocking) signal. Wouldn't be true RS485 but would pass through transceivers and cabling at sensible baud rates. Manchester coding is fine provided the clocks are within 2:1 of each other. You will need to bit-bang the interface though, the UART won't handle it.

Reply to
Andrew Smallshaw

I'm glad we are in agreement. My point is you could have pointed us to any useful info in the document, or better quoted it, if there was anything you had not already quoted. I find CPU data sheets to be rather onerous to read, as they have so much data in them these days, and they don't always put timing data in the timing section, for example.

The 10% was for a fixed voltage and temperature without calibration. I don't recall if you are adverse to calibration. But you do have a wide temperature range which is an issue.

That means pretty much nothing. While testing can prove that something doesn't work, it can't prove that it does.

Instead of simply testing pass/fail, it would have been more useful to measure the clock rate, by measuring the bit rate over temperature. Get some numbers for multiple units to see what sort of spread you get.

You can't add a crystal? Then the two workable choices would appear to be calibration of each unit over temperature, or a real time calibration from the data rate of the incoming data. I can't think of any other solutions. Adding the crystal seems the simple route.

Reply to
Rick C

What about Manchester encoding is not RS-485? That's just an electrical interface standard, no?

But that is a great idea... if the hardware will accommodate it. Or this can be done in the UART using a faster clock and synchronous mode. Send characters with one data bit per character, the Manchester encoded bit, x0F or xF0. It would not be terribly hard to decode the data in software.. possibly. I believe you align to the transition that is always present mid-cell, then look for the presence/absence of the other transition. The OP talked about the "small" processor being program space constrained, but again, this is not a lot of code... maybe. So maybe this will be too much. But it would solve the clocking issue. Then again, so would a crystal.

Reply to
Rick C

I doubt that the ATTiny can handle Manchester coding at the requested bit rate, and it may be difficult for the SAM.

In 2016, I made a processor unit using AT91SAM4E for IEC H1 Manchester coded bus at 31.25 kbit/s. The trick was to innovatively use the timer counter units of the chip. A timer used to measure the times between pulse edges could be used to receive and decode the incoming data, and a timer running at half of the bit rate (15.625 kbit/s) could be used to send the data. The receiver needed to respond to interrupts at the incoming edge rate, and the transmitter needed to respond at the outgoing bit rate.

Reply to
Tauno Voipio

Atmel implemented Manchester Coding in the SAM7 USART (My proposal) but the SAMD20 has a "SERCOM" module without Manchester Coding. I would look into the event system.

The tiny will have to do it in S/W. /Ulf

The SAM4E USART supports Manchester Coding in H/W. The SAM4E UART does not.

/Ulf

Reply to
Ulf Samuelsson

That's if the entire job is handled in software, perhaps. The USART can be used to send the bits as characters at the transmitter. A USART can be used to handle the reception with software seeking edges. I don't think that would be a huge burden at 38.4 kbps. But then, I'm more used to FPGA work.

Reply to
Rick C

The problem with the USART Manchester coder was in address markers (intentional mis-codings). It was not possible to conform with the markers in the IEC coding.

Reply to
Tauno Voipio

Had to bit-bang. The USART cannot create or detect IEC H1 standard address marker octets.

Reply to
Tauno Voipio

I did a Google search and this didn't return anything useful. So I don't know for certain what an IEC H1 standard address marker octet is, but if I'm specifying the waveform, rather than relying on the hardware to do the Manchester encoding, I can't see a reason why I could not transmit any given waveform. Can you point me to something that describes these marker octets?

Reply to
Rick C

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.