Connecting two PC's via RS485 (USB to RS485 converter) - modbus

I'm trying to establish Modbus RTU connection (for learning purposes) between two PC's (Win10). I'm using two USB to RS485 converters (D- connected together and D+ also connected together). This converters are connected to USB2.0 ports.
USB to RS485 converter
So I'm using "Modbus Poll" and "Modbus Slave" from "modbus tools".
First computer act as slave and has the following settings:
Slave configuration
Slave definition
Second computer act as master and has following settings:
Master configuration
Master definition
And my problem is, everytime i get "Timeout error":
Timeout error
So, what I'm doing wrong? I'm pretty sure converters are not damaged, because Win10 detecs them.
After all I just want to send simple value to another computer (via Modbus RTU) :)
Thanks

Well, this is not a real answer but I can provide some debugging suggestions.
In the past, I had problems with that RS-485 hardware you're using. It didn't work and I'm not sure why. The one I have uses a strange logic to drive DE pin of the MAX485. If I remember correctly, it inverts the TX line coming from CH340G using a NAND gate and feeds it to DE pin. I'm not sure if it was the problem, but I don't think it's a good design.
You may need pull-up and pull-down resistors on RS-485 lines to prevent it from floating when no driver is driving the bus. Some converters include them internally. Also, you may need 120 ohm termination resistors on both ends.
Instead of working with RS-485, you can simply use TTL logic for testing purposes. Use two USB-TTL converters, connect TX to RX (cross connection).
When debugging communication buses (USART, SPI, I2C etc.) always use logic analyzers. Even the cheapest one saves hours of debugging time.

you need to install proper drivers. I used following link which includes a how to video as well as download link for the drivers . Also disable RTS as its 2 wire RS485 so RTS cant be used.

Related

stm32f407 ADC cannot read data

i need some help.
i built custom board and had problem with my adc reading, it's not software problem...yet.
my question is really hardware. it might be my lack of understanding from reading STM32f407 manual book. so i have my microcontroller STM32f407zgt6 with LQFP144 package. and i fail to read the ADC. i use stm32cubeide for programming but my programming is very simple since i follow this link https://deepbluembedded.com/stm32-light-sensor-ldr-interfacing-ambient-light-sensor-project/. my question is:
do i have to connect pin VREF+ to VDDA externally to activate the ADC?
cause in STM32f103 with LQFP48. the VREF+ pin doesn't exist and the manual says that it's internally connected to VDDA pin. can i assume that the same rules can be applied to STM32f407ZGT6? or the external connection of VREF+ -> VDDA is mandatory since it is using LQFP144 package? cause i didn't connect it in my custom board and left the VREF+ pin hanging.
i just wanna use the ADC VREF+ = VDDA in LQFP144, so i assume that it is internally connected, is my assumption wrong?
here is my confusion on STM32F4 manual:
and
please help. i might have a false design on my custom board then...
In the smaller packages Vref is connected internaly just to save external pins.
In the larger packages Vref can be connected to a different power rail - more stable or slightly different, like 3.0V. And there is no configuration options to connect Vref to Vdda. The datasheed states explicitly in the "General operation conditions" chapter:
And in most cases, Vref is just wired to Vdda.

How to intercept J1939 CAN messages?

I'm building a HIL/SIL test with Simulink, which tests the Vehicle Control Unit(VCU) from a vehicle. This VCU talks with a Power Distribution Module(PDM) over a J1939 CAN network. The PDM handles the in- and outputs from switches and to actuators and puts the information on the CAN bus. The VCU then knows what the PDM is seeing from connected sensors. In turn, the VCU puts info on the CAN bus on how the PDM should control the connected actuators.
My laptop is hooked to the same CAN bus with a Vector adapter and Simulink.
To test the VCU, I need to mimic the PDM and send messages to the VCU as if I were the PDM. The VCU then has to take the correct actions and control the real PDM accordingly.
Obviously, if I just mimic the PDM, my messages will interfere with those sent from the real PDM. So basically, I need the PDM to shut up and only listen. I do the talking for the PDM. However, the PDM is not configurable in a listen-only mode, so I have to intercept all messages it sends so they never arrive at the VCU.
My idea was that i'd detect(by observing the arbitration field of all messages) when the PDM starts sending, and pull a bit down in the arbitration field. It'd recognise the priority of my 'message' over its own, and it'd stop transmitting. It'd be as if the CAN bus is always to busy to give room to the PDM. This would shut up the PDM without it throwing errors. But other suggestions are welcome.
So (how) is it possible to intercept J1939 CAN messages in MATLAB/Simulink, or with a separate CAN controller?
Here is an idea, how to realize what you are looking for. You need some extra hardware, however.
This is the rough outline:
Setup a CAN-gateway device, which has two independent CAN-interfaces can0 and can1.
Disconnect the PDM from the CAN-bus and connect it to one of the interfaces of your CAN-gateway, e.g. can0
Connect the second interface of the CAN-gateway, can1, to the original CAN-bus, which also includes your laptop and the VCU
Program your CAN-gateway to forward all incoming CAN-frames on can1 to the can0 interface
As you want to ignore all messages from the PDM, simply ignore the CAN-frames coming in on interface can0 and not forward them to can1
Example, how to realize such a CAN-gateway:
Hardware: Use a Raspberry Pi and a CAN extension board with two can-interfaces, such as the PiCAN2 duo board.
Software: Write a small program to forward traffic between the interfaces can0 and can1, using socketcan, which is already included in the Linux kernel.
In case your devices are communicating via the higher layer J1939 transport protocol, you might also need to get the J1939 transport protocol running on the Raspberry Pi. If you are simply using 29-bit indentifiers with a maximum payload of 8 byte of data, this should also not be necessary.
Alternatively, you could also use a more expensive commercial solution, this CAN-Router for example.
Your original idea:
I think what you are envisioning is technically feasible, but might have some other drawbacks.
As the drivers of can controllers typically don't expose interfaces to interactively manipulate CAN-frames while their transmission is still ongoing, you could directly address a can-transceiver from a microcontroller
A few researchers realized a CAN Denial of service attack by turning the first recessive bit in a CAN-frame after the arbitration ID into a dominant bit for certain selected CAN-IDs. They used an Arduino Uno and a Microchip MCP2551 E/P CAN transceiver. The code used is also available online. As this interactive manipulation of CAN-frames during transmission is related to what you are looking for, this could be a good starting point for you.
Still I see some drawbacks, when you silence the PDM this way:
You will not only silence the PDM this way, but also (at least) delay the transmission of other nodes on the CAN-bus with arbitration IDs that have
lower priority than the messages from the PDM
It is very likely that the PDM will go into some error state, when it is not able to successfully send its CAN-frames to the bus after a certain number of retries
Yet another idea:
In case you are able to adapt the software of the VCU, change it in a way that it does not consume the CAN-frames from the PDM, but CAN-frames from your laptop by using different CAN-IDs for the same messages. You will have to change the dbc-file for that purpose.

