STM32 - USB - CDC_Transmit - How to read the data on PC? - Matlab? - matlab

I am in the process of programming some sort of USB oscilloscope.
I followed the tutorial, using a STM32F429.
https://www.youtube.com/watch?v=MmwR1VU_rVc&list=PLnMKNibPkDnHxpOv2HETihQy5HHQGv2nS&index=26
The tutorial was very helpful with this and I am able to use the software from the tutorial (stmscope) to see the incoming data.
However, I would like to process the data in Matlab, where my problems start. As far as I understand the baudrate does not matter, because there is no real UART connection?
For reading the UART in another project I used for example "Putty" or "SerialMonitor". By specifying the baudrate and the com port the readout was quite easy, even in Matlab.
The used USB port is simulated as a virtual com port and the data is sent with CDC_transmit. However, with the previous methods "Putty" or "SerialMonitor" I cannot read the sent data, because I have to specify a baudrate for this, which is unknown to me. Which program is suitable to monitor the incoming data?
In Matlab I also have the same problem that I have to specify a baudrate for the com port.
My goal is to evaluate the data in Matlab. Preferably I would like to read the data directly with Matlab from the virtual com port and save it in Matlab. If this is not possible I would first save the data to a txt.file and then read it into Matlab.
Are there any ready-made solutions or open source programs for this?
Thanks for reading and your help!

Related

How do I view raw memory addreses of MODBUS TCP/IP holding registers in CODESYS

For a work project, I have to read a bunch of holding registers from an IFM CR1203 PLC that is programmed using CODESYS 3.5.
The PLC will be running a slave instance and the device reading the holding registers will be a PC running a custom application programmed in Javascript to be a client. I have already programmed MODBUS TCP/IP functions for the custom application that is tested and works (For a previous project I had to do the same for a different PLC programmed using a different platform).
My current issue is that I need the raw memory address of the first holding register to do this, but I can't find it on the CODESYS IDE. CODESYS uses an addressing system that makes it easy for different CODESYS-based devices to communicate. Here is a link that explains how it works: CODESYS MODBUS register location guide
The only thing that looks like it can work is from the link above:
<memory position> : <number> ( .<number> )* // Depends on the target system
But I don't fully understand what all that means.
I also can't find any documentation on the PLC or CODESYS that explains this topic in enough detail. Here is a snippet of dummy code used for testing that shows the CODESYS addresses:
Can someone please explain to me how I can convert the value %IW0 to a raw memory address, for example, 0xFFFF?
I use Machine Expert (Codesys 3.5.16) and in their documentation says:
The I/Os are mapped to Modbus registers from the master perspective as follows:
%IWs are mapped from register 0 to n-1 and are R/W (n = Holding register quantity, each %IW register is 2 bytes).
%QWs are mapped from register n to n+m -1 and are read only (m = Input registers quantity, each %QW register is 2 bytes).
So in your example they should be address 0 and 1.

Read simulink signal data into matlab during simulation

I want to continuously read simulink signal data into the command line while the simulation is running. get_param() seems to be blocking so that doesn't quite work when put in an infinite while loop.
I'm now trying to use a UDP send block but I can't seem to receive data. My UDP block sends data to localhost over remote port 25000 and local port 25001.
In matlab I use the following code but it simply times out with no data
u=udp('127.0.0.1', 25001,'LocalPort',25000);
fopen(u)
fread(u)
fclose(u)
delete(u)
What are my options to continuously read out simulink signal data into Matlab CLI?
Control Simulation Using the "set_param()" command like follows:
set_param('sys','SimulationCommand','WriteDataLogs')
For a working example, type "sldemo_varsize_basic" in the matlab command window. Then above command becomes
set_param('sldemo_varsize_basic','SimulationCommand','WriteDataLogs')
If you set the simulation time to sufficiently large and start the simulation, the "simout, simout1", "tout" and "xout" variables are created/updated in the workspace every time you issue the command above.
Unfortunately, I was not able to find a good quality documentation of this feature.
Are you trying to store the value of your model outports DURING simulation? This is not possible because the variables 'simout, simout1", "tout","xout" etc are created only once simulation is OVER.
In order to read/store the value of outports during simulation, you will have to attach an 'Runtime Object' to the outports.
Refer 'Access Block Data During Simulation' in the Simulink documentation or see this link: http://in.mathworks.com/help/simulink/ug/accessing-block-data-during-simulation.html?s_tid=gn_loc_drop
Hope it helps :)
This question has already been answered here using RunTime Objects as I have described above:
https://stackoverflow.com/a/17006419/6580313

