#avr Logs

Feb 13 2022

#avr Calendar

10:08 AM rue_bed2: # means "that becomes"
10:16 AM rue_bed2: what are you making?
01:03 PM joebobjoe: I have a question about SPI programming
01:03 PM joebobjoe: in the datasheet it says "Power-up sequence: apply power between VCC and GND while RESET and SCK are set to “0”"
01:04 PM joebobjoe: well it says inverted RESET
01:04 PM joebobjoe: RESET with a bar over it
01:05 PM joebobjoe: does that mean RESET pin my be left floating?
01:05 PM joebobjoe: and SCK grounded?
01:06 PM twnqx: no, bar over it meand "active low"
01:07 PM joebobjoe: when it says RESET (with bar) must be set to "0" does that mean 0 volts?
01:07 PM twnqx: ground, yes
01:07 PM twnqx: RESET with bar just means that the signal is active low, 0 always is 0 (not inverted)
01:07 PM joebobjoe: wouldn't that mean RESET (with bar) is "true"?
01:07 PM twnqx: basically, you program the chip as an SPI slave ehile holding it in reset
01:07 PM twnqx: yes
01:07 PM joebobjoe: oh ok
01:07 PM twnqx: you need it in reset to program it
01:07 PM joebobjoe: I always though 0 meant false and 1 meant true
01:08 PM twnqx: that's in logic, not electronics
01:08 PM twnqx: there 0 means gnd and 1 vcc
01:08 PM joebobjoe: oh ok
01:08 PM qu1j0t3: (and the bar means NOT)
01:09 PM twnqx: that... might be confusing
01:09 PM joebobjoe: at the sent it says "set RESET to "1"" (reset with a bar over )
01:09 PM qu1j0t3: sure
01:09 PM qu1j0t3: :)
01:09 PM joebobjoe: so does that mean set RESET (with bar) to 1 volts?
01:09 PM twnqx: no, to vcc
01:10 PM twnqx: well.. to a voltage, that according to the data sheet will be read as "logic one", but VCC is save.
01:10 PM joebobjoe: huh?
01:10 PM joebobjoe: logic one for RESET (with bar) means true
01:10 PM twnqx: no.
01:10 PM joebobjoe: https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf page 152
01:10 PM twnqx: logic LEVEL one, i should have been more precise
01:11 PM joebobjoe: logic level 1 does not mean true?
01:11 PM twnqx: not relative to the signal interpretation, absolute.
01:11 PM joebobjoe: ok
01:11 PM joebobjoe: question about that page in the datasheet
01:11 PM twnqx: the bar changes the interpretation
01:11 PM joebobjoe: steps 7 and 8
01:12 PM joebobjoe: "At the end of the programming session, RESET can be set high to commence normal operation."
01:12 PM joebobjoe: RESET has bar
01:12 PM joebobjoe: what happens if I set high to commence normal operation, but then my program immediately outputs low to RESET (with bar)
01:12 PM joebobjoe: wouldn't that cuase a short
01:13 PM twnqx: what do you mean, "set high"
01:14 PM twnqx: if you have two outputs connected to it, you need an arbitration mechanism
01:14 PM joebobjoe: RESET (with bar) sorry
01:14 PM twnqx: ignore that
01:14 PM joebobjoe: huh?
01:14 PM twnqx: the bar
01:14 PM twnqx: it's irrelevant mostly
01:15 PM joebobjoe: what I'm saying is
01:15 PM twnqx: it just tells you "put 0 here to put chip in reset"
01:15 PM twnqx: and you can only control it from outside
01:15 PM joebobjoe: it is telling me to set !RESET to logic level high to end programming
01:15 PM joebobjoe: and then it immediately commences the program?
01:15 PM twnqx: from your external programmer, yes
01:15 PM twnqx: yes
01:15 PM joebobjoe: so
01:16 PM joebobjoe: so
01:16 PM twnqx: do you know about concepts such as "open drain" drivers?
01:16 PM joebobjoe: ok where does it say I have to use an open drain on the data sheet
01:17 PM joebobjoe: is !RESET held high by the chip?
01:17 PM joebobjoe: pulled up*
01:17 PM twnqx: no
01:17 PM joebobjoe: then how would the chip know to end programming
01:18 PM twnqx: let's take a step back from your questions
01:18 PM joebobjoe: doesn't !RESET have to be pulled high by the chip?
01:18 PM twnqx: what... do you want to do?
01:18 PM joebobjoe: otherwise if it weren't tied to Vcc it could reset the chip randomly
01:18 PM joebobjoe: learn how to program my AVR with a raspberry pi SPI
01:18 PM twnqx: yes, that's why you normally add a pull-up resistor externally
01:19 PM twnqx: not doing so can indeed cause stability issues
01:19 PM joebobjoe: wait
01:19 PM joebobjoe: my digispark doesn't have that https://s3.amazonaws.com/digistump-resources/files/97a1bb28_DigisparkSchematic.pdf
01:19 PM twnqx: yeah
01:19 PM twnqx: most of the time you're lucky
01:19 PM twnqx: and get away with saving another 0.5ct
01:20 PM exp: i think it does depend on the chip too
01:20 PM exp: newer avrs seem to have much weaker pull-ups
01:20 PM exp: as weak as 100k
01:20 PM joebobjoe: is that good or bad
01:20 PM twnqx: good for power (while being in reset), bad for stability :P
01:20 PM exp: neither really, just reinforces that you should add a position for an external pull-up
01:20 PM twnqx: i have a circuit where i put a 100k too
01:20 PM exp: i also have external pull-ups
01:21 PM twnqx: if i connect a wire to the reset pin, touching the wire (not even the metal) can cause a reset
01:22 PM joebobjoe: so right below where it says set !RESET high to commence normal operation
01:22 PM joebobjoe: it says power off sequence if needed it set !RESET to "1" and turn Vcc power off
01:22 PM joebobjoe: does that mean there is no way to turn off the programmer without briefly starting the program?
01:23 PM exp: the answer to that is quite complex
01:23 PM exp: there are many ways, but it is never something you should rely upon
01:24 PM joebobjoe: well I need to know how spi programming works in order to writes programs that will be written via spi
01:24 PM twnqx: nah
01:24 PM exp: you should not be concerned about your program accidentally starting
01:24 PM joebobjoe: I shouldn't?
01:24 PM twnqx: no
01:24 PM twnqx: so it starts, what happens?
01:25 PM exp: your firmware should be resilient to such behaviour, as it's a common effect
01:25 PM joebobjoe: ok
01:27 PM joebobjoe: so basically the datasheet is saying you need to pull up !RESET to end programming
01:27 PM joebobjoe: and when you do that your program will start
01:27 PM exp: if you read the datasheet of your part it should explain how its reset system works
01:28 PM joebobjoe: ok
01:28 PM joebobjoe: I'll read the reset section
01:28 PM exp: but the long and short of it is, when no reset source is active, it starts executing code
01:28 PM joebobjoe: wait so it pulls it up internally?
01:28 PM joebobjoe: I don't need a pull up?
01:28 PM joebobjoe: I thought you said I needed one for stability
01:28 PM exp: you should have a space for an external pull-up, to decrease its sensitivity
01:28 PM exp: it's good design practice
01:29 PM joebobjoe: what happens if my program disables the reset pin, is it a danger to an SPI programmer?
01:29 PM joebobjoe: could it cuase a short
01:29 PM exp: the internal pull-up will be weak and as twnqx points out you can easily pull it low enough to trigger a reset
01:29 PM twnqx: "disables the reset pin"?
01:29 PM exp: joebobjoe: i am not sure if any parts have that functionality
01:29 PM joebobjoe: ok but when the reset pin is used for reset it has its internal pull up enabled
01:29 PM twnqx: if you fuse it away you can't program it with SPI any more
01:30 PM * twnqx did that by accident
01:30 PM joebobjoe: twnqx: yea but couldn't it damage an SPI programmer
01:30 PM twnqx: you should have circuits in palce to prevent that
01:30 PM joebobjoe: because the SPI programmer might try to open drain the reset pin
01:30 PM twnqx: like.. a series resistor that limits the current
01:30 PM joebobjoe: when it is being output high
01:30 PM joebobjoe: wait I've only ever heard of pull ups and pull downs before but now there are current protecting resistors, too?
01:31 PM joebobjoe: is there anything else I need?
01:31 PM twnqx: it's whatever you want
01:31 PM twnqx: you only need them when you are scared things might be wonky
01:31 PM exp: there are many many things 'needed'
01:31 PM joebobjoe: yea but that's a big gotchya though
01:31 PM exp: there are no trivially correct solutions to anything
01:31 PM exp: everything you do is trading off one thing for many others
01:32 PM exp: it's a frustrating answer i appreciate, but there's a lot to learn about this
01:33 PM twnqx: i guess that's why most people just buy a programmer :P
01:33 PM joebobjoe: yea but then what's the purpose of all these development boards like raspberry pi computer in your hand with gpio if you can't use them
01:33 PM joebobjoe: the datasheet should tell me everything I need to know to make a programmer
01:33 PM exp: it does
01:33 PM twnqx: to use them for more suitabe things
01:34 PM joebobjoe: if you read all 1000 pages
01:34 PM twnqx: well sure
01:34 PM exp: and, you can use them just fine, but it's also easy to break them
01:34 PM twnqx: imagine, i am working with a cpu that has has a 2600 pages datasheet
01:34 PM twnqx: and i keep finding details that make me wonder how my hardware even works
01:34 PM * exp has spent several days routing a pcb
01:35 PM exp: how i wish for 2600 page datasheets :D
01:35 PM joebobjoe: ok fair enough
01:35 PM * twnqx has spent days playing TIS-100
01:35 PM twnqx: :D
01:35 PM exp: god i wish i could game these days
01:35 PM twnqx: one should build a TIS-100 with avrs.
01:35 PM twnqx: those "CPUs" have maybe 0.1% of an avrs capabilities...
01:35 PM exp: the worst thing about coming to an end of a project
01:36 PM exp: is summarising the things you did which failed, or you failed to implement properly
01:36 PM exp: and immediately knowing you've weeks of work ahead just to revise it to where you're happy
01:36 PM twnqx: heh
01:36 PM exp: i made a symmetric pcb for example
01:36 PM exp: so it could be installed in both orientations
01:36 PM exp: this turned out to be a huge pain in the arse and took up way too much space
01:37 PM exp: 's all tradeoffs, now i gotta spend more on manufacturing but i'll actually have space to route shit :-p
01:43 PM joebobjoe: I wish they woul have made it so you can complete programming without having to unset !RESET
01:43 PM joebobjoe: then you could just power it off and not have the program start
01:44 PM exp: that most likely will work, but there are other electrical issues
01:44 PM exp: you should not apply > Vcc+0.3v to most pins on most ICs
01:44 PM joebobjoe: the digispark runs at 5 volts but when I connect it via spi pins to the pi I'm gonna power it at 3.3 volts off the pi for programming
01:45 PM exp: it may be that the ~RESET does need to be asserted but i'd need to check datasheet of the part
01:45 PM exp: i'm no AVR expert
01:46 PM joebobjoe: what do you mean?
01:47 PM joebobjoe: RESET needs to be asserted to end programming
01:47 PM joebobjoe: ~RESET to begin it
01:48 PM exp: i mean i don't know if that is strictly required to end it
01:48 PM exp: i'm no expert
01:48 PM joebobjoe: then the datasheet should be more clear
01:49 PM joebobjoe: it says there is a power off sequence where you set ~RESET to 1 then turn off Vcc power
01:49 PM joebobjoe: why would it say to do that if there wasn't a reason
01:49 PM twnqx: just assume none of us did read it
01:49 PM twnqx: even if you linked it
01:50 PM joebobjoe: ok
01:50 PM joebobjoe: can I do serial programming at any point? or do I have to power off the chip first
01:50 PM joebobjoe: oh maybe it says that because SCK has to be held low
01:50 PM joebobjoe: and you don't want to short your program
01:51 PM joebobjoe: that's why it says this is the "recommended sequence"
01:51 PM joebobjoe: this is gonna be fun
01:51 PM joebobjoe: I'm gonna make an spi programmer!
02:13 PM masoudd: Please tell him to not drive the spi signals straight from the rpi gpio pins. This is why usbtinyisp from adafruit uses a 74AHC125N: https://cdn-learn.adafruit.com/assets/assets/000/010/326/original/usbtinyisp2sch.png
02:14 PM twnqx: well, he explicitly powers it from the rpi, so he should be save from that
02:14 PM masoudd: I'm pretty sure rpi gpio pins are on 3.3v level.
02:15 PM twnqx: yeah, he wants to run the avr with 3.3V
02:15 PM twnqx: not an ISP
02:16 PM masoudd: and those gpio pins can sink 0.5mA max. That's just a recipe for a bricked rspi
02:16 PM twnqx: never looked at that...
02:17 PM twnqx: to me a raspi is a low-end low-power server to drop in some corner
02:18 PM masoudd: It is fast enough to speak a lot of slow protocols with the gpio pins just by bitbanging it in a python script
02:18 PM masoudd: great learning tool but use a buffer. Those gpio pins can not sink any meaningful current
02:23 PM qu1j0t3: huh. they probably should make more noise about the low current gpio
02:26 PM qu1j0t3: why would you do that on a device that's going to have a squillion inexperienced users...
02:26 PM qu1j0t3: they could have put buffers on the board ._.
02:27 PM * qu1j0t3 has to bitbang SPI on this MCU because the hardware module is not very good lol
02:33 PM qu1j0t3: joebobjoe: masoudd raised the point that the gpio can only sink 0.5mA so you might want to confirm that's not going to be a problem into your load
02:34 PM twnqx: (the raspi's gpio)
02:34 PM qu1j0t3: joebobjoe: (& that you can use a buffer e.g. 74ahc125n)
02:35 PM twnqx: hm, i can't wrap my head about this tis-100 programming solution, and i wanted it to be the last for today... an hour ago
02:35 PM twnqx: some are... hard
02:57 PM joebobjoe: qu1j0t3: wait the raspberry pi can only sink 0.5 mA? can't the attiny it is programming sink way more? like 40 mA?
02:57 PM joebobjoe: gah I just realized reset is disabled from the factory for my digispark... so I guess I will have to figure out what the process is of using micronucleus without arduino
02:58 PM twnqx: or update the fuse
02:58 PM joebobjoe: don't I need a HVP to do that
02:58 PM qu1j0t3: joebobjoe: I didn't check primary sources but that's what masoudd said
02:58 PM qu1j0t3: joebobjoe: which is alarming i agree
03:00 PM joebobjoe: wait if all the rpi gpio sees are the ports on the avr... running at 3.3 volts wouldn't the current only be like 66 uA
03:00 PM joebobjoe: if the pull up in the avr is 50 kohm
03:00 PM twnqx: it should be pretty low, yes
03:01 PM joebobjoe: can I really disable reset without hvp and only self programming?
03:02 PM joebobjoe: I've decided I'm just gonna program the digispark with the bootloader
03:03 PM qu1j0t3: joebobjoe: (re current, yeah, just a good-to-know thing)
03:03 PM joebobjoe: and use the rpi simply as a serial connection since i can't get that to work over usb
03:04 PM joebobjoe: for getting a serial console to the avr how should I connect it to the rpi if I don't need programming?
03:04 PM joebobjoe: i2c or spi?
03:04 PM joebobjoe: or uart whatever it's called
03:20 PM masoudd: I'm not an expert or anything. 0.5mA is what I remember. Do your own research. I just don't want you to fry the rpi. That's all
03:25 PM masoudd: my experience is limited to rpi 3 B I worked with a few years ago
04:33 PM specing_ is now known as specing
11:21 PM rue_bed2: asynchronous serial, ttl