Reading KNX using Raspberry Pi 3 GPIO

My dad wants me to make kind of a smart home.
I would like to interface with KNX (a home automation protocol) using the GPIO on a Raspberry Pi 3. Ideally, I would like to build a web interface for it, but I don't have a clue how to interface with KNX in the first place.
Any suggestions?
It wont make sense for you to interpret and understand the KNX bus communication protocol directly. There is a massive specification behind the KNX bus which deals with so many problems from device addresses to collision detection. It would take years to master it and unless you develop KNX devices you really should not spend your time on it. You will be better off by doing the following:
Buy a KNX/IP gateway/interface such as https://www.mdt.de/en/products/product-detail/system-devices/system-devices/ip-interface.html
Understand that KNX bus traffic can be routed/tunneled to your home LAN/WIFI
Play around with one of the KNX libraries on GitHub. For example for C#: https://github.com/search?l=C%23&q=knx&type=Repositories&utf8=%E2%9C%93
If you want, have a look at my experimental .NET Core project which starts a radio streaming process when someone touches a button (in the bathroom in my case). It runs on any operation system (so Raspberry and Linux are fine) and you can find it here: https://github.com/ThomasZeman/KnxNetCore
check this website : http://michlstechblog.info/blog/raspberry-pi-eibknx-ip-gateway-and-router-with-knxd/ that might help. also there are special knx 2 ip devices sold by electronic stores
You can't connect the KNX bus to anything on the pi. The KNX bus has its own electrical specs, and you need specialized hardware to connect to it.
Such hardware is available, but probably a KNXnet/IP device (such as the Siemens N148) is a better option.
I see two options for you:
A) use an IP interface (e.g. the ones from MDT) and access the IP interface from your raspberryPi (e.g. with http://calimero-project.github.io/)
B) use a TPUART controller, which makes KNX TP telegrams accessible (r/w) to UART - see http://www.konnekting.de/konnekting-lernen/l1-knx-mit-arduino/

SH72867 with I2C

I am using ‘SH72867(Renesas)’ connect with ‘EEPROM(24LC04B)’ . In the customer’s document at ‘address 0xF0 of EEPROM have data 0x5555’, But when I reading from this address always return ‘0xFFFF’ and same with other address.
I can’t write to EEPROM too.
I used I2C sample of Renesas but not run.
Do you have any suggestion about setting up I2C?
Sorry for my bad English and no clear explanation.
Any help apprciated,
Thanks
Verify the common issues:
Data and clock are connected properly.
Pull up resistor on clock and data connected to VCC.
Loop the I2C read request, connect scope and verify that I2C signals are OK. In addition check the ACK bit.
Verify clock is lower then 400kHz.
When using code examples, they usually fit to specific board. Verify that the code example configuration is the same as your board.
Some MCU may have more then one I2C pinout options. The code example might use I2C module that connected to diffrent pins.

Power save mode STM32F205RG

I am using STM32F205RGT6 Cortex-M3 microcontroller and coding with IAR Embedded Workbench.
I plan to keep the microcontroller in a power saving mode most of the time except when an external component tries to either communicate via SPI (the STM32 microcontroller is meant to be a SP slave) or via USB.
One external compinent is connected via SPI (PB12-15) and PC is connected via USB (PA11-12).
The communication works fine - I have tested both the SPI as well as USB.
I figured that once I am done setting up SPI and USB I will call a power saving function and add the same function call at the end of interrupt service routines. I have found PWR_EnterSTANDBYMode and PWR_EnterSTOPMode (in stm32f2xx_pwr.h) both of which I tried using.
However with such arrangement I cannot establish any communication (SPI or USB) with the microcontroller.
Is there something extra that needs to be configured (for example which pins should wake the microcontroller up)?
Am I using wrong function? Or wrong header file?
Can you point me to an example resembling such case (I could not find anything similar on ST's website)?
Any constructive feedback would be welcome.
In the mean time I found the application note AN3430 (http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/APPLICATION_NOTE/DM00033348.pdf) which is somehow more digestible (only 38 pages) which gives an excellent overview on power saving in the microcontroller.
Since I don't have access to PA0-WKUP (the wake-up pin) I had to discard using stand-by. Seems that just a simple sleep mode in main loop - by calling __WMI(); - should lower current consumption enough in my case. I might consider stop mode if sleep mode isn't enough but I will have read fragments of datasheet on configuration of EXTI registers that the application notepoints to.