Skip to main content
mehmet.karakaya
Associate III
August 6, 2013
Question

modbus ascii wants 7 bit word length - stm32 has 8 bit ?

  • August 6, 2013
  • 5 replies
  • 2105 views
Posted on August 06, 2013 at 17:10

#define USART_WordLength_8b ((uint16_t)0x0000)

#define USART_WordLength_9b ((uint16_t)0x1000)

hello forum,

I am trying to modbus ascii comunicate with a delta operator panel

the settings of OPanel is 7 bit data, 1 stop, 1 parity

however my STM32F103 has only the above settings

why there is no 7 bit wordlength ? what can I do else ?

thanks

#modbus-ascii-stm32f103

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    August 6, 2013
    Posted on August 06, 2013 at 17:15

    7-bit + 1-bit (parity odd or even) = 8-bit

    You program the STM32 as 8-bit, and enable parity. This will enable 7N1 or 7O1 in the classic sense. For 8N1 or 8O1 you'd configure in 9-bit mode.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    mehmet.karakaya
    Associate III
    August 12, 2013
    Posted on August 12, 2013 at 20:23

    hello ,

    I did what you said ; I setup serial port 7Even1 ( 8 bit word length + even parity )

     

    what I want is to connect my STM32F103 to Delta HMI operator panel with modbus ascii

    when I request some internal memory of HMI , it responds with an ascii array just like modbus standart says

    as you know modbus ascii has terminating characters 0xd 0xa  however

    when I watch the received ( by the STM32 ) characters I see 0x8d and 0xa

    how can a serial port receive an 8 bit character with 7E1 setup ?

    thank you

    PS. delta HMI is also setup 7 E 1

    Tesla DeLorean
    Guru
    August 12, 2013
    Posted on August 12, 2013 at 21:18

    That should have been 7E1 and 8E1 above.

    You'll want to mask the data from USARTx->DR to remove the parity bit.

    Basically USART_ReceiveData(USART1) & 0x7F; for the 7-bit case and USART_ReceiveData(USART1) & 0xFF; for the 8-bit case. The register is 9-bits long.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    itay
    Visitor II
    November 11, 2014
    Posted on November 11, 2014 at 18:15

    I am trying to get 8E1 to work right now I get 7E1 , I have a board with  

    32bit STM32F427 Cortex M4 

    and I using the operation system to open the Uart etc, how do I set the

    USART_WordLength_9b to make the STM send 8E1

    Itay

    Tesla DeLorean
    Guru
    November 11, 2014
    Posted on November 11, 2014 at 18:58

    I am trying to get 8E1 to work right now I get 7E1 , I have a board with 32bit STM32F427 Cortex M4 and I using the operation system to open the Uart etc, how do I set the USART_WordLength_9b to make the STM send 8E1

    Itay

    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Enable USART1 Clock */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); /* Connect PB6 to USART1_Tx*/
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); /* Connect PB7 to USART1_Rx*/
    /* Configure USART1 Tx & Rx as alternate function */
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    USART_InitStructure.USART_BaudRate = 9600;
    USART_InitStructure.USART_WordLength = USART_WordLength_9b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_Even;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init(USART1, &USART_InitStructure); /* Configure USART */
    USART_Cmd(UART1, ENABLE); /* Enable the USART */

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..