usbslave

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times

usbslave

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: usbslave

Post 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.

Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times

Re: usbslave

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: usbslave

Post 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.

Post Reply