Microcontroller c++ data sending

Discussion in 'Embedded Systems and Microcontrollers' started by syndred, May 6, 2014.

  1. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Greetings,

    I have a custom-made (not by me) microcontroller, whose hardware I know very little about. It has its driver, can be programmed using Flowcode.

    However, for one reason or another, I would like to send data via a c++ program. I would rather avoid having to write a custom driver, I don't know how to do so anyway.

    I only know the microcontroller has a FCI USB connector and that the Driver name for Flowcode is Flowcode USB slave.

    I was told that a comparatively easy way to send very simple data (any kind of simple recognizable command) to the microcontroller would be by making the connection as a virtual COM port, and then sending data using standard C++. The data could be interpreted from the microcontroller's point of view by using Flowcode.

    However, I have no idea how to make the device be detected as a serial port. I have a couple of virtual device serial ports on my Windows 7, but I don't know how to associate them to a usb port either. The info I've looked up seems to be very OS-dependent or hardware-dependent.

    I know C++ a little but next to nothing about USB interfaces and drivers. Any help or explanations on the matter would be greatly appreciated.

    Thank you very much.

    Edit : Alternate solutions to the VP solution are welcome as well, if they are simpler to implement.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What kind of controller board do you have. Can you name the brand or even better post some links? Most micros do have an UART on board. By using this and a cheap USB to serial dongle. The latter will create a virtual serial port on your PC. With this setup you should be able to do what you want quite easy
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    A "virtual COM port" is a Windows method of receiving data thru a USB device that your Windows program sees as a serial port. FCI makes several chips to do this task. They are well documented, so look at the part number on your board and see what FCI says about it.

    It should also be a simple thing to load the corrent FCI driver into Windows and see it on the device manager. The FCI will negotiate a connection with the PC, and you should see that on the PC without any modification to your board or it's program.

    You will also need to know what connections exist between the FCI chip and your PIC. That will determine what the Flowcode code needs to do, wether you are getting/sending serial data, parallel bits, or what.
     
  4. colinb

    Active Member

    Jun 15, 2011
    351
    35
    FCI makes USB connectors; FTDI makes USB serial interface chips. A little confusing.
     
    ErnieM likes this.
  5. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Sorry for the late reply.

    The driver I have is for Flowcode, not really what I'm looking for. And I don't have any other information about the card.

    I do know however that the driver makes use of the mchpcdc.inf file enclosed, which does contain some information about the way the interfacing works. If I'm not mistaken (it's a rough guess), a virtual serial port that can be used to exchange with the card is defined in that .inf file.

    I think now what I need is an installer for the driver, and a way to link it to one of the two COM virtual ports on my computer (COM3 and COM4).

    Does that sound about right to you ? I really am not familiar with that stuff, and I really need help.

    Thanks in advance.
     
    Last edited: May 11, 2014
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    It sounds like a lot of things to me, mostly like your microcontroller has some sort of bootloader that Flowcode can use to insert another program.

    You can check the virtual com ports by opening up Device Manager on your PC then plugging in your microcontroller device. If there is a com port active you will see it show up there.

    However, even having the hardware there you need to find what it is on your microcontroller end, how to control it from Flowcode, and write that end of the program.
     
  7. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Thanks for your answer.

    The microcontroller end is no issue, interpreting the necessary bytes and strings is no problem. However, the device appears as a USB device on my computer, when I use the installer provided.
     
  8. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    I've finally been able to obtain the name of the microcontroller : It's one of the Matrix Multemedia PIC 18F 4553 series.
     
  9. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    I've downloaded the Microchip USB library for PICs, including the PIC18f4550 series.

    It seems there is a CDC Driver (enclosed) with the same name as the one I've previously uploaded that could do what I wish, and it also seems that there are example files on how to use the USB and CDC parts of the library.

    However, I don't know how to install the .inf file. The Flowcode driver keeps reinstalling whenever I plug in the device, is 'fully up to date', and I can't seem to detect the .inf folder via Device Manager, nor install the .inf by right-clicking and selecting 'install'.

    Essentially, IF I am on the right track, all I should need to do is complete that driver installation and then move to COM port programming in C++ once it shows up as one of said ports.

    Am I on the right track ? And how come the installation isn't working properly ?

    I realise these are more general issues with drivers, so might not belong in this topic so much, but they're still linked to the PIC18f controller. And I probably won't advance without help here.
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I think you are messing things up for your self here. If you want to send simple commands to the PIC on your board in an easy way. Use some sort of USB to Serial dongle. And do the communication with the UART onboard your PIC.
    You have the datasheet right?
    http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
    Then look at sextion 20
    I guess you use a board from this site http://www.matrixmultimedia.com/ but it looks like the site is down at the moment
     
  11. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    I know it would be a more natural suggestion, however :

    The microcontroller's board is connected to the PC via USB, I don't have choice in the matter. The microcontroller needs to receive a signal via the USB.
    It would be WAY more practical to send said signal through user-made software than through Flowcode, from a user point of view, and it's only a couple of bytes and strings. No need to receive signals, just send those and then the microcontroller will be programmed to interpret the signal (using Flowcode or similar typical microcontrollers programming methods).

    Surely there's a relatively simple way for me to do this, setting up a virtual com port ?
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    syndred: The part I keep coming back to is when you said in your first post "I have a custom-made (not by me) microcontroller, whose hardware I know very little about. It has its driver, can be programmed using Flowcode."

    Now "Flowcode" is a language, not a programming tool. When starting off people can be fuzzy when naming the parts (and the providers don't help much either). I suspect you have a design environment program that uses Flowcode to write code, then can use the USB to send the code to your target PIC device.

    Hopefully I'm guessing the correct process there. ;-)

    To do that the PIC has to have a fixed piece of code called a "bootloader" that talks to the PC over the USB, and can accept code and program the rest of the PIC. It's main limitation is a bootloader cannot upload another bootloader, it can't program the entire memory range.

    To break away from that you need a "real" programmer, a piece of hardware that can handle any piece of code to place into anywhere in memory. A PICkit can do that.

    Once you make your own program (and the examples you found for a CDC device is an excellent starting point) ("Communications Device Class" is used for things such as virtual serial ports) you can use a PICkit to program your PIC chip then talk to it over the USB.
     
  14. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Thanks again for the replies.

    t06afre : My apologies, the microcontroller isn't custom-made, but the board is. I used the wrong terms in my first post.

    ErnieM : You're about right. I guess I wasn't descriptive enough. I know Flowcode isn't a programming tool, it wasn't the right term to use.

    We use a programmer to load programs (or more accurately, code generated by those Flowcode diagrams) onto the PIC. We make use of the USB connection for this purpose. However, when it is running, we also want a permanent USB connection to a computer, that waits for computer to send some bytes or some strings.

    In essence, Flowcode tells the PIC how it should interpret data received, but if I want to send data via the USB connection, which I do, without Flowcode, that's where the problem lies, driver-wise, as mentioned above, and complexity-wise.

    The situation is just about like this : the microcontroller controls a motor for a propeller as well as a basic speed monitor for the the propeller. The way it handles the last two is configured with Flowcode. I want to be able to run a basic program on my computer that, when launched, sends a byte in order to tell the microcontroller to start the propeller, and then at a command tell it to change speed.

    It's just basic signals. The CDC requires installing an IDE and a very specific compiler and writing some very unusual code for me. Surely there's a way to do this with more classic compilers or IDE ?

    Hopefully this makes my problem a little bit more clear. I also have the aforementioned driver issue.
     
  15. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Can you post any picture of your mystic board?
     
  16. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Unfortunately I can't. But why do you need to see one ? It has a couple of input/outputs, and the one I'm interested in is the USB connector.

    On a side note, the multiprogrammer board is an EB-006 if that may help.
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    This problem seems general enough that a full detailed schematic is not required. Knowing D+ and D- from the USB connector go to PIC pins 16 and 15 is all anyone should need to know from the schematic. I am assuming such is true (with reservation noted below).

    Therein lies your problem: you want to use the same USB port to load the program, then later on to accept data.

    The 2nd use, runtime USB for data is not a big problem. The CDC class is fully supported by Windows, meaning it already has the driver built into the OS. Additionally, most any Windows programming language (VC, VB) has a widget to comminucate with COM (serial) ports be they traditional RS-232 or a virtual port via the USB.

    The 1st use, to act as a programmer port hopefully requires a USB bootloader be permamently loaded into the PIC, otherwise the programmer is using a USB connector for a different protocol. It is easy to tell, if you simple plug your unit directly into a PC USB port for programming then you have the best case.

    There should be no reason a USB bootloader and a USB app cannot live in the same PIC: the bootloader typically checks if a program is being loaded, and if not jumps to the "application" portion of the code, never to run boot code again till the next power up. I would be curious how this determination is made: is there a button to press, does the PIC simply stay in bootloader mode if connected when powered up, or does it detect the PC USB connection on a continious basis?

    I'm not very familiar with FlowCode, does it have a block to handle USB, or are you going over to your own C program?

    For any application program to live in harmony with a bootloader requires a custom linker script to arrange the app code into the memory locations where the bootloader expects it to be. That may be listed somewhere in your documentation.
     
  18. syndred

    Thread Starter New Member

    May 6, 2014
    13
    0
    Thanks a lot for your answer.

    The first use is no problem. Microcontroller is configured using Flowcode, so propeller moves according to speed and all that, generated code is sent through usb connection to board which loads it onto microcontroller.

    The 'not a big problem' is the one I have a problem with. You say that CDC classes are supported by Windows. So I just have to include the librairies in a C++ project ? I don't need to make sure my device is set to a virtual port ? What about the driver I mentioned in my very first post ?

    And I've a friend who's been looking into libusb as well. Perhaps we'll go for that instead of CDC, it seems (from afar) to be slightly simpler to implement. It's not COM port communication though.
     
  19. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Damn, I would really like to be more helpful but I have a nagging feeling we are takling past one another, probably because I am not a Flowcode user.

    I did find this interesting link when I googled "Flowcode USB slave". It appears Flowcode may very well have a very useful component for you.

    Not having that product myself you would have to tell me if that is relevant.
     
Loading...