alejoseb / Modbus-STM32-HAL-FreeRTOS

Modbus TCP and RTU, Master and Slave for STM32 using Cube HAL and FreeRTOS
GNU Lesser General Public License v2.1
579 stars 192 forks source link

problem in running modus master code for STM32F730r8t6 #110

Closed nirbhow closed 3 months ago

nirbhow commented 3 months ago

Dear sir, i'm trying to use your code for STM32F730R8T6. as modbus master initialized as follows: / Modbus Master initialization / ModbusH.uModbusType = MB_MASTER; ModbusH.port = &huart2; // This is the UART port connected to STLINK in the NUCLEO F429 ModbusH.u8id = 0; //slave ID ModbusH.u16timeOut = 1000; ModbusH.EN_Port = NULL; // No RS485 //ModbusH2.EN_Port = LD2_GPIO_Port; // RS485 Enable //ModbusH2.EN_Pin = LD2_Pin; // RS485 Enable ModbusH.u16regs = ModbusDATA; ModbusH.u16regsize= sizeof(ModbusDATA)/sizeof(ModbusDATA[0]); ModbusH.xTypeHW = USART_HW; //Initialize Modbus library ModbusInit(&ModbusH); //Start capturing traffic on serial Port ModbusStart(&ModbusH); //query initilization telegram.u8id =1;

But i'm facing problem that the code always stuck at function xQueueReceive(modH->QueueTelegramHandle, &telegram, portMAX_DELAY); in the modbus.c library.

when i check the status of USART2.TDR register it is empty.

My second question is how i have to generate a modbus query for slave devices., which function i have to call for modbus query.

alejoseb commented 3 months ago

The behavior that you are observing is expected. The library will wait there for a telegram to be sent through Modbus as a master. To send a request as a master check the master example for the F103 MCU the example in the freertos.c within the core folder

nirbhow commented 3 months ago

Thanks a lot for your advice, I've checked the example in the freertos.c of F103MCU. As per my understanding

  1. i've to use following section in function "void StartTaskModbusMaster(void argument)" .*

    // telegram 0: read registers uint32_t u32NotificationValue; telegram[0].u8id = 1; // slave address telegram[0].u8fct = 3; // function code (this one is registers read) //telegram[0].u16RegAdd = 0x160; // start address in slave telegram[0].u16RegAdd = 0x0; // start address in slave telegram[0].u16CoilsNo = 1; // number of elements (coils or registers) to read // telegram[0].u16reg = ModbusDATA; // pointer to a memory array in the Arduino

and this section is to be added before calling xQueueReceive(modH->QueueTelegramHandle, &telegram, portMAX_DELAY);

I just want to confirm before I start modifying the code.

Regards

On Wed, Aug 14, 2024 at 10:43 AM Alejandro Mera @.***> wrote:

The behavior that you are observing is expected. The library will wait there for a telegram to be sent through Modbus as a master. To send a request as a master check the master example for the F103 MCU the example in the freertos.c within the core folder

— Reply to this email directly, view it on GitHub https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/issues/110#issuecomment-2287870358, or unsubscribe https://github.com/notifications/unsubscribe-auth/BKQW23DGJBBNAZB2BBTHDRDZRLROTAVCNFSM6AAAAABMPOLZRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBXHA3TAMZVHA . You are receiving this because you authored the thread.Message ID: @.***>

-- with regards Nirbhow jap singh EIED

alejoseb commented 3 months ago

I don't quite understand you are doing, notice that you don't need to modify the library. In the example that I pointed you can see that you send a telegram to the queue using a Modbus function.

nirbhow commented 3 months ago

Thanks a lot for your response. i think at the time of my previous email, i got little bit confused to differentiate the purpose of two functions void StartTaskModbusMaster(void argument) in modbus.c and void StartTaskMaster(void argument) in the freertos.c. Now after you reply, what i have understood is that StartTaskMaster(void argument) is used to send telegram to queue and the other function StartTaskModbusMaster(void argument) is for transfer of data from queue to USART.

am i right? or still missing something

Regards

On Fri, Aug 16, 2024 at 3:05 AM Alejandro Mera @.***> wrote:

I don't quite understand you are doing, notice that you don't need to modify the library. In the example that I pointed you can see that you send a telegram to the queue using a Modbus function.

— Reply to this email directly, view it on GitHub https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/issues/110#issuecomment-2292299056, or unsubscribe https://github.com/notifications/unsubscribe-auth/BKQW23ASXHWPBCEQPLVPRHTZRUNIXAVCNFSM6AAAAABMPOLZRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJSGI4TSMBVGY . You are receiving this because you authored the thread.Message ID: @.***>

-- with regards Nirbhow jap singh EIED

alejoseb commented 3 months ago

StartTaskMaster is the master handler task you don't need to worry about that unless you need to modify the library. So my recommendation is to let modbus.c as is.

Please focus on the examples. Specifically, the following line shows how to send a master request using a specific telegram prepared earlier. Study the example first, and second the library if you need to mod it. https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/blob/master/Examples/ModbusF103/Core/Src/freertos.c#L185

Closing this thread, since this is not an issue and I can only provide limited support.

nirbhow commented 3 months ago

Okay, thank you!

On Wed, Aug 21, 2024 at 10:48 PM Alejandro Mera @.***> wrote:

StartTaskMaster is the master handler task you don't need to worry about that unless you need to modify the library. So my recommendation is to let modbus.c as is.

Please focus on the examples. Specifically, the following line shows how to send a master request using a specific telegram prepared earlier. Study the example first, and second the library if you need to mod it.

https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/blob/master/Examples/ModbusF103/Core/Src/freertos.c#L185

Closing this thread, since this is not an issue and I can only provide limited support.

— Reply to this email directly, view it on GitHub https://github.com/alejoseb/Modbus-STM32-HAL-FreeRTOS/issues/110#issuecomment-2302591834, or unsubscribe https://github.com/notifications/unsubscribe-auth/BKQW23BQS4GOUDBABONMIULZSTDW7AVCNFSM6AAAAABMPOLZRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBSGU4TCOBTGQ . You are receiving this because you authored the thread.Message ID: @.***>

-- with regards Nirbhow jap singh EIED