Read SD connected to atmega - Page 1
Forum section: electronics / projects

author: Amper
author_rank: Frequent Contributor
timestamp: July 13, 2019, 08:30:21 pm
content: Hi,another short questionregarding my geiger datalogger build.I plan on using a atmega 328 for arduino compatibility and low sleep current consumption. It will write to an sd card mounted inside of the device which i want to access without removal.Is there any possibility to connect a common micro sd over a bridge IC to the micro and still have a second sd-reader on board connected at the same time? Is there some better way to do this without using a larger micro with worse standby performance?Of cause i dont expect both usb and micro at access at the same time.cheers

author: Kasper
author_rank: Frequent Contributor
timestamp: July 14, 2019, 05:11:57 am
content: Yes that is possible. If you search for SPI with 2 masters 1 slave you might find some good info.I once added a 328p to a df player. I think all I did was connect the SPI and gnd and insert a tri-state buffer in sclk. I used the buffer to disconnect the df player from the sd card when the 328p wanted to drive sclk and read the sd card. Not sure the buffer was needed, but it seemed to be the quickest solution.

author: Amper
author_rank: Frequent Contributor
timestamp: July 14, 2019, 09:22:47 am
content: Thanks!I just found a chip that seems to be absolutely perfect for this application, however it is out of stock everywhere and seems to be "not recommended for new designs"Its the MAX14502, it would allow having a single usb port that by default is routed to the uart bridge and after activation via the controller switches from sd feed through to usb card reader. The absolutely ideal part...Is there any modern equivalent i could use or is this application just non existent today?

author: Ian.M
author_rank: Super Contributor
timestamp: July 14, 2019, 11:29:38 am
content: I think you are overcomplicating your design. Although an ATmega32U4 (as used on the Arduino Leonardo) has a significantly higher current consumption than an ATmega328P, you can still expect to run it in power down sleep mode, with WDT enabled as a possible wakeup event source, for over a year from a single CR2032 coin cell.Program it to be a USB mass storage SD card reader when USB is connected and to run your data logger code when USB isn't connected, and put the money saved from chips to support a dual master SD card interface, dedicated USB SD card reader and USB hub or switch into a better higher capacity battery and you should come out ahead on operating battery life

author: Amper
author_rank: Frequent Contributor
timestamp: July 14, 2019, 01:31:45 pm
content: Mhm, you may be right there, i never had a look at the 32 atmegas until now. I expected them to be similarly bad in sleep consumption as the stm32 analogues. Also i like the fact that there seems to be some projects directly driving the SD with no interface chip. The downside seems to be a serious speed disadvantage. While i dont really have to move much data thats still sad. Also it would be nice to have the ability to run the micro and sd access at the same time.One variant i also like is using a two channel usb hub on board, connecting to the controller side and some sd to usb bridge, i will just have to find a way of switching the sd between the sides. This way it would be possible to operate the device controlled by the computer via usb-uart and at the same time use the mass storage.

author: Ian.M
author_rank: Super Contributor
timestamp: July 14, 2019, 04:12:14 pm
content: Errr...... using a 32U4 the micro code *is* the SD card USB access. The only thing that stops you logging while USB mass storage mode is active is the host USB stack and host OS assumption that it has exclusive access to the block device. There are ways of working around that, e.g. by caching the FAT and directory entries the host 'sees' so they only update on USB connection/disconnection or an eject request. The logger control interface doesn't need to present as a serial port, it can be via a config file on the mass storage device, and zero length 'trigger' files, that start/stop various actions by their creation/deletion.There's not a lot that can be done about the low access speed - that's the penalty you pay for using a relatively slow 8 bit MCU not optimised for USB bulk data transfers rather than something 32 bit with DMA driven high speed USB and several orders of magnitude greater quiescent current consumption.

author: Amper
author_rank: Frequent Contributor
timestamp: July 14, 2019, 06:02:18 pm
content: tbh i did not realize HOW simple the sd is to interface. I have only ever used breakout boards and assumed the chip they all have is some magic isp to sd bridge. well, a levelshifter is a different story... Now i have changed my plans a little again. For now i will stick with my mega328 because i know that all the peripheries work with it, just no nasty surprises and i have just over a month to get the prototype running with or without sd over usb. The next iteration may use the 32 just for being the more modern choice and having some more headspace for future expansions. I may try to put a usb hub on board and just crowbar ground all the data lines by an additional pin of the controller. This way i can disable the usb reader and interface using the 32 or turn the 328s pins limp and let the card reader take over. Not the most elegant way but as far as i can see its the simplest ans smallest way to achieve some more or less high speed data connection without insane efforts to program.Regarding control over files yes, it would be possible but the reason i want to interface the sd in the first place is so that i dont have to use special software on the PC. A simple serial via usb can run on any computer, i could even break out the uart directly and have the entire thing controlled by a master device without the need of any changes to the device or additional software.