Simplified Microchip PIC USB demos (C18/XC8 MLA)

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby imarian241t » Fri Oct 02, 2015 7:52 am

I just checked and say that this is the latest version, should've payed attention to the warning "warning: (1459) peripheral library support is missing for the 18F4550"....thank you very much sir, I will do as you say to resolve the issue
imarian241t
 
Posts: 7
Joined: Fri Oct 02, 2015 7:09 am

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby deiv23 » Fri Oct 02, 2015 3:45 pm

13 transfers and 12 memcpy of 64 bytes. It takes 150ms or 0.15secs

I see what you explained. mmm, now i don't see how can I improve it to be faster... but I should, cause it is a lot of time.
deiv23
 
Posts: 12
Joined: Fri Aug 07, 2015 12:21 pm

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby imarian241t » Thu Oct 22, 2015 10:38 am

So I'm trying to interface my device using your firmware and LIBUSBDOTNET library, I run one of their example codes, I set up the vendor id and product id as requested (0x04D8,0x003F) but it doesn't find the device, I don't really have much experience with USB protocol so I'm guessing the problem is that they are using different ENDPOINTS for communication?...any ideas?...I coud really need some indications on what the problem might be..




.On a side note I'm using another source file for the software part, works fine it detects the my Device, I can read from the device(only on request or polling which sucks)...and write to it but it has very few functions unlike the methods LIBUSBDOTNET provides
imarian241t
 
Posts: 7
Joined: Fri Oct 02, 2015 7:09 am

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby vloki » Thu Oct 22, 2015 11:09 am

Does your device show up in the windows device manager?
(Like in this screen dump that shows a PICkit3)
screenshot34.png
screenshot34.png (67.87 KiB) Viewed 8608 times

<edit> I don't know LIBUSBDOTNET or C# at all. So I can not help you here ...
vloki
Verified identity
 
Posts: 186
Joined: Wed May 28, 2014 8:42 am
Location: Germany
PIC experience: Professional 5+ years with MCHP products

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby imarian241t » Thu Oct 22, 2015 11:14 am

Yes it does
Attachments
fdsfds.png
fdsfds.png (73.96 KiB) Viewed 8608 times
imarian241t
 
Posts: 7
Joined: Fri Oct 02, 2015 7:09 am

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby imarian241t » Thu Oct 22, 2015 4:17 pm

Anyway I solved the problem so for future reference If anyone is interested in interfacing c# (using LIBUSBDOTNET, visual studio) using this firmware follow these steps (provided that everything else is in order)
-install LIBUSBDOTNET
-follow this path (assuming you installed it in your C Drive) C:\Program Files\LibUsbDotNet\libusb-win32
-run install-filter-win
-select install a device filter
-and from a list of populated devices choose your device
-finish

Then their example codes provided by them can actually work (previously I had a problem they ran, but didn't find my device)
imarian241t
 
Posts: 7
Joined: Fri Oct 02, 2015 7:09 am

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby sergiu » Mon Dec 07, 2015 6:58 pm

Hello!

i have a problem with a pic18f46j50. Firmware is the generic hid usb demo from microchip, the pc software i made a new project based on libusbdotnet.
the device is visible and i can transfer data to it, i cant read no mater what i do.

i get "io timedOut" and for bigger buffer i get "win32 error"

for reader.SubmitAsyncTransfer i get "io cancelled"

also after some debugging on the firmware i think the problem is with " if(!HIDTxHandleBusy(USBInHandle))"

with the LATC6 in this if i never get any variation (tested on scope for multiple toggles and nothing)

Code: Select all
void APP_DeviceCustomHIDTasks()
{   
    //Check if we have received an OUT data packet from the host
    if(HIDRxHandleBusy(USBOutHandle) == false)
    {   
        //We just received a packet of data from the USB host.
        //Check the first uint8_t of the packet to see what command the host
        //application software wants us to fulfill.
        switch(ReceivedDataBuffer[0])            //Look at the data the host sent, to see what kind of application specific command it sent.
        {
            case COMMAND_TOGGLE_LED:  //Toggle LEDs command             
               LED_Toggle(LED_USB_DEVICE_HID_CUSTOM);
               
               
                break;
               
            case COMMAND_GET_BUTTON_STATUS:  //Get push button state
                //Check to make sure the endpoint/buffer is free before we modify the contents
               
                if(!HIDTxHandleBusy(USBInHandle))   <<<< this is always false( jumps over)
                   
                    {
                    ToSendDataBuffer[0] = 0x81;            //Echo back to the host PC the command we are fulfilling in the first uint8_t.  In this case, the Get Pushbutton State command.
                    if(BUTTON_IsPressed(BUTTON_USB_DEVICE_HID_CUSTOM) == false)   //pushbutton not pressed, pull up resistor on circuit board is pulling the PORT pin high
                    {
                            ToSendDataBuffer[1] = 0x01;
                    }
                    else                           //sw3 must be == 0, pushbutton is pressed and overpowering the pull up resistor
                    {
                            ToSendDataBuffer[1] = 0x00;
                    }
                   
                    //Prepare the USB module to send the data packet to the host
                      //LATC6 = ~LATC6;
                    USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
                }
               
                break;
        }
        //Re-arm the OUT endpoint, so we can receive the next OUT data packet
        //that the host may try to send us.
        //USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
       
        LATC6 =~ LATC6;
       
        USBOutHandle = HIDRxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ReceivedDataBuffer, 64);
    }
}


where could the problem be ???
sergiu
 
Posts: 1
Joined: Mon Dec 07, 2015 6:36 pm

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby nsgee2015 » Mon Jan 25, 2016 11:16 pm

