Arduino_Profibus_DP
Arduino_Profibus_DP copied to clipboard
some issue
We wanted to do a replacement for an old profibus DP device and I found this repository which is easy transformer to ESP-IDF or PicoSDK. It does what I need successfully, Thanks a lot! I encountered two issues in use, as follows:
1, Line 689 need replace to profibus_send_CMD(SD2, DATA_LOW, 0, &uart_buffer[7], Output_Data_Size); // send data
https://github.com/tuenhidiy/Arduino_Profibus_DP/blob/d4603382e719bc186f36b2f058f3578deac56685/Arduino_Profibus_DP.ino#L685-L689
2, Here just accept function code = 0x5D or 0x7D, but 0x6D also is a good function code. According https://www.felser.ch/profibus-manual/funktionscode.html, 0x6D is first frame with FCV. For our application, we don't have to strictly follow the protocol, we just need to add 0x6D to the if then it works well.
https://github.com/tuenhidiy/Arduino_Profibus_DP/blob/d4603382e719bc186f36b2f058f3578deac56685/Arduino_Profibus_DP.ino#L662-L664
cheers
thank you @feecat . I'm trying this code on s7400 plc and uno. But doesn't work as expected. If there are any modifications other then the above mentioned in the arduino code, please provide it, also whether gsd file is ok or any modifications required?
hi @whatdtech , In my project it works fine. maybe you need a logic analyze for rs485 communication, also you need read mostly important documents on https://www.felser.ch/profibus-manual/telegrammformate.html
@feecat Worked fine for me with uno but I'm trying to adapt the code for esp32 and Arduino framework.
@whatdtech The uart response speed of esp32 is slower than stm32/ch32v. But esp32 is dual-core. In my code, I had isolate one core to do UART communication, Otherwise, UART communication will be affected by FreeRTOS scheduling. profibus_RX() will be your data process loop. You need more work to do real-time response not profibus communication, Anyway its little diffcult. Im suggest to use stm32 and stm32cubeide, cuz arduino framework is too slow when compile.
And if you really want to use esp32, i cannot provide code but a little tips:
- Use esp-idf with vscode
- xTaskCreatePinnedToCore() pinned uart loop to core 1
- use portMUX_INITIALIZER_UNLOCKED spinlock to disable rtos scheduling in core 1, enter critical and never release it.
- check rx logic level to check if frame finish, cuz in 1.5MHz uart need quicklly response.
- read frame use UART.fifo.rw_byte by 1 byte, write frame use uart_ll_write_txfifo() and check status.st_utx_out.
thank you @feecat . any example of yours with stm32?