Page 1 of 1
usbslave
Posted: Tue Oct 05, 2010 11:59 am
by Roy Johnston
How can i go about using the usb slave but still allow the chip to run on its own. one routine to read and write data from the usb port and another to execute independently. i first thought of the usb serial, however this assigns a com port . rs 232 emulation. I would imagine a total rewrite of my visual basic.
Re: usbslave
Posted: Wed Oct 06, 2010 12:28 pm
by Benj
Hello Roy,
The USB Slave can be used without running the slave service. You can simply use the read and write byte functions to send and receive data. Note that the PC will have to be polling on a regular interval as the microcontroller cannot initiate comms transactions in slave mode. If you decide to do things this way then you will still have to set up the USB slave component properties with a dummy service macro to allow the compilation to work.
Another way of doing this would be to use the slave service as normal but then also have a timer running in your program which allows the rest of your program functionality to run while communications are not taking place.
Re: usbslave
Posted: Thu Oct 07, 2010 4:59 am
by Roy Johnston
Thanks,
Am I correct in assuming the following.
1) my Vb program polls the chip every 3 seconds.(this happens at present)
2) In my service macro I only read and write from and to the PC.
3) My main macro is used to set up all parameters like the slave service i2c comms ect.
4) I can create a new macro from where I will execute all the other functions like counters set outputs ect.this macro could be called from mwithin the main macro.
5) The new macro could have a routine to keep poling itself from the beginning.
6) I am not sure by what you mean a timer
7) where do you read and write the byte method from within the service macro
Re: usbslave
Posted: Thu Oct 07, 2010 8:36 am
by Benj
Hello Roy,
1) Yes the VB program controls how often transfers occur.
2) The service macro is a way of reacting to the PC request as soon as it occurs. You could instead not use the slave service and poll for incoming data by using the Get_Byte or Get_String routines.
3-5) Seems fine.
6) A timer interrupt could be used to allow you to use the slave service routine along side a regular macro that runs when a timer overflows. See my article on the USB slave scope for an example of this.
http://www.matrixmultimedia.com/mmforum ... =26&t=6813
7)If your using the service macro then you simply use the macro parameters to pass in values from the PC, you return data at the end of the macro by sending a string or a single byte. Note that multiple byte sends will not work so if you need to do this you will have to use a string like an array of byte variables and then send the string.