Modbus setting

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
markavo42
Posts: 8
Joined: Sat Nov 24, 2018 11:47 am
Has thanked: 1 time
Been thanked: 1 time

Modbus setting

Post by markavo42 »

Hello

Is there a way to change the default modbus setting
Data bits / Parity / stop bits.

What is the default settings ? as i can only seem to find and change the baud rate.

My slave only allows the configuration of multiple speeds but with fixed:
1 / 8 bits / Even

I think this is my reason why i see no responses from the slave to the arm master using flowcode.
Is there a way to just change the parity to Even from none ?

Thank you. :D

markavo42
Posts: 8
Joined: Sat Nov 24, 2018 11:47 am
Has thanked: 1 time
Been thanked: 1 time

Re: Modbus setting

Post by markavo42 »

Anyone any ideas or comments please.

Thank you.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Modbus setting

Post by Benj »

Hello,

Currently the mode is.

1 stop bit
8 data bits
no parity

Which ARM device are you using and I will investigate how tricky adding parity would be. It might be very simple to switch on.

If you're using the ST-ARM devices then it looks like it should be fairly simple.

Simply edit the following file using a text editor.

"C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\STARM\STARM_CAL_UART.c"

Please note that the ProgramData folder is hidden by default so simply paste the full path into a Windows explorer address bar.

C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\STARM\


Look around line 228 and you should see a line of code like this.

Code: Select all

MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_NONE;
Try changing it to this instead.

Code: Select all

MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_EVEN;
Save the file and hopefully that is all that is required.

If you run the update system (help -> Check for updates) it will flag the CAL .c file as invalid and if downloaded will overwrite with the official file so you can easily go back to stock at any point if you need to.

markavo42
Posts: 8
Joined: Sat Nov 24, 2018 11:47 am
Has thanked: 1 time
Been thanked: 1 time

Re: Modbus setting

Post by markavo42 »

Thank you. Just tested

Leaving the parity as NONE in the STARM_CAL_UART.c
I the monitor the coms on the 9 way’D application set to NONE
a good result SENT IS

01 05 00 01 ff 00 dd fa


Setting the parity as EVEN in the STARM_CAL_UART.c
I the monitor the coms on the 9 way’D application set to EVEN
The bad result SENT IS

81 41 81 00 77 ff


I check again by changing the monitoring application to NONE leaving Leaving STARM_CAL_UART.c
on EVEN.
The bad result SENT IS

81 05 00 81 ff 00 dd fa


I’m using STARM 746 any more suggestions please to allow me to change to EVEN as the salve is fixed on EVEN i wish to talk to.
Is it something to do with the 9th bit do i need to enable this some way please ?

Thank you for you support. :D

markavo42
Posts: 8
Joined: Sat Nov 24, 2018 11:47 am
Has thanked: 1 time
Been thanked: 1 time

Re: Modbus setting

Post by markavo42 »

OK some news

by changing to EVEN it did not help but by also changing 8B to 9B and to EVEN it worked !
but i have a new issue i also have a display connected to a different UART and i guess this is parity NONE so as you may of guessed now the display will not talk to the ST-ARM

Any work around for this please ?
Changing 8B to 9B will it cause any more issues you can think of ?

Thank you,



//MX_UART_HANDLE_X.Init.WordLength = UART_WORDLENGTH_8B;
MX_UART_HANDLE_X.Init.WordLength = UART_WORDLENGTH_9B;

Code: Select all

		#if(MX_UART_DBITS_X == 9)
			MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
		#else
			//MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_8B;
			MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
		#endif

		MX_UART_HANDLE_X.Init.StopBits     = UART_STOPBITS_1;
		MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_EVEN;
		MX_UART_HANDLE_X.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
		MX_UART_HANDLE_X.Init.Mode         = UART_MODE_TX_RX;
		MX_UART_HANDLE_X.Init.OverSampling = UART_OVERSAMPLING_16;

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Modbus setting

Post by Benj »

Hello,

You should be able to use the preprocessor to do different code.

For example to override only channel 1 and leave other channels as was.

Code: Select all

#if (MX_UART_CHANNEL_X == 1)

		MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
		MX_UART_HANDLE_X.Init.StopBits     = UART_STOPBITS_1;
		MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_EVEN;

#else

		#if(MX_UART_DBITS_X == 9)
			MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
		#else
			MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_8B;
		#endif

		MX_UART_HANDLE_X.Init.StopBits     = UART_STOPBITS_1;
		MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_NONE;

#endif

markavo42
Posts: 8
Joined: Sat Nov 24, 2018 11:47 am
Has thanked: 1 time
Been thanked: 1 time

Re: Modbus setting

Post by markavo42 »

Thank you! :D

That did the trick.

Code: Select all

	#if (MX_UART_CHANNEL_X > 0)


		/* Enable USARTx clock */
		MX_UART_CLOCK_X();


		MX_UART_HANDLE_X.Instance          = MX_UART_USART_X;

		MX_UART_HANDLE_X.Init.BaudRate     = MX_UART_BAUD_X;


////////////ADDED CHANNEL 3 FOR EVEN PARITY////////////

		#if (MX_UART_CHANNEL_X == 4)

      			MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
      			MX_UART_HANDLE_X.Init.StopBits     = UART_STOPBITS_1;
      			MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_EVEN;

		#else

			#if(MX_UART_DBITS_X == 9)
				MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_9B;
			#else
				MX_UART_HANDLE_X.Init.WordLength   = UART_WORDLENGTH_8B;
			#endif

			MX_UART_HANDLE_X.Init.StopBits     = UART_STOPBITS_1;
			MX_UART_HANDLE_X.Init.Parity       = UART_PARITY_NONE;
		#endif

////////////ADDED CHANNEL 3 FOR EVEN PARITY////////////


		MX_UART_HANDLE_X.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
		MX_UART_HANDLE_X.Init.Mode         = UART_MODE_TX_RX;
		MX_UART_HANDLE_X.Init.OverSampling = UART_OVERSAMPLING_16;

Post Reply