cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus/RTU on STM32F303

ArturasV
Senior
Posted on September 16, 2014 at 11:54

Hello everyone, i am implementing Modbus/RTU protocol on STM32F303 and i want to check something, because i don't know if i understand this correct. According to RM ModBus/RTU: 

In this mode, the end of one block is recognized by a �silence� (idle line) for more than 2 

character times. This function is implemented through the programmable timeout function. 

The timeout function and interrupt must be activated, through the RTOEN bit in the 

USART_CR2 register and the RTOIE in the USART_CR1 register. The value corresponding 

to a timeout of 2 character times (for example 22 x bit time) must be programmed in the RTO 

register. When the receive line is idle for this duration, after the last stop bit is received, an 

interrupt is generated, informing the software that the current block reception is completed.

so:

1) I configure my timeout function:

 USART_SetReceiverTimeOut(USART3, 35); // Line idle for 35 bits

 USART_ReceiverTimeOutCmd(USART3, ENABLE); // Enable receiver timeout function

2) Enable receiver timeout interrupt

USART_ITConfig(USART3, USART_IT_RTO, ENABLE); 

3) In USART IRQ Handler:

void USART3_IRQHandler(void)

{

if(USART_GetITStatus(USART3, USART_IT_RTO) != RESET)

  {

    USART_ClearITPendingBit(USART3, USART_IT_RTO); // Clear RTO bit

    ......

  }

}

Communication flows, i tested it and it works, so if you don't have any observations that i did something wrong, my question is as follows:

How this function actually works: USART_SetReceiverTimeOut(USART3, 35);

Does this mean that after last stop bit is received, interrupt will be generated after 35 baud clocks? I mean if my USART baud rate is 9600, so this interrupt will be generated after (1000ms/9600)*35 = 3,65ms , after last stop bit is detected ? 

#need-help:modbus-rtu-stm32f303vc
6 REPLIES 6
frankmeyer9
Associate II
Posted on September 16, 2014 at 12:45

In this mode, the end of one block is recognized by a “silence�? (idle line) for more than 2 character times.

 

This is not correct.

The specification

http://www.modbus.org/specs.php

(Modbus Serial Line Protocol and Implementation Guide V1.02

http://www.modbus.org/docs/Modbus_over_serial_line_V1_02.pdf

) states 3.5 character times, which ought to be strictly observed for baudrates up to 19200.

For higher baudrates, fixed times should be used (see page 13).

ArturasV
Senior
Posted on September 16, 2014 at 13:32

Thanks for your quick answer fm, but i know this, thats why i set: 

 USART_SetReceiverTimeOut(USART3, 35); // Line idle for 35 bits

. (i assume that my packet has 10bits)

I just copied what RM states, but that wasn't what i was asking. Im interested is if that function works as i think (described my understanding in first post).

Thanks anyway,

Cheers.

frankmeyer9
Associate II
Posted on September 16, 2014 at 14:37

I would understand the RM the same way.

While I never implemented the Modbus protocol on STM32, implementing and testing shouldn't be too difficult.

I hope you are aware that not all USARTs support this receiver timeout feature (RM page 793).

manjunathele
Associate
Posted on September 30, 2016 at 12:28

Hi Arth, I am new bee. &  I want start task on Modbus RTU ,so I need help on STM32F303 DISCOVERY,can you please share a Modbus project file on stm32f303 for my reference.

Posted on September 30, 2016 at 17:57

You are unlikely to get a response on a 2-year old thread. Perhaps try Google, or reviewing chip documentation. Discuss with your project supervisor.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
manjunathele
Associate
Posted on October 01, 2016 at 12:11

Hi,

Thanking for your reply.

Even stm support team can respond and solve my problem.

Regards,

Manjunath