#avr Logs

Apr 11 2020

#avr Calendar

09:38 AM Smidge204_: 80 bytes of code to convert an ASCII string (e.g. "2B") into an 8-bit value (e.g. 0x2B). I wonder if there's room for optimization... :D
09:44 AM Thrashbarg: there's *always* room for optimisation lol
10:46 AM rue_bed: 8!?
10:46 AM rue_bed: 10!?
10:46 AM rue_bed: 80!?
10:46 AM rue_bed: 80 how tf did you take 80 bytes for that?
11:01 AM Smidge204_: Bound checking
11:04 AM Smidge204_: I certainly could cut this down a bit, thinking about it. I don't need to isolate the high nybble to check the bounds separately
11:32 AM Thrashbarg: Smidge204_: what's the method you're using?
11:36 AM Smidge204_: Two bytes become two nybbles, First check if the byte is within bounds based ont he ASCII value, then check if it's 0-9 or A-F. I just use the low nybble of the ASCII value directly for 0-9, or add 9 if it's A-F
11:38 AM Thrashbarg: hmmm
11:40 AM Smidge204_: I can pastebin it if you want to take a look
11:40 AM Thrashbarg: when I'm converting numbers I usually shift the accumulator by the base (10, 16, etc) then add the incoming nybble to it
11:41 AM Thrashbarg: sure
11:41 AM Smidge204_: This is an ASCII string representing a hex value, so it's not a straightforward based conversion
11:43 AM Thrashbarg: that's what I mean though. It's base 16 so you'd only need to shift the accumulator by 4 bits (easy on an AVR with the swap op-code) and add the incoming value to the lower 4 zeros of the accumulator
11:43 AM Smidge204_: It's not base 16
11:43 AM Thrashbarg: hex is base 16?
11:43 AM Smidge204_: HEx is, AScii is not
11:44 AM Smidge204_: one sec
11:44 AM Thrashbarg: I see what you mean, but you're already converting from ASCII to hex
11:44 AM Thrashbarg: with the 0-9 and add 9 thing
11:44 AM Smidge204_: right but by that point the conversion is done
11:45 AM Smidge204_: https://pastebin.com/KSdqYLs1
11:47 AM Thrashbarg: yeah I see what you're doing
11:52 AM Smidge204_: I suppose one fancy thing I could try is using one of the cutom look-up tables. Gonna read up on that
11:53 AM rue_mohr: I liked how the apple IIe basic rom did it
11:53 AM rue_mohr: cant remember hwo they did error checking tho
11:54 AM Thrashbarg: there's a great 8080/Z80 routine that outputs a 16-bit register as a decimal number using recursion
11:55 AM rue_mohr: basically, subtract 30, and if your answer is more than 16, subtract another 6
11:55 AM Thrashbarg: yeah
11:55 AM Thrashbarg: https://wikiti.brandonw.net/index.php?title=Z80_Routines:Other:DispHL
11:55 AM rue_mohr: more than 15
11:55 AM rue_mohr: heh
11:56 AM Smidge204_: yay recursion
11:56 AM Thrashbarg: hmm not *technically* recursion, just a neat optimisation
11:57 AM rue_mohr: #define ASCNibToBin(A) (((A)>'9')?((A)-'7'):((A)-'0'))
11:57 AM Smidge204_: I'm reminded of the bogobogosort
11:57 AM rue_mohr: but lacks the error check
11:58 AM Thrashbarg: ouch I'd better sleep
11:58 AM Thrashbarg: Sun 12 Apr 02:27:47 ACST 2020
11:58 AM rue_mohr: #define BinToASCNib(B) (((B)&0x0F)<9?((B)&0x0F)+'0':((B)&0x0F)+'7')
02:37 PM Smidge204_: I'm running my USART test code through Atmel Studio's simulator. Stepping through I see all the registers set up, data goes into TX data register, but it doesn't seem to clock out? Doesn't work on the actual device either. Any ideas what I could be missing?
02:50 PM Smidge204_: Port pin wasn't configured as output :/
06:10 PM evidlo2: how complicated is programming an atmega32 over USB?
06:10 PM evidlo2: and can I simultaneously use the USB interface for serial printing?
06:13 PM cehteh: eh atmega32 doesnt even have usb to begin with, there are drivers to emulate it (v-usb etc) but implementing and usb stack with many profiles is gonna a bit of a stretch
06:13 PM evidlo2: atmega32u4
06:13 PM evidlo2: it has a hardware USB interface
06:13 PM cehteh: well thats something different then :D
06:13 PM cehteh: you saied atmega32
06:14 PM cehteh: for that check the datasheet, in theory one usb device can implement different profiles, like hid, serial, storage etc
06:15 PM evidlo2: I don't want to fiddle with the preloaded bootloader. Should I just use an external serial adapter?
06:15 PM cehteh: while programming it would be done by a bootloader 'usually' and having serial data and programming concurrently looks a bit wild
06:16 PM cehteh: what exactly do you want to do?
06:16 PM evidlo2: I basically want to build a custom Leonardo
06:17 PM evidlo2: so use the microusb port for flashing, and be able to open up a serial console to see what the program is printing
06:17 PM evidlo2: Leonardo also uses atmega32u4, so it should be possible somehow
06:17 PM cehteh: iirc once the bootloader is done you are free to use usb for whatever you need it
06:18 PM evidlo2: so how does programming over USB work if I its set up as a serial device. Are there some special control codes that put it in flashing mode?
06:18 PM cehteh: some bootloaders can even be programmed to be skipped, by some io line/switch or only activate when reset was pressed, pretty much anything is possible
06:19 PM evidlo2: do you know what the Leonardo does?
06:19 PM cehteh: its all the bootloader
06:20 PM evidlo2: https://arduino.stackexchange.com/questions/25346/upload-code-on-arduino-leonardo-using-command-line
06:20 PM cehteh: you could implement a bootloader where you enter programm code in morse code with a pushbutton ... or (on stm32) i frequently seen bootloaders which emulate storage devices, when you copy a firmware.bin or so there then it gets flashed
06:21 PM evidlo2: do you think the bootloader on the Leonardo is the one Microchip ships?
06:22 PM cehteh: no idea, prolly an arduino bootloader, from a glimpse on that text its only that it doesnt reset when you connect it
06:22 PM evidlo2: I guess I'll just put a 6 pin ISP header on there so I can always recover it, but just use USB for any serial debugging
06:22 PM cehteh: which is actually my prefered way, on normal arduinos i disable this reset thing
06:23 PM evidlo2: they say that it can be reset via software by connected at 1200 baud
06:23 PM cehteh: isnt that something your firmware has to implement?
06:23 PM evidlo2: no, I'm definitely not going to write a bootloader
06:23 PM cehteh: or the arduino stack .. they say
06:24 PM cehteh: well often bootloaders can easily be configured and have a lot options for that
06:24 PM cehteh: you dont need to write one, just read the docs
06:24 PM evidlo2: I'm just trying to make sure I have the right stuff on my board for rev1
06:25 PM cehteh: or when its a leonado then once you flash a arduino sketch it has this 1200 baud reset thingy compiled in or?
06:25 PM evidlo2: the arduino IDE supposedly does this for you
06:25 PM cehteh: most often i flash without bootloader .. saves some space :D
06:25 PM cehteh: isb programmign ftw
06:25 PM cehteh: isp
06:25 PM cehteh: well yeah i dont use arduino
06:25 PM evidlo2: that reminds me, do 10 pin usbasp programmers usually come without the TX/RX pins?
06:26 PM cehteh: dunno
06:26 PM cehteh: in theory yes, but its chinese clones
07:10 PM Smidge204_: evidlo2: The atmega32u4 comes from the factory with a bootloader to let you program it directly from the USB port
07:10 PM twnqx: optionally comes with a bootloader*
07:11 PM Smidge204_: "The 8bits mega AVR with USB interface devices are factory configured with a USB bootloader located in the on-chip flash boot section of the controller."
07:11 PM Smidge204_: http://ww1.microchip.com/downloads/en/DeviceDoc/doc7618.pdf
07:11 PM twnqx: still
07:12 PM twnqx: all of mine come without
07:12 PM Smidge204_: Dunno what to say about that
07:12 PM Smidge204_: Docs don't say anything about it being an add-option.
07:18 PM twnqx: http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf page 422 should clarify
07:19 PM twnqx: as in, the TQFP are not preprogrammed, the VQFN are
07:20 PM Smidge204_: Fucking weird
07:28 PM cehteh: also .. what you buy as hobbyist sometimes comes from dubious sources ... leftover preprogramemd stocks sometimes :D
07:29 PM twnqx: dunno, i usually buy from digikey or mouser
07:29 PM twnqx: as a hobbyist
07:29 PM cehteh: mkay
07:29 PM cehteh: i meant china/ebay etc
07:29 PM twnqx: i just ordered from china
07:29 PM twnqx: but i guess buying a few thousand sockets straight from manufacturer differs :P
07:29 PM Smidge204_: Always a dice roll buying from some backalley aliexpress vendor
07:30 PM cehteh: often enough its good
07:31 PM Smidge204_: Good enough, at least, that if you're just dicking around it's worth the risk for the proce anyway
07:31 PM Smidge204_: price*
07:32 PM twnqx: anyway, good night folks
08:08 PM Smidge204_: I can assert a pin high via internal pullup, use it as an output (chip select) , and still detect a pin change if something external pulls it low right?
08:11 PM Smidge204_: Actually I might be screwed either way, in terms of pin count
08:17 PM evidlo2: well I'll have an ISP header on there for initial flashing anyway, so I can use whatever bootloader
08:17 PM evidlo2: and I think I have to use a 3rd party bootloader anyway to get it working as a Leonardo target in Arduino
08:19 PM Smidge204_: evidlo2: Right; Point is what you want to do is not only possible but the chip is specifically designed to do that :)
10:13 PM Thrashbarg_ is now known as Thrashbarg
11:36 PM Santh_ is now known as Santh
11:52 PM day_ is now known as day