LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Control PIC18F4550 via USB with LabWindows/CVI

Hello,
 
at first excuse my bad english, it´s not my native language.
I try to control a PIC18F4550 microcontroller with CVI via USB-RAW. I want to switch 8 digital outputs and read 8 digital inputs of the PIC. I own the sourcecode of the microcontroller and know how to adress it.
 
At first I created an *.inf driver file with NI-Visa. This driver works fine and my device is displayed in MAX. Then I programmed the CVI-Prog.
With the use of various functions in CVI, I am right now able to switch all my 8 digital outputs, but I have trouble reading the inputs.
 
Here is the sourcecode for switching the outputs (not perfect just for example). "sendbuf" is an 64 bit array and contains the message the PIC have to receive to switch the outputs.
----------------------------------------------------------------------------------------------------  
    viOpenDefaultRM (&SessionUSB);
    viFindRsrc (SessionUSB, "?*RAW", VI_NULL, VI_NULL, USBdevice);
    viOpen (SessionUSB, &USBdevice[0], VI_NULL, VI_NULL,&instr);
    viSetBuf (instr, VI_WRITE_BUF, 64);
    GetCtrlVal (panelHandle, PANEL_RD7LED10, &valueRD7);
   
    #define UPDATE_LED    0x32
        sendbuf[0] = UPDATE_LED;      
        sendbuf[1] = 10;             
        sendbuf[2] = valueRD7;     
    
    viBufWrite (instr, sendbuf, 64, VI_NULL);
    viClose (SessionUSB);
----------------------------------------------------------------------------------------------------  
While switching the outputs works fine, reading the inputs doesn´t work at all.
I get this error message "BFFF003A  Invalid setup (attributes are not consistent).
          (VI_ERROR_INV_SETUP)".
 
Here´s my sourcecode for reading the inputs: "receivebuf" is an 64 bit array for storing the data CVI gets from the PIC.
----------------------------------------------------------------------------------------------------  
 viOpenDefaultRM (&SessionUSB);
   viFindRsrc (SessionUSB, "?*RAW", VI_NULL, VI_NULL, USBdevice);
   viOpen (SessionUSB, &USBdevice[0], VI_NULL, VI_NULL,  &instr);
     
   viSetBuf (instr, VI_WRITE_BUF, 64);
   #define RD_POT    0x37
         sendbuf[0] = RD_POT;    
         sendbuf[1] = 0x02;
      
   viWrite (instr, sendbuf, 64, VI_NULL);
   viSetBuf (instr, VI_READ_BUF, 64);
       // viRead function doesn´t work. Program collaps!!!
   viRead (instr, receivebuf, 64, VI_NULL);  
   viClose (SessionUSB);
----------------------------------------------------------------------------------------------------   
The error message says something about wrong attributes. The programm collaps when reaching the viRead function. I think I have forgot something, maybe I have to use viSetAttribute or anything like this. I really have no idea.
 
Perhaps somebody outthere have an idea?? Thanks everybody!!!!
 


Message Edited by Skadi on 04-23-2008 11:22 AM
0 Kudos
Message 1 of 8
(9,498 Views)
Does nobody have an idea?
 
My viread function still don´t work. I even don´t really understand the error message - >"BFFF003A  Invalid setup (attributes are not consistent).    (VI_ERROR_INV_SETUP)".
I think my microcontroller is programmed correctly. I own a Visual Basic program, which do the same things my CVI should do and this programm works just fine.
 
I am really confused... 😞
 


Message Edited by Skadi on 04-26-2008 05:19 PM
0 Kudos
Message 2 of 8
(9,441 Views)

Hi Skadi,

I just looked over your code and as far as I can tell, it looks fine. The error that you are getting indicates that something is going wrong

when communicating with your device via the driver that you have created. To investigate this in more detail I would recommend you to

create a NI-PAL report.  To do this, open MAX and got to HELP >> System Information. Click on "Report" at the bottom of the window and proceed

to generate a full report. Maybe there is something that tells us what exactly the problem could be. Let me know when you have news.

 

Best regards

 

David

0 Kudos
Message 3 of 8
(9,411 Views)

Thank you David for your fast reply!!!

I have a attached the PAL report. Well, I hope it is the right file - I have a German version of NI MAX and things look a little bit different there...
It wasn´t possible to a attach the *.htm file directly so I have zipped the file.

My LabWindows/VISA-programs are relatively new, but I often had problems with the VISA *.inf files. Sometimes the files weren´t recognized by Windows or there were strange error messages and nothing worked. I will reinstall VISA today, perhaps there was an error during the installation - at least it´s better then doing nothing...

0 Kudos
Message 4 of 8
(9,404 Views)
Well, I don´t know if this means something, but when I type
 
viRead (HandleUSBDAQ, receivebuf, 0, &retCount);    
instead of
viRead (HandleUSBDAQ, receivebuf, 64, &retCount); 
the viread function didn´t collaps an I receive the status code "3FFF0006  The specified number of bytes was read.
          (VI_SUCCESS_MAX_CNT)"
 
The value 64/0 stand for the maximum number of bytes I want to receive from the device.
"Zero" can´t be correct, but perhaps it helps solving the problem.
 
p.s. Reinstallation of VISA didn´t chance anything. I also don´t think trying an older VISA version would help.
0 Kudos
Message 5 of 8
(9,390 Views)

Problem solved -  there was an error in my microcontroller firmware. I changed the endpoint descriptors in the usbdsc.c file of the microchip framework and now everything works fine.

Here are the correct descriptors:

/* Endpoint Descriptors *
sizeof(USB_EP_DSC),DSC_EP,_EP01_OUT,_BULK,64,0x00,
sizeof(USB_EP_DSC),DSC_EP,_EP01_IN,_BULK,64,0x00

0 Kudos
Message 6 of 8
(9,186 Views)

Hi Skadi,

 

I'm planning to create a Window/CVI GUI to talk to the PIC18F4550. Currently I have PICDEM FS USB Starter Kit.

I did create the INF via NI VISA and that is the furthest step I went.

 

I knew you had great success of resolving the USB issue. I'm wondering if I can obtain a sample of your CVI program as well as the PIC18F4550 firmware that you'd already modified and working.

 

Your help will be greatly appreciated.

 

-Chee

 

p.s. Let me know how I can compensate you. I can be contacted at cheechong04@yahoo.com

 

0 Kudos
Message 7 of 8
(8,258 Views)

Skadi,

 

Please disregard with my previous e-mail to you. 

 

I managed to make it works in BULK USB RAW using Window CVI. Surprisingly I don't have the end point descriptors problem you came across. But I took the PIC demo code and made it into a standalone project so that other programmers can compile it easily.

 

 

Your code (in the first posting) is helpful and provided a good starting point.

I took your code, made slight modification, and created a project.

With my CVI program, I can toggle LED 3 and LED 4 as well as reading the POT value of the PICDEM FS USB Demo board using PIC18F4550.

 

With my CVI program, you don't have to modify your demo board to toggle the RD7 line.

 

To benefit other programmers, I posted 2 projects in this forum:

1) The sample program of CVI BULK USB RAW

2) The standalone PIC demo program that you can make modification and compile it.

 

Have a good day,

-Chee Chong

0 Kudos
Message 8 of 8
(8,231 Views)