PDA

View Full Version : Has anyone been successful in interfacing a PIC16, a MAX3421 USB Host and a camera?



johnmaetta
- 4th October 2011, 17:06
My latest project is to take timelapse photos using a Nikon D40 DSLR camera. There are a couple of PC based camera control programs out there such as DIY PhotoBits, but I want to operate from remote locations where AC power is not available. So, my operating time is limited to the battery life of the laptop and I need the timelapse to span a couple of days.

I used a USB analyzer and DIY Photobits software to capture the Nikon USB command to activate the shutter. The MAX3421 USB Host controller seems like a good choice to interface with the 16F648. It seems possible to use SHIFTIN/OUT to load data into the MAX3421 registers and output the shutter command to the Nikon.

Has anyone used the MAX3421 USB Host controller? I have read the MAX3421 Programming Guide and datasheets, but still have some questions that only an experienced MAX3421 user can answer.

Thanks,

John

dhouston
- 4th October 2011, 18:31
I am planning to use a MAX3421E in a project I'm working on but I'm also new to this chip and to USB Hosting so I probably cannot help much. And, I'm not using a PIC for this.

However, Jan Axelson has a new book on Embedded USB which Amazon will have in November. She also hosts a forum (http://www.lvr.com/forum/index.php) where she answers questions about all of her books, articles and things like this. I think I've bought all of her books in the past 10 years or so and find her to be one of the best technical writers ever - she presents things clearly, making most things easy to understand. That said, she may have her work cut out for her explaining embedded USB.:(

EDIT: There is a sample chapter available - see the USB forum. It looks promising.

dhouston
- 4th October 2011, 18:51
Obviously, I don't write as clearly as Jan. Here's a direct link about her Embedded USB Hosts (http://www.lvr.com/usb_embedded_hosts.htm) book.

johnmaetta
- 4th October 2011, 22:22
I ordered the MAX3421EVKIT-1+ from Digikey to help me understand USB a bit more and to develope my camera intervalometer project.
There are many questions about enumeration and other things. Just how much does the MAX3421 do behind the scenes to allow the PIC to just read and write registers via SHIFTIN and SHIFTOUT.
Only one device will be connected to MAX3421, so I am assumming that the MAX3421 will assign the endpoint as EP1???
Below is how I understand the MAX3421 to work. Someone with MAX3421 experience please check my program flow and let me know if I am missing any steps.

Set Mode:
1. Assert SS low.
2. Clock out SPI command byte 11011010 – selects R27 (MODE) for a write.
3. Clock out 11000001 – sets D+ and D- pulldowns and Host mode.
3. Assert SS high to end.

Read HRSL status register:
4. Assert SS low.
5. Clock out SPI command byte 11111000 – selects R31 (HRSL) for a read.
6. Clock in R31 data and check for JSTATUS AND KSTATUS to determine when a device has been connected or disconnected and is a Low or High speed device.
7. Loop step 6 until detected.
8. Assert SS high to end.

Load Send FIFO register with camera shutter release command data bytes:
9. Assert SS low.
10. Clock out SPI command byte 00010010 – selects R2 (SNDFIFO) for a write.
11. Clock out data bytes to load Send FIFO.
12. Assert SS high to end.

Load Send Byte Count register with the number of data bytes in Send FIFO:
13. Assert SS low.
14. Clock out SPI command byte 00111010 – selects R7 (SNDBC) for a write.
15. Clock out number of bytes loaded into SNDFIFO.
16. Assert SS high to end.

Send data to device by writting to HXFR register:
17. Assert SS low.
18. Clock out SPI command byte 11110010 – selects R30 (HXFR) for a write.
19. Clock out 00100001 – selects Bulk Transfer and EP1.
20. Assert SS high to end.
21. Pause x seconds then repeat the write to HXFR register.

Normnet
- 5th October 2011, 00:33
I also have a MAX3421 waiting for better explanation.
The following C code reference (not a lot of help) is what I had found:


********************
MAXIM USB Laboratory
********************
This project was constructed from the downloaded Keil demo code mdk303a.exe,
available on the Keil web site. If you have a Keil ULINK box, be sure also
to download the USB driver from the Keil web site. The USB driver downloaded
and tested with this code has the file name "3071.zip".

This project uses two files that are not supplied with the Maxim code:

C:\Keil\ARM\RV30\Boards\Keil\MCB2130\Blinky\startu p.s
C:\Keil\ARM\RV30\Boards\Keil\MCB2130\Blinky\retarg et.c

If you installed the Keil demo code in the default C:\Keil directory this project
should compile without incident.

Norm

ardhuru
- 5th October 2011, 03:16
Actually, if all you want to do is control the shutter remotely (or an external intervalometer), there's an easier way to do this. I dont have a Nikon, I use Canon, but the principle is the same.

Check out this page for a complete time-lapse aid that *fits in an EP plug*!

http://cms.diodenring.de/en/electronic/mikrocontroller/82-intervalltimerv2

Regards,

Anand Dhuru

johnmaetta
- 5th October 2011, 15:51
Unfortunately, the Nikon D40 only has a USB interface, so USB commands are the only option.

ardhuru
- 5th October 2011, 15:55
How about IR, then?

http://www.bigmike.it/ircontrol/

Well written code running off NiMH batteries should go on for quite a few days without a recharge, I guess. Still much simpler than USB, I'm sure.

Regards,

Anand

johnmaetta
- 5th October 2011, 17:27
I actually started down the IR path several months ago, by buying another IR control to modify.

My MAX3421 Eval kit arrives today, so I will be able to experiment with USB control. Who knows, I may go back to IR soon.

dhouston
- 5th October 2011, 20:30
This might be helpful (http://www.circuitsathome.com/mcu/arduino-usb-host-shield-build-log-part-2) although not directly answering your question. I went searching for a 3.3V to 5V converter and stumbled on to it.