Skip to main content
B C
Associate III
March 23, 2018
Question

Sending infos from computer via SPI or USB

  • March 23, 2018
  • 1 reply
  • 3376 views
Posted on March 23, 2018 at 08:59

Hello everyone,

I am currently working on a STM32F103RBT6 MCU on the OLIMEXINO-STM32 board :

https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/open-source-hardware

 .

So far, I am sending and receiving CAN messages, but I would like to parametrize a little bit more without changing the code (I want to be able to change the number of messages I want to send without recompiling everything, while the code is running on my board).

I first thought about reading those parameters in a file. Problem is that I can't find a way to access it from my MCU (while the file is still on my computer).

I then thought about directly sending the required informations from my computer via USB or a serial port, the issue here is that I have no idea on how to proceed... On the MCU side, I know how to look at data coming from an SP port (not with the USB yet, but I don't think it will be too hard to find), but on the computer side, I have absolutely no idea on how to send these informations ...

Do you know the way to proceed ? Or do you have an idea that would work better ?

    This topic has been closed for replies.

    1 reply

    Nikola Krneta
    Visitor II
    March 24, 2018
    Posted on March 24, 2018 at 12:07

    Actually, using the USB in communication without reading up on the USB hardware and and it's underlying protocol is not so easy despite the apparent ease of use of USB in daily life. SPI, while easy to use, is not so useful when you want to interface with a PC unless you have a Raspberry PI or similar single board computer which has an SPI port.

    I would recommend you use the UART/USART module for your current need. It is much easier to implement. As for the PC side of things you can use Putty (

    https://www.putty.org/

    ) for Windows or Minicom if you happen to use any flavor of Linux OS.

    By the way, if you get stuck along the way in this 'mess' of things, leave a message here again and I will try to help again if possible and if you find my advice useful.

    B C
    B CAuthor
    Associate III
    March 26, 2018
    Posted on March 26, 2018 at 10:01

    First of all, thank you for your answer.

    I took a look at PuTTY and I can't really figure out how to use it, do you know if there is any documentation/tutorial available ? 

    On the USB part, my first thought was not to send data through USB, put just access a file via a path (as we would use C:/Program Files/ ..., but starting from the MCU), before I give up on this idea, I want to make sure that it is not possible (as it would be clearly the most efficient way regarding the different constraints I am facing (i.e : the MCU will be in a waterproof box, it should be easy to change CAN frames etc..).

    Thank you for your future answer !

    Nikola Krneta
    Visitor II
    March 26, 2018
    Posted on March 26, 2018 at 19:55

    To be honest with you Mr. Clergue, I got a bit lazy in trying to find an appropriate online tutorial or simple document showing how Putty works at the basic level so I kind of wrote a small guide with images for you (please check the attachment). I hope it helps.

    Additionally, you may want to check out this link -

    https://learn.sparkfun.com/tutorials/terminal-basics/all#tera-term-windows

    I suggest reading the first three sections (Serial Terminal Overview, What Is a Terminal?, Basic Terminology) and the section Tera Term (Windows). If you are in a hurry, reading the Basic Terminology and Tera Term (Windows) sections should be enough. Tera Term is a simpler tool compared to Putty, but specifically geared towards simple UART/USART communication.

    Your reply contains some information on what you wish to do but it is not enough to form a complete picture. As such I can not claim to understand you system, but if you don't mind me assuming some things I would like to offer some advice. By your statement of accessing a file via a path I assume you mean that you wish to have a 'configuration' file on you PC and then access it, as needed, from the MCU. If I am correct, then the manner in which you connect your MCU to the PC (USB, USART, or even CAN - I checked and there are some USB to CAN converters for PCs) is completely irrelevant for the purpose of accessing that file. File access in this manner is software dependent, meaning the file access depends on how you implement the access protocol. This almost the same idea as accessing files on a NAS server from your PC. This also means that your protocol for accessing that configuration file can be configured to use any hardware interface for communication (USB, USART, CAN).

    Please keep in mind that I have absolutely no idea how you can access directories on the PC via those hardware interfaces mentioned before using built in functionality in the Windows operating system. As I said, this is similar to the idea of accessing NAS storage, but I have no idea how to do this with an MCU.

    If you are hell bent on using this method of access I would suggest you write some sort of simple server software for your PC which will listen for incoming commands on any chosen hardware interface. After the server accepts the incoming command with the path variable, it could open the file at the given location, and finally send back the configuration data. In this case it might be better to just write the server program to listen for a command that means 'request configuration' and then just sends back data (you could put your file in the same directory as the server executable is).

    Final thing I would suggest is NOT using the MCU as the client (the MCU request configuration data) but rather using the MCU as the listener. In essence, program the MCU to listen for incoming data and if the data matches some pattern, use it as your configuration data. This will simplify and software written for the PC to 1) select interface 2) read config file 3) send config data as data stream to MCU.

    I hope my reply will be helpful to you and I also apologize if I have overstepped my bounds.

    With respect.

    ________________

    Attachments :

    putty_guide.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxri&d=%2Fa%2F0X0000000b1Y%2FgfIvNIJGYRLFMUxhptRQm7b.jEFaL.8rwq7cL65CQLQ&asPdf=false