#avr Logs

Feb 11 2022

#avr Calendar

04:33 AM specing_ is now known as specing
06:21 AM masoudd: hey guys. I am in a pickle. I have a attiny2313 that I mistakenly set the fuses to use external clock. Now I don't have an external clock. What can I do? I have a usbtinyisp and some other working avr microcontrollers that I can program. Can I program one of them to put out a clock and use that as a clock source?
06:23 AM LeoNerd: Yah, any decent square-wave output should be fine
06:23 AM LeoNerd: E.g. just set one of the PWM controllers to generate a fast pulse
06:23 AM LeoNerd: Provided you only talk ISP no faster than 1/4th of the frequency of that clock, the exact speed isn't critical
06:27 AM masoudd: Thanks. I'll give a try. Now what do I connect to the XTAL1 and XTAL2 pins? attach the square wave to XTAL1 and ground to XTAL2?
06:47 AM LeoNerd: For "external clock" it's expecting a squarewave in on one of the pins and nothing on the other. You'll have to check the datasheet for what it wants. I suspect it might be xtal1 but do check
08:13 AM qu1j0t3: just set up a crystal :)
08:15 AM exp: won't work if it's set to clock
08:15 AM exp: some of the avrs are annoyingly fused that way
08:18 AM qu1j0t3: ah ok.
08:18 AM qu1j0t3: i should have inferred that from what LeoNerd said
08:19 AM exp: i think 'modern' (i'm no expert on microchip's range) parts now have internal oscillators and all the config is set on init
08:19 AM exp: at least the xmegas, some of the newer tinys etc seem that way
08:19 AM exp: it may just be a segment of their offerings though
08:20 AM LeoNerd: Yeah; all the newer chips are impossible to brick this way. The clock selection is software controlled
08:20 AM LeoNerd: I like them. I don't use the older chips any more
08:20 AM exp: LeoNerd: please send me some xmega384s then ta ;)
08:20 AM twnqx: is there a replacement for the megau32 then?
08:20 AM twnqx: haven't worked with avrs for soem time..
08:21 AM LeoNerd: Ah; yeah there's no UPDI-talking USB-capable chips, last time I looked :/
08:21 AM exp: is there a substantial difference between PDI and UPDI for these purposes?
08:22 AM exp: i've had no problems debugging xmegas using usb and pdi
08:22 AM LeoNerd: i've never used PDI
08:22 AM LeoNerd: You can talk UPDI from any ol' USB-UART widget, like a cheap CP2102
08:22 AM exp: one dedicated pin and dual mode ~RESET
08:22 AM LeoNerd: whereas PDI needs special dedicated harwdare
08:23 AM exp: oh i guess, i just bought an -ice as they're not crazy cash
09:39 AM masoudd: success!! Thank you very much
09:39 AM exp: masoudd: congratulations
09:40 AM masoudd: needed to give -B 16kHz to avrdude to go slow :)
10:16 AM joebobjoe: what is the purpose of diodes D1 and D2 in https://s3.amazonaws.com/digistump-resources/files/97a1bb28_DigisparkSchematic.pdf ?
10:20 AM twnqx: ensuring the voltage doesn't go beyond 3.6V (it would go to 5V, potentially damaging other USB devices)
11:07 AM joebobjoe: wait so
11:08 AM joebobjoe: what happens if I use PB3/PB4 and set it as a high output?
11:08 AM joebobjoe: I'll create a short circuit?
11:09 AM joebobjoe: I mean the pin is at 5 V when output high
11:10 AM joebobjoe: doesn't that D1 or D2 create a short with GND when the pins are outputting 5 V?
11:30 AM twnqx: no, those are zener diodes
11:31 AM twnqx: they clamp to 3.6V, and the current is limited by the resistors between the pins and the zeners
11:36 AM joebobjoe: ohhh
11:36 AM joebobjoe: right I didn't see the resistors
11:37 AM joebobjoe: gawd I'm so bad at electronics
11:37 AM twnqx: also note that those diodes ar reversed - a "normal", non-zener diode would remove negative voltages with this direction
11:41 AM joebobjoe: huh?
11:41 AM joebobjoe: you mean the drawing is wrong?
11:42 AM twnqx: no
11:43 AM twnqx: it's just that your interpretation of creating a short circuit would require the opposite direction of the diodes
11:43 AM twnqx: regardless of zener or not, normal diodes would just not do anything there
12:07 PM joebobjoe: twnqx: is it safe to use those pins
12:08 PM joebobjoe: as GPIO
12:08 PM joebobjoe: PB3 and PB4 https://s3.amazonaws.com/digistump-resources/files/97a1bb28_DigisparkSchematic.pdf
12:08 PM joebobjoe: do those 66.5 kohm resistor mess with them
12:09 PM twnqx: that's not kOhm... that's ohm
12:09 PM joebobjoe: oh wow
12:11 PM joebobjoe: so if PB3 or PB4 pins output 5 V that's 255 mA draw across tha resistor?
12:11 PM masoudd: I don't think they mess with anything. those resistors would have 5 - 3.6 = 1.4 volts on them. So they would draw 1.4/66.5 = 21mA at most. You can use those pins as normal. But know that you can draw 21mA less from them
12:11 PM joebobjoe: from 5 V down to 3.3 V
12:11 PM joebobjoe: ah ok
12:12 PM joebobjoe: but doesn't attiny85 only guarantee 5 mA?
12:12 PM masoudd: hmm
12:12 PM twnqx: in that schematic
12:12 PM joebobjoe: oh it says 40 mA
12:12 PM twnqx: they are meant for software-based 1.5mbit USB
12:13 PM masoudd: Are you programming it using the arduino IDE? or do you want to program the thing avrdude style?
12:13 PM joebobjoe: avrdude
12:13 PM joebobjoe: I'm done with arduino it sucks
12:13 PM joebobjoe: the serial console doesn't work with digicdc
12:14 PM joebobjoe: I can't get a serial console for my programs over usb in arduino
12:14 PM twnqx: uh...
12:14 PM masoudd: Just backup the stock firmware on it somewhere in case you want to go back to arduino way
12:14 PM twnqx: usb.. on those things? with serial console?
12:14 PM twnqx: good luck
12:15 PM joebobjoe: I mean it used to work
12:15 PM joebobjoe: but not anymore
12:15 PM joebobjoe: I read in one comment on one issue it was the macos driver that changed
12:15 PM joebobjoe: and apparently a cdc device is supposed to be usb normal speed
12:16 PM joebobjoe: and the digispark is only low speed usb
12:16 PM twnqx: yes, and it won't ever do more...
12:16 PM joebobjoe: and the macos driver has changed
12:16 PM joebobjoe: so now I need to learn how to program it with avr dude
12:16 PM joebobjoe: what do I lose by not using the arduino ecosystem anymore?
12:16 PM joebobjoe: I'm not to micros
12:16 PM masoudd: You'd need a seperate avr programmer for starters
12:18 PM masoudd: just to make sure you're working with this thing right? http://digistump.com/products/1
12:18 PM joebobjoe: yup
12:19 PM joebobjoe: the usb is useless except for programming
12:19 PM joebobjoe: so I need to program it somehow where I can get serial back for debugging
12:19 PM joebobjoe: all I have is a raspberry pi
12:19 PM joebobjoe: I was thinking about using it as an SPI programming for the attiny85 on the digispark
12:19 PM joebobjoe: or maybe I can just use it as a serial console relay or something?
12:20 PM masoudd: rpi doing SPI is doable I think. have you seen this? https://arduino.stackexchange.com/questions/41535/digispark-serial-port-communication
12:20 PM joebobjoe: I just need to get some kind of console to the digispark for debugging
12:20 PM joebobjoe: masoudd: thanks
12:20 PM masoudd: And this: http://digistump.com/wiki/digispark/tutorials/debugging
12:20 PM masoudd: Just want to make sure you can't solve the problem before burning any bridges so to speak :)
12:20 PM joebobjoe: they say the digiusb is deprecated elsewhere in the wiki
12:20 PM joebobjoe: and do use digicdc
12:20 PM joebobjoe: but that doesnt work
12:21 PM joebobjoe: I'm just done with these pod digispark I just want to turn it into an attiny85
12:21 PM joebobjoe: the company doens't support the thing no more
12:21 PM masoudd: That's fair
12:23 PM masoudd: The SPI pins are routed to the JP3 (MISO,MOSI, NRES and SCK). So you can do that. Look up how to do SPI with rpi GPIO pins. I'm sure someone else has already done that
12:27 PM joebobjoe: wait when people say "serial" connection do they mean spi?
12:27 PM joebobjoe: or i2c?
12:27 PM joebobjoe: or some other connection
12:27 PM masoudd: those are both serial
12:27 PM masoudd: vs parallel
12:27 PM masoudd: This looks promising: https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins
12:28 PM twnqx: or rs232 (with either native or ttl/cmos levels), or usb, or pcie, or I3C, single wire...
12:28 PM joebobjoe: wait so
12:29 PM twnqx: but normally i'd interprete it as rs232 at any levels
12:29 PM joebobjoe: I've decided I will program the board with avrdude/micronucleus or whatever
12:29 PM joebobjoe: but I just need a serial monitor
12:29 PM joebobjoe: for my program to talk to me with
12:29 PM joebobjoe: I need to read the temperatures to calibrate the device
12:30 PM twnqx: i'd get a ft232 or pl2303 breakout (for 5V) and use "serial" serial
12:30 PM joebobjoe: twnqx: is that rs232? spi? i2c? one wire?
12:30 PM joebobjoe: how does it interface with the attiny85
12:30 PM twnqx: thos are usb-to-rs232 converters
12:30 PM twnqx: and would use rs232-like communication (tx & rx only)
12:31 PM joebobjoe: ok and there is an rs232 library for the attiny85?
12:31 PM twnqx: wellllllll
12:31 PM twnqx: i don't know, i don't really use libraries
12:31 PM joebobjoe: oh ok
12:31 PM joebobjoe: it looks like there are a bunch of different kind of of cables
12:31 PM joebobjoe: http://www.prolific.com.tw/US/ShowProduct.aspx?pcid=41
12:32 PM twnqx: prolific makes the IC
12:32 PM twnqx: check amazon or so
12:33 PM joebobjoe: what type of driver should I get VCP, CDC, or HID?
12:33 PM twnqx: up to you... linux just works
12:33 PM twnqx: probably VCP
12:33 PM twnqx: and surely not HID
12:34 PM joebobjoe: it says the CDC driver is implemented natively by most OSes http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=416&pcid=41
12:34 PM joebobjoe: VCP it doesn't say anything like that I don't even know what VCP is
12:35 PM twnqx: virtual com port
12:35 PM twnqx: dos/windows terminology
12:35 PM joebobjoe: is it natively supported by mac?
12:35 PM joebobjoe: I'm developing on mac
12:37 PM joebobjoe: ah https://www.amazon.com/Communication-Connector-PL2303GS-Version-Compatible/dp/B09F6GZGX6/ref=sr_1_10?crid=1L2BYFPI0S1A6&keywords=PL2303GD&qid=1644603668&sprefix=pl2303gd%2Caps%2C181&sr=8-10&th=1
12:37 PM twnqx: i really don't know more about macs than that they have bad screens and are overly expensive
12:37 PM joebobjoe: bad screens?
12:37 PM joebobjoe: they have great screens
12:37 PM twnqx: mirrors.
12:37 PM joebobjoe: better color rendition duh
12:37 PM joebobjoe: jk
12:37 PM joebobjoe: they used to offer matte
12:40 PM masoudd: you can talk serial from the tiny85 to rpi I think
12:41 PM qu1j0t3: yes but it's not as much fun as it sounds
12:42 PM joebobjoe: on this page
12:42 PM joebobjoe: what is Tx/Rx? 0041
12:42 PM joebobjoe: sorry, http://www.prolific.com.tw/US/ShowProduct.aspx?pcid=41&showlevel=0041-0041
12:42 PM joebobjoe: what should I use to talk from the attiny85 to the rpi? uart, tx/rx, rs232, rs485, i2c, or spi?
12:43 PM masoudd: I must admit I haven't done anything related to serial protocols. rpi can do all of those. See what the tiny85 can do and go from there
12:44 PM masoudd: Tx= Transmission, Rx= Receive
12:44 PM joebobjoe: yea but what protocol is Tx/Rx?
12:45 PM joebobjoe: how does Tx/Rx relate to VCP?
12:45 PM twnqx: normally uart/rs232 minus the control pins
12:48 PM masoudd: I have used one of these before. But not for avr. I used it to talk from pc to an orangepi. https://www.amazon.com/HiLetgo-FT232RL-Converter-Adapter-Breakout/dp/B00IJXZQ7C/ref=sr_1_1?keywords=ftdi&qid=1644604273&rnid=2661599011&sr=8-1
12:49 PM joebobjoe: ok I have a question then
12:49 PM joebobjoe: back in arduino land for the digispark
12:50 PM joebobjoe: it exposed arduino functions
12:50 PM joebobjoe: and one of the objects it exposed was Serial
12:50 PM joebobjoe: if I used Serial.println("hi") in arduino
12:50 PM joebobjoe: what pins and what protocol does it use?
12:50 PM joebobjoe: maybe I can just use arduino libraries
12:52 PM masoudd: I think it speaks usb to the arduino IDE. the arduino IDE shows the messages in the serial window for you. But it's all in the usb connection
12:53 PM joebobjoe: nope lol
12:53 PM qu1j0t3: i did the same thing a few months ago. yeah it's bitbanged usb serial
12:53 PM qu1j0t3: it did not work well
12:53 PM joebobjoe: that's the digicdc.h example
12:53 PM qu1j0t3: there's softserial as well
12:53 PM joebobjoe: I don't know what the attinycore Serial() functions do in arduino
12:53 PM qu1j0t3: (alternatively)
12:54 PM joebobjoe: what protocol is that? uart?
12:54 PM joebobjoe: Tx/Rx?
12:54 PM qu1j0t3: there are no uarts on the chip
12:54 PM qu1j0t3: it's bit-banged rs232-ish
12:54 PM joebobjoe: kk
12:54 PM qu1j0t3: i think i got that to work okay. the bitbanged usb did not work at all for me
12:55 PM masoudd: it's a hack on top of another hack. Look at what they made this poor tiny85 do
12:55 PM qu1j0t3: yeah, a friend said they use the other Attiny chips which have real uarts, easier
12:56 PM qu1j0t3: not sure they're obtainable now, they were early victims of supply issues iirc
12:56 PM joebobjoe: the spec for attiny85 says: "Using the USI Data Register in three-wire mode it is possible to implement a more compact and higher perfor- mance UART than by software, only."
12:59 PM LeoNerd: Ugh,, UART via USI is terrible.. primarily because the bit-order is wrong, so you end up having to reverse it
12:59 PM LeoNerd: Whenever I've wanted UART on the tiny85 I just bitbang it in pure software
12:59 PM LeoNerd: That said these days I'd use a tiny412, which already has a real USART peripheral in the same pincount
12:59 PM joebobjoe: ok thanks
01:01 PM masoudd: tiny412 has no DIP packages?
01:01 PM LeoNerd: None of the new tinies do, no. DIPs are giant
01:02 PM qu1j0t3: joebobjoe: Yes, there is an appnote about that
01:02 PM LeoNerd: If you really want it DIP you can mount it on one of those breakout PCBs
01:02 PM qu1j0t3: ^
01:02 PM masoudd: Can you solder in in that pcb with a regular soldering iron?
01:03 PM LeoNerd: Can I? I do it all the time ;)
01:03 PM qu1j0t3: ^^
01:03 PM masoudd: nice :) I never tried it
01:04 PM LeoNerd: They're only SOIC, they have exposed gullwing-style legs. Easy enough by hand
01:04 PM LeoNerd: They're not underneath-pads like a QFN has
01:09 PM exp: yeah even QFN is doable with cheap soldering gear if the footprints are right
01:09 PM exp: it's not as difficult as some people make out
01:09 PM exp: having some sort of microscope or magnifier is very very useful though
02:09 PM joebobjoe: can anyone help me understand this formula
02:09 PM joebobjoe: https://github.com/digistump/DigisparkArduinoIntegration/blob/master/libraries/DigisparkTinySoftPwm/examples/TinySoftPwmDemo/TinySoftPwmDemo.ino
02:09 PM joebobjoe: The PWM frequency = 128 x 60 # 7.7 ms -> F # 130Hz
02:09 PM joebobjoe: what does # mean
02:11 PM joebobjoe: if TinySoftPwm_Process() is called every 60 us then wouldn't the PWM frequency be 1/0.00006/2
02:11 PM joebobjoe: 8333 Hz?
02:17 PM joebobjoe: ugh I can't use TinySoftPWm.h
02:18 PM joebobjoe: I think it uses the pin in an output mode
02:18 PM joebobjoe: but I need open drain pwm
02:21 PM nohit: smash that thing with a hammer and buy a breadboard, few different avrs, programmer and few other components and start reading datasheets. that Arduino stuff is garbage
03:15 PM joebobjoe: nohit: roger that