SD Card on a AVR128DB28 Part #359
-
I'm trying to get SD Card working on the AVR128DB28 part, not on the primary port (PA4-PA7) using voltage dividers, which works perfectly. I want to be able to use the multi-voltage I/O pins PC0-PC3, so that I can drop the divider network. Seems like this is a no-brainer use case....yet it doesn't work. I am using the "Listfiles" example, and when using the PC0-3 I use SPI.swap(SPI1_SWAP_DEFAULT); as the first line in setup{}. I see SClk on PC02 and CS on PC03 no problem. I ran this same example on one of Spence's AVR128DA64 boards, on both PA4-PA7 and on PC0-PC3 (using SPI.swap(1); ), which worked perfectly via the voltage divider network. I suppose that I can remove the jumper and add the 3.3V regulator, but I'm not sure what that would prove. I feel like I am missing something. But I thought I have chased everything down. Maybe the answer is "it doesn't do that". Almost seems like I'm missing something like an interrupt isn't being attached or something. I'm going with the voltage divider network for now via PA4-PA7, but using PC0-PC3 seems much cleaner. I do absolutely need the SD Card functionality, and I have plenty of I/O pins left over. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 18 replies
-
To use a second voltage on Port C you must both supply that voltage at chip pin 6 (complete with decoupling) and enable Multi-Voltage on the tools menu. If that doesn't help, maybe it's code issue? |
Beta Was this translation helpful? Give feedback.
-
I think what you're missing is what @mosqu-ito pointed out. The whole point of MVIO is that you supply a different voltage to the VDDIO2 pin - in this case 3.3v - and then you don't need to do any level shifting yourself - MVIO does it for you. I have AVR128DB64 boards assembled and ready to sell (with 5V Vdd reg and 3.3V VDDIO2 reg installed even - as well as versions with a software configurable fancypants regulator for VDDIO2, which lets you select 5v, 4v, 3.3, 3.1, 3.0, 2.5, or 1.8v (or 1.5 or 1.2 - but those are too low for MVIO to work). That regulator costs about as much as the AVR128DB64 itself, but my god it's specs are amazing. Minimum dropout is like... 0.1V or something? so you can get 5v on MVIO pins from a typical USB port as input, since these days those generally run a few tenths of a volt high for charging cellphones with crappy cables (max input voltage 6.5v though, and controlling it requires bringing pins close to it's Vin, so basically, you can only use it when running the AVR at 5v - I tied the enable line to PE6, and the two voltage select lines to PG6 and PG7. The only thing keeping me from listing it is that i need to write up a product description and... do you have any idea how painful that is going to be for this? There are TWENTY solder bridge jumpers on the damned board! (2 for each crystal to let you isolate the pins from the FTDI header, then 3 more to let you reroute it to the USART0 alternate pins, 5 to route the power, 1 additional one to provide power if you're using an external clock instead of a crystal (so you can crank these bad boys up to 48 MHz) and the 6 standard ones - RPB, VUP, CTS-to, autoreset enable - and one to tie the ESP-01M's strapping pin to PC7 (connected to Serial1 alt pins, plus PC6 for CHPD, and if that bridge is closed, PC7 for BOOT0 - so you could have it start up the ESP in FW update mode, with the AVR configured to act as a passthrough serial adapter, and update the firmware that way. Note that I have never tested the esp functionality in any way shape or form, so I don't even know if that works. Obviously that only has hope of working if the regulator is 3.3v for VDDIO2. ) |
Beta Was this translation helpful? Give feedback.
-
Yup...right on....the Business Card version I sent Spence (did you get it?, if not, I can send you another) has the voltage regulator on it, and that's failing. I also have Spence's AVR128DA64 which does work....although I haven't tried putting dropping a regulator on it (it has the spot for it, but it's jumped). I should have added in the above post that the output on PC2 is the same clock I saw on PA6, and PC3 has the same CS but both are at 3.3V. Which eliminates the correct assumption @mosqu-ito made based on the incomplete data I posted. I'm pretty confident it's not an MVIO problem. On Spence's product description, as I am an IT Architect, would you like some help creating that info? I am used to doing markdown, so that should work if you are directing to a GitHub project. I probably need a schematic at most and can get that cranked out. |
Beta Was this translation helpful? Give feedback.
-
Doesn't SPI1 live on those four pins normally without any remapping? And you say that port is operating at the desired voltage? So... you're simply having trouble moving from SPI0 to SPI1? |
Beta Was this translation helpful? Give feedback.
-
At first it wouldn't work for me on Port C either. SPI.swap(SPI1_SWAP_DEFAULT); SPI._uc_pinMOSI = PIN_PC0; SPI._uc_pinSCK = PIN_PC2; pinMode(PIN_PC3, OUTPUT); // SS SPI.begin(); |
Beta Was this translation helpful? Give feedback.
-
Okay, this is the dumbest shit ever. do you know what the ONLY GODDAMNED TIME THE PINS REFERENCED THERE ARE EVER USED IS? Guess... IT's when they make a single stupid pinMode call to set them as outputs in begin. That library needs a flamethrower. |
Beta Was this translation helpful? Give feedback.
-
Let me wrap this up a little better for @ITDiscovery and/or anyone else trying to use SPI on Port C under the current release, because last night I was typing with my thumbs in bed. If you make a minor (three lines, one character each) repair to a single file buried in the core, The tricky part is finding that one file. I use Linux. For me the file is located here: On my Linux installation at least, no special privileges are required to edit the file, though stashing away a backup before you start is always a good idea. You're looking for three lines (152, 153, 154) as described in closed issue #321. Although these have already been fixed by @ObviousInRetrospect for future release, they're not yet in the released version. Hence the need to go and patch it manually. Here are the three WRONG lines: You can confirm they're wrong by looking at page 18 of the datasheet. Here's what they SHOULD be: Remember to save the file after the patch. That's step (1) complete. For step (2) just make sure you open SPI like this: That should be that, no need to hack SPI.h (if you have, try to put it back how you found it) and no need to set the pins manually. I'll be keen to know if that gets you going. |
Beta Was this translation helpful? Give feedback.
Let me wrap this up a little better for @ITDiscovery and/or anyone else trying to use SPI on Port C under the current release, because last night I was typing with my thumbs in bed. If you make a minor (three lines, one character each) repair to a single file buried in the core,
the ONLY other thing you'll need, to get running, is to add the line pinMode(PIN_PC3,OUTPUT) to your program. So that's:
(1) repair one core file, and (2) add one line to your program.
The tricky part is finding that one file. I use Linux. For me the file is located here:
~/.arduino15/packages/DxCore/hardware/magaavr/1.4.10/variants/28pin-standard/pins_arduino.h
If you use Windoze you'll have to search it up yours…