Hi,

I'm trying to get the CDC demo up and running on a PIC 18F26J50. I've made my configuration for the chip and got the HID version up and running (computer recognizes HID device after flashing) but after flashing the CDC version, it shows up but will not start (requires a driver). Is this normal or does something need to be done on my end Image

Thanks!
nsgee2015
 
Posts: 1
Joined: Mon Jan 25, 2016 11:11 pm
PIC experience: Experienced Hobbyist

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby vloki » Tue Jan 26, 2016 7:59 am

Yes, it requires a driver.
You can find an *inf* file for windows in MLA folder
...\mla\v2015_08_10\apps\usb\device\cdc_basic\utilities\inf
vloki
Verified identity
 
Posts: 186
Joined: Wed May 28, 2014 8:42 am
Location: Germany
PIC experience: Professional 5+ years with MCHP products

Re: Simplified Microchip PIC USB demos (C18/XC8 MLA)

Postby susi » Wed Mar 30, 2016 7:36 am

Dear Vloki
HI
I used your code (PIC and PC side) for pic18f4550 and XC8 compiler in order to communicate with PC. I could change some lines in your code to get some signs of correct connection between my PIC and PC. For example I turned on and off a LED. I finally want to read some pieces of data from an EEPROM on my board and send them to PC to print hex value of them in a *.txt file by clicking on a button on HID-Demo.exe . I know that in HID class and interrupt mode, in each transaction, only 64 bytes should be send or receive. But my data is more than that, about 300 bytes. So I broke data into packets, each packet contained 64 bytes.

here is my changes in PIC side. Assume by clicking on CID-VERSION button, my code will be run:

Code: Select all
void APP_cmd(void) {

    memset( ToSendDataBuffer, ' ', sizeof(ToSendDataBuffer) ); //clear buffer

    switch (ReceivedDataBuffer[1]) {

    case CID_VERSION:// send version info-string
            ToSendDataBuffer[1] = CID_VERSION | ID_MESSAGE;
            ToSendDataBuffer[0] = sizeof (strVersion) + 1;

            int max_packet_num = MAX_NUM_BYTES/64;  //MAX_NUM_BYTES = 300
            for (unsigned char packet_num = 0; packet_num < max_packet_num; packet_num ++)
            {   
                for (  num_of_samples = 2 ; num_of_samples < 64 ; num_of_samples++ )
                {
                ToSendDataBuffer[num_of_samples] = packet_num;
                }
                USBInHandle = HIDTxPacket(HID_EP,(uint8_t *)ToSendDataBuffer, 64);
            }
 
            Flags.IN_TODO = 1;

            break;
.
.    //other "case"s
.
    }//switch (usb_outPck.ID.all)

    if (Flags.IN_TODO == 0) // generate std. ACK
    {
        ToSendDataBuffer[1] = ReceivedDataBuffer[1] | ID_MESSAGE;
        ToSendDataBuffer[0] = 1;
        Flags.IN_TODO = 1;
    }
}


and here is the PC side:

Code: Select all
void MainWindow::rxHandler()
{
    QString s = "";

    io_result = hid_read(connected_device, inBuffer, 65);

    if (io_result == 64){
        if(ui->cbTimeStamp->isChecked()){
            ui->teInHEX->insertPlainText("\r" + QString::number(timeStamp.elapsed())+ "ms -> ");
            ui->teInHEX->ensureCursorVisible();
        }
        for (int i = 0; i<= inBuffer[0];i++){
            s += QString("%1").arg(inBuffer[i],3,16);
        }
        ui->teInHEX->append(s);
        ui->teInHEX->ensureCursorVisible(); // (for auto-scolling)
        ui->teInASCII->append((char*)&inBuffer);
        ui->teInASCII->ensureCursorVisible();

//        if (inBuffer[1] == IDERROR){ // multiple possibilities ------------ERROR
//            edErrors->Text = "ERROR: unknown Device error";
//        }else
      
      switch (inBuffer[1] - ID_MESSAGE)   //---------------------- MESSAGE
      {
        case CID_VERSION:   // version info-string
         //ui->lbVersion->setText((char*)&inBuffer[2]);

         for (int packet_num = 0; packet_num < max_packet_num ; packet_num++)
         {
            for (long int count = 0; count < 65; count++)
            {
               long int numm = count + packet_num * 64;
               my_store[numm] = inBuffer[count];
            }
                                io_result = hid_write(connected_device, inBuffer, 65);
                        }
         myfile.open("file.txt", ios::out | ios::binary);
         for (int ii=0 ; ii <300 ; ii++)
         myfile << " " << hex << int(checkin2[ii]) << endl;
         myfile.close();
         
               break;
                 }
    }
}


By these, in transaction number 1, I sent 64 bytes of "0x00" to the PC and therefore I should get 64 bytes of "0". In transaction number 2, I sent 64 bytes of "0x01" to the PC and therefore I should get get 64 bytes of "0x01" and so on. I have 300 bytes of data, so in (300/64)=4 transaction, whole of the data should be sent.

I using USBlyzer to monitor usb port. the result of the code is that I send 64 "0x03" value, 3 times!!! why?

would you please tell me how I should organize sending data more than 64 bytes? which part of my code is wrong?

Thank you Vloki or any other person who will help me!
Attachments
New Picture (2).jpg
the result of the communicationg data between PIC and PC.
New Picture (2).jpg (235.57 KiB) Viewed 8184 times
susi
 
Posts: 9
Joined: Wed Mar 30, 2016 6:02 am
PIC experience: EE Student

PreviousNext

Return to USB

Who is online

Users browsing this forum: No registered users and 5 guests

cron