So, after realizing my first circuit were not up to snuff because how the internal clock on the ATtiny841 behaves when you run it off 5v, I made a new version, and included a crystal at 16MHz
(and having done at least some of my homework, I realized it should have fitted capacitors, and tried to calculate the right value(s) based on the internal capacitance of the crystal.)
Now, when I burn the bootloader, with the setting to use an "external Clock Source", I still get the out of sync errors, just like I got with no external crystal.
I remember esteemed Dr.Azzy said he used external crystals on the 841 boards he made for the same reason. But now I really am at a loss here, and can't figure what I am doing wrong.
I'll keep tweaking and trying though. But all the same I really would appreciate all and any input on this.
Here is a simple sketch of how I have things connected at the moment;
Coming out of the factory, the chip will run from its internal clock, and possibly set to a low value, like 1 MHz. You may need to slow down the communication for the first ICSP programming run.
Two things I notice in your schematic:
there is no ICSP header. You need this to program the chip, there is no bootloader on it yet so it will not respond to Serial commands. I'm not sure if you can even set fuses via the bootloader, I recall that required an ICSP connection.
the capacitors with the crystal have a very low value, common is 20-22pF. The 2x 6pF in series give 3 pF, plus a little parasitic in the traces, total 6-7 pF or so. Most crystals ask for double that.
Thanks for replying- and my bad for not clarifying that in my first post; I have connectors for programming through ICSP (and most other pins, though it does not show up in the drawing) and I do successfully upload bootloader (or a sketch, though I know that overwrite the bootloader) through ICSP, so I know the chip works.
My idea were to upload them through serial on this board, as that uses fewer pins, and don't require a second arduino as ISP just to program the board(s)
I have tried bootloaders with the setting at 8MHz (internal, >4.5V), 16MHz (Internal) and, with the crystal in place; 16MHz (External), but neither gets the serial communication tonwork more than randomly one out of aproximately 50 tries. (And when it works I can't reproduce the result or upload another sketch again, even with no changes in the bootloader settings)
The size of the capacitors is possibly an answer though. How would that affect the frequency from the crystal?
I did make my own arduino nano a few years ago, just for a different project, and had that working fine for upload through USB, though the Mega 328 doesn't have its own clock (if I remeber right) so it had an oscillator for the 16MHz, but working without external capacitors to it. Stil have some of those laying around.
Would perhaps using the same oscillator work the same for my ATtiny 841 also, considering it worked on the ATmega328?
If you have the capacitors wrong either the frequency may be a bit off (no big deal), or your crystal may not oscillate at all (very well possible in your situation). The latter is a very big deal as setting the fuses to external crystal means you effectively brick the chip until you get the crystal to work, or get some other form of clock signal.
The ATMega328 does have its own internal oscillator, like the ATtiny841, limited to 8 MHz. Arduino has it set by default to 16 MHz external crystal.
Looking back at your schematic I notice another major error: the crystal pin 1 is left unconnected. It should connect to the right-hand side of C6. This way it won't work, ever.
Now if you don't have your chip set to external crystal you may try something else: see if the CH340 actually works. Upload a simple sketch using ICSP, which then prints something like "Hello, world" onto the Serial port. That you should be able to see in the Serial monitor. If not, there's something wrong with the CH340.
For ICSP programming you don't need a second Arduino - a simple USBasp programmer works wonders. Thanks to a set of pogopins I don't even have to solder in a header, just press it against the block of 2x3 through holes. I find USBasp to work better than using a second Arduino as a programmer, which I've done before (I just dedicated a Nano to it, just like I dedicated a Nano for UDPI programming of the newer Atmel chips - those boards are very cheap anyway).
For programming over Serial, instead of using a CH340 on board as your schematic shows, you can use an FTDI cable, which is also used with the Pro Mini boards. As added bonus it gives you easy Serial debugging.
The missing wire on pin 4 is my bad, but thankfully only on this sketch, and not my circuit.
Then again I did not spot it missing before uploading, so good of you to check in either case.
The hello-world sketch is a good idea though. I will try that.
On thebother hand; if setting the 841 to external oscillator, while that were not working, would that also mean I would not be able to upload through ICSP?
I ask because I have burnt bootloaders with the fuse set to external, having had no serial working, but still been able to later upload working sketches through ICSP later (the complete circuit has some aRGB leds controlled by the 841, and i get them to play as intended, changing colors and intensity)
So if it would temporarily brick my 841 if it is set to use an external oscillator, but the oscillator did not work, then technically I shouldn't be able to upload scketches through ICSP or burn bootloaders with other settings? (Which again must mean the oscillator does work, but perhaps at an odd frequency?)
I also did consider going with an ATtiny85, but I tried it once, but never got the UPDI to work. Might have been me again, trying to invent the wheel on my own or something, but I werent even able to determine if I needed to burn a bootloader to get the UPDI to work, or if I could burn bootloaders to the 85 through UPDI. Though having only one pin instead of two, would make things even easier in my case.
And thanks for sparring with me here. I really do appreciate your input!
I think so. The processor must be operating to receive the data and write it to its memory.
It sounds like in your case the oscillator is in fact running. Maybe at an off frequency? I don't know enough about crystals to know their limits.
The ATtiny85 is also programmed through ICSP.
UPDI programming (indeed nice - only needs the reset pin) is for the 0 and 1 series like the 402 and 814.
You're right again, and I remembered wrong. the chip I were toying with were the 816 -helps to go back on the computer and check, rather than trying to go by memory. I'll have to keep trying to get the UPDI to work there though I suppose. If I do mange to get serial UPDI to work, I might just have to change the chip on my project yet again, and use that instead.
-But is it true that you can upload through that, even before burning a bootloader? -meaning I do not need to worry about the ICSP wires for the 816, -or similar-, just the reset for UPDI? It's almost hard to believe if so. But even more reason and motivation to keep testing UPDI with the 816 boards I have.
As to the crystal, -I'll do a test with the serial message as you suggested, as soon as I have the time to go solder and tinker again. Might be there's some other issue than the crystal even. I'll try with a different (off-board) USB-Serial too, in case there's either wiring or something else not working as intended with the CH340E here too
Yes, UPDI is that simple. I'm using a modified FTDI/USB adapter using the jtag2UPDI method. Those chips don't support ICSP. No bootloader needed, that's for Arduino-style Serial programming.
I did consider repurposing an arduino Nano as an JTAG2UPDI for testing the 816, but never got it to work. Then I saw the sketches for that were pretty much discontinued too.
I also tried to make my own, on-board with a CH340E (again) and the apropriate resistors. That never worked though, sadly.
I also built my own UPDI programmer but used the cheap CH330N chip. The programmer was built before a diode was recommended instead of a resistor (R1 in the attached schematic). I do add an inline 470Ohm resistor on the target devices.
It works great at the turbo speeds.
I do not burn a bootloader on any of my designs (apart from setting the fuses) - I do not think the extra effort and cost adding a USB to Serial chip is justified for just uploading. I add an I2C LCD panel (sometimes only temporarily) to facilitate debugging.
I tried the CH340E -might be a long shot, but do you know any differences between the CH330N and CH340E?
I have pondered if making my own adapter might be the way to go, at least while developing my other board(s). I saw a nice idea somewhere on an USB-C to UPDI adapter, that had a switch to change it to normal serial, and another to switch from 3v3 to 5, depending on your need. Might try to make one of those.
Though, for starters, as you pointed out, the specifications for how you connect TX and RX together, to make the single UPDI line has changed some over time.
I read up on SpenceKonde's guide on JTAG2UPDI, and it seems like the design idea I found used the first example from his list of alternatives.
On the other hand it also seems like they included the 470 Ohm resistor in the adapter. But wouldn't that be an issue if you get your hands on a board to program though UPDI that already has an inline resistor?
So far my understanding says this is the difference between an normal serial, and UPDI adapter. Or are there more important differences?
I am not familiar with the 340E variant since my sources only have the 340G variant available. Also when I got my 330N chips the 340G was not available.
As far as I am aware they are functionally the same. The 330 has only the RTS signal while the 340 features a full compliment (CTS, DTR etc). Also the 330 has a built in crystal and needs no additional external components like crystal with caps (which the 340G requires).
I specifically do not include the 470 Ohm resistor on the adaptor but on each of my individual circuit boards where it provides some inline resistance if I screw up with the pin connections (for whatever that may be worth).
I also do not think the 1.5K resistor (R2 in your diagram) should be there (at least not according to the diagrams in the SpenceKonde guide).
This is the suggested layout I use with a 470 Ohm resistor on the target board.
No internal resistor on adapter.
Yes resistor on target >= 100 ohms and not more than a few k.
-------------------- To Target device
DTR| __________________
No resistor? Rx |--------------,------------------| UPDI----\/\/\/------>
Are you sure? Tx |----|<|------` .--------| Gnd > 100
This is rare! Vcc|---------------------------------| Vcc < 2.2k
CTS| .` |__________________ Resistor of around a few hundred to a few k
Gnd|--------------------'
--------------------
If you got it to work without already, then I guess you are right about the 1.5k resistor. Though if you go by the first option in his guide, you have it here;
-------------------- To Target device
DTR| __________________
internal Rx |--------------,------------------| UPDI---\/\/---------->
Tx---/\/\/\---Tx |-------|<|---' .--------| Gnd 470 ohm (100 ~ 1k)
resistor Vcc|---------------------------------| Vcc
typ 1-2k CTS| .` |__________________
Gnd|--------------------' If you make a 3-pin connector, use this pinout
--------------------
I figure the author of the guide I follower had picked 1.5k because SpenceKonde say 1-2k internal resistor in the example above.
Then again he has options further down where there is no resistor on the adapter side, so I do suppose it might be unnecessary
The circuit I currently use in my working programmer uses a resistor in place of the diode. The diagram in post #11 shows I am using a 4.7K resistor. Apart from that it is the same as the configuration as in post #13 ( ). This works fine so I did not try to replace the resistor with a diode, if it works ..... etc .
At some stage I may manufacture a new one using the diode (I do have all the components and the board already designed) and see how that performs.
The resistor value is not critical, specifications give quite a range, with 470 Ohm somewhere at the lower end. Having two 470 Ohm resistors in line should not be a problem. It's a signal line, which generally can handle quite high resistance.
Check the datasheet of the ATtiny for the exact value range as recommended by the manufacturer.