Hello all
I am Raju Kamal, a Student from University of offenburg, Germany. Now I am faceing a problem to implement the USB-CDC protocal by using MAX3420e interface with our Microprocessor. Can any body send me the c source code for MAX3420e for USB-CDC. It will be gratefull from me!!!
Best regards Raju Kamal
// basic function call that handles a SETUP transfer request. // The main loop calls this function whenever the MAX3420E asserts the SUDAVIRQ bit. void _USBmax3420E_ENUM(void) { readbytes(rSUDFIFO,9,SUD); // got a SETUP packet. Read 8 SETUP bytes
switch(SUD[bmRequestType]&0x60) // Parse the SETUP packet. For request type, look only at b6&b5 { case 0x00: std_request(); break; case 0x20: class_request(); break; // just a stub/placeholder in this program // case 0x40: vendor_request(); break; // just a stub/placeholder in this program default: STALL_EP0 // unrecognized request type // If no legal case value is found, the correct peripheral // response is to send the STALL handshake instead of // ACK or NAK to indicate that it failed to recognize the request. } }
// Standard USB request void std_request(void) { BYTE a;
switch(SUD[bRequest]) // bRequest byte of the SETUP data packet // The ‘SR_’ names in the switch statement correspond to the nomenclature // in Chapter 9 of the USB Specification, which defines the USB standard // requests and data formats. // The SET_FEATURE and CLEAR_FEATURE requests are served by a single feature() // function that takes an argument indicating which operation, set (1) or // clear (0), is required. The SET_ADDRESS request does nothing but set the // ACKSTAT bit by doing a dummy read to the REVISION register. This is // because the MAX3420E hardware automatically handles the Set_Address request. { case SR_GET_DESCRIPTOR: send_descriptor(); break; case SR_SET_INTERFACE: set_interface(); break; case SR_GET_INTERFACE: get_interface(); break; case SR_GET_CONFIGURATION: get_configuration(); break; case SR_SET_CONFIGURATION: set_configuration(); break; case SR_SET_ADDRESS: a= rregAS(rFNADDR); break; // discard return value default: STALL_EP0 //wreg(9,0x23); } }
// ************************************************************************** // // ************************************************************************** // // About Descriptors // Our application uses the following USB descriptor types: // - Device // - Configuration // *Interface // - Endpoint // - String // - (Report) // The include file EnumApp_enum_data.h contains the various descriptors used to // give our peripheral device its personality. A USB device can have multiple // configurations and interfaces, but our application uses only one of each. // The descriptors in parenthesis above are unique to the HID class,and would // be omitted by a non-HID device.
void send_descriptor(void) { WORD reqlen,sendlen,desclen; BYTE *pDdata; // pointer to ROM Descriptor data to send int send_ZLP=FALSE; // // NOTE This function assumes all descriptors are 64 or fewer bytes and can be sent in a single packet // The send_descriptor function uses two variables to determine the number of bytes // to send: the requested length, reqlen; and the actual descriptor length, desclen, // which it retrieves from the descriptor tables. The function starts by setting // desclen = 0. If desclen is still zero after all the descriptor-type checks are // complete, a valid descriptor type was not found and the function sends the STALL handshake. // The requested lengths are found in the wLengthL and wLengthH bytes of the SUD array. // After loading this 16-bit value into the reqlen variable, the function uses a // switch statement to check for various values of wValueH, which indicates the descriptor type.
desclen = 0; // check for zero as error condition (no case statements satisfied) reqlen = SUD[wLengthL] + 256*SUD[wLengthH]; // 16-bit // showword(reqlen);
switch (SUD[wValueH]) // wValueH is descriptor type { case GD_DEVICE: desclen = DD[0]; // descriptor length pDdata =(BYTE*) DD; break;
case GD_CONFIGURATION: if(SUD[wLengthL] > CD[2]) desclen = CD[2]; // Config descriptor includes interface, header and ep descriptors (67 Bytes [0x0043]) else desclen = SUD[wLengthL];
if(SUD[wLengthH]!=0) desclen = CD[2]; // wLengthH=1 (last byte) pDdata = (BYTE *) CD; break;
case GD_STRING: desclen = strDesc[SUD[wValueL]][0]; // wValueL=string index, array[0] is the length pDdata =(BYTE*) strDesc[SUD[wValueL]]; // point to first array element break; case CS_INTERFACE:
if(SUD[wIndexL]==0) // Interface Number=0. Del EndPoint 2 (interrupción), Communication { //if(SUD[wLengthL]>CD[9]) desclen = CD[9]; //else desclen = SUD[wLengthL]; pDdata = (BYTE *) &CD[9]; }
else if (SUD[wIndexL]==1)// Interface Number=1. Del EndPoint 1 (bulk), Datos { //if(SUD[wLengthL]>CD[44]) desclen = CD[44]; //else desclen = SUD[wLengthL]; pDdata = (BYTE *) &CD[44]; } break;
case GD_REPORT: desclen = CD[25]; pDdata = (BYTE*)RepD; break;
} // end switch on descriptor type
Now why did you post your code without specifying that it was code?
Look once more at the information you see when posting comments - there is one sentence specifically mentioning what you should do when posting code. If you don't follow that instruction, the code you paste will be practically unreadable.
ok, i am sending my code with couple of pages: #include <io.h> #include <string.h> #include "SD_driver.h" #include "FAT.h" #include "MAX3420E_BF1.h" // MAX3420E registers (rREGNAME), bits (bmBITNAME), and subroutine-definitions
//Hauptprogramm int main() { long int g; int i; int msec_timer=0; int PC_DTR=0; int USB_int=0;
// Enumeration, Initialisierung des internen FPGA-USB-Controllers ////////// for(g=0;g<4000000;g++); putport(0x13,4); for(g=0;g<3000000;g++); putport(0x13,0); for(g=0;g<3000000;g++); //Warte bis USB bereit! //////////////////////////////////////////////////////////////////////////// // Enumeration, Initialisierung des USB-Maxim3420E-Controllers ///////////// initialize_MAX(); // Enumeration-Interrupt abwarten for(g=0;g<3000000;g++); //Warte bis MaxUSB enumeriert ist
USB_writeln(_Copyright); //Ausgabe der Versionsnummer
if(loadData()!=0) USB_writeln("Karte nicht lesbar!\r\n\0"); while(1) //Endlosschleife der Befehlzeile { USB_writeln("\r\nSD\0"); USB_writeln(_path); //Aktueller Pfad USB_writeln(">\0");
MaxUSB_readln(_stinp); //Befehl einlesen USB_writeln("\r\n\0"); USB_writeln2(" juhu\r\n\0");
if((getport(0x16)&1)!=0) //SD-Karte gesteckt? Nein -> Meldung USB_writeln("Keine Karte vorhanden!\r\n\0"); else if(checkState()!=0) //SD-Karte initialisiert? { if(loadData()!=0) USB_writeln("Karte nicht lesbar!\r\n\0"); } else { for(i=0;_stinp[i]!='\0';i++)//Eingabe in Großbuchstaben wandeln if(_stinp[i]>0x60&&_stinp[i]<0x7B) _stinp[i]-=0x20;
if(runProc(_stinp)!=0) //Auswertung der Befehlszeile
USB_writeln("Befehl oder Dateiname nicht gefunden\r\n\0"); }
} return 0; }
// USB-Maxim3420E Routinen #include "EnumApp_enum_data.h" //CDC enumeration data #include "USB_SPI_COM.c" #include "USB_INIT.c" #include "USB_Enumeration.c" //#include "USB_Interrupt_handle.c" #include "USB_CDC_Appl.c" // SD-Karte bzw. Dateisystemroutinen #include "SD_driver.c" #include "FAT.c"
How do you expect anyone to make any comment on your program without seeing your program?
It is like saying, "My car doesn't work - what's wrong with it"
Remember: nobody knows anything about you, your project, or your code apart from what you provide in your posts!
I have finished my program for USB-CDC with some problem. my problem is now i can read but cannot write. Is it like can communicate from Host to usb but cannot usb to host? Does anybody has any idea about this problem?
Thanks Neil for sending the link for interface. May be i confuse you, actually i wish to see a source code as an example, which will be usefull for me to get some information and can program my project.
"Can any body send me the (sic) c source code for MAX3420e for USB-CDC"
You are making the assumption that there is only 1 possible "source code" in the whole world to do this for any & every application. Unfortunately, this is not the case - otherwise Maxim could supply it with their chip!
You need to study the MAX3420e datasheet - that will tell you what you need to do in order to use the chip.
You should also visit the Maxim website and look there for examples, application notes, etc...
This is the standard process for interfacing anything to anything else - see: www.8052.com/.../160143
View all questions in Keil forum