Matlab and FTDI

I am trying to send/retreieve data from/to FPGA using Matlab. I connected FPGA using Virtual com port. Now how to send data from Matlab to FPGA or read data of FPGA ?
FTDI 2232H is on the FPGA as well. I connected external LED's and switches on the I/O ports of the FPGA.
I am new in this field, so want some guideline to start communication b/w MAtlab and FPGA:
I tried following code:
s1= serial('COM9')
fopen(s1)
. Is it the right way to communicate ? Kindly guide. thanks
FPGA's are configured using a Hardware Description Language (HDL) such as Verilog or VHDL. These languages let you specify how the switch configuration within the FPGA, which in turn lets you construct your custom digital logic and processing system.
The HDL Coder Toolbox in Matlab lets you design and prototype your custom logic using higher-level functions, which are then translated into HDL and can be be used to directly program your chip. This tutorial describes the process in detail.
If you already have a design implemented on your FPGA and want to communicate with that implementation, you would use Matlab's serial port communication functions. The exact protocol will depend on the interface you have implemented.
Some intermediate debugging steps I find helpful:
Verify that you can send serial port data from your computer. In Windows XP, you can do this easily with HyperTerminal, and hooking up a scope to the output pins of your serial cable. Set up a trigger to capture the event. For Windows 7 and newer, you'll need to download a HyperTerminal client.
Repeat this same process with Matlab. Using a scope, verify that you see the serial port signal when sent from Matlab, and that the output matches the results from step 1. Again, set up a scope trigger to capture the event.
Now connect the serial cable directly to the FPGA board. Modify your HDL to include a latch on the serial input that displays the output on the LED's. Verify that your board initializes to the correct LED state, and that the LED state changes when you send the serial message.
Lastly, verify that you are interpreting the message correctly on the FPGA side. This includes making sure that the bit-ordering is correct, etc. Again, the LED outputs can be very helpful for this part.
The key here is to take small, incremental steps, physically verifying that things are working each step of the way.

Interfacing between a PC and custom made circuit

I'm working on a project where I want to install a photodetector circuit to a computer through some sort of interface (preferably USB). However, since I am new at this so I do not know in what direction that I should approach this problem on. Assuming I have a photodector circuit with a USB connection, does the "interfacing" require only writing the device driver? Or do I need to do any additional work? Please advise if I am overlooking something. Thanks!
The easiest way to communicate with your computer would be using an integrated circuit that does all the communication for you. Take a look e.g. at the FTDI FT232 Chip. It is extremly simple to use as it emulates a virtual COM port in the basic mode (USB drivers for all major platforms are included). So the only thing you would have to do on the PC side would be writing to the serial (COM) port.
Then your microcontroller circuit can simply communicate with this chip via UART, which is supported by almost every controller (e.g. Atmel ATmega series).
Alternatively you can simply use your real RS232-Port, but many modern computer don't have such a port anymore.
The simplest one possible is obviously through the LPT port.
Out of its 25 pins, 8 are available for input/output and can be connected to any sort of electronic device... including your custom PCB.
It takes simple values :
0 - 00000000
1 - 00000001
2 - 00000010
3 - 00000011
.
.
.
.
255 - 11111111
Check this out for pinouts http://t3.gstatic.com/images?q=tbn:ANd9GcTQy9wmJzTBVAJjMwEdavBoypcwFOXwQ-sA5E2aR-dBLyn1_DDRfg

How can I read a UDP segment in Kernel Space?

I create a module in kernel space that send a UPD segment using socket RAW, but my problem is read the UDP segment from kernel space.
I can read the UDP segment from user space, but when I prove to use "sock_recvmsg" from kernel space, I obtain as result -512
Please, help me!
I don't know why you feel the need to use a raw socket to send/recieve UDP - just use a UDP socket instead.
It may be that the structure you're supplying to sock_recvmsg for the address isn't right.
In general using networking from inside the kernel is a bad idea and should be avoided (not least, it ties your code to a specific kernel version). If you tell us what you're trying to do (ideally in the form of another question) maybe someone can suggest a better way.