Skip to main content
shaktishekhar789
Associate III
February 26, 2013
Question

STM32W108xx UART implementation

  • February 26, 2013
  • 23 replies
  • 3604 views
Posted on February 26, 2013 at 10:10

Hi 

I want to show the output(i.e. sended data) on tera term terminal. How to setup tera term for that.(I am using UART for serial communication in which i am sending data from one port and receiving from other one.) Please reply me asap.

    This topic has been closed for replies.

    23 replies

    Tesla DeLorean
    Guru
    February 26, 2013
    Posted on February 26, 2013 at 15:41

    Attach cable, open window select COM port, baud rate, and parity/stop bit settings.

    Perhaps you work with someone who can walk you through the basics?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 26, 2013
    Posted on February 26, 2013 at 17:27

    Thanks for reply. But I need more help from ur side. I am just working on Device by myself and i am trying to learn the basics programming on it. STM32W108xx dosen't have onchip uart. How I will input data and get those data on receiving end and How I will watch those data.

    Tesla DeLorean
    Guru
    February 26, 2013
    Posted on February 26, 2013 at 19:19

    At least some of the STM32F108W parts have a USART.

    The USART should function and program in a manner similar to other STM32F1 series parts. Have you reviewed some of the firmware examples?

    Which specific part are you using?

    What specific board are you using?

    Perhaps you can cite a schematic for your board.

    Perhaps you can get an EVAL series board from ST that has serial ports built on, and with which you can experiment before jumping in the deep end of the pool?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 27, 2013
    Posted on February 27, 2013 at 06:15

    Thanks for your reply.I am using STM32W108CBT6 in which UART having wired connectivity. I want to send and receive data through UART . Now tell me how to do that. 

    Tesla DeLorean
    Guru
    February 27, 2013
    Posted on February 27, 2013 at 16:29

    // STM32W108 UART1 (PB.1 Tx, PB.2 Rx) sourcer32@gmail.com
    #include ''stm32w108xx.h''
    void outstring(char *s)
    {
    while(*s)
    {
    /* Loop until transmit data register is empty */
    while (UART_GetFlagStatus(SC1_UART, UART_FLAG_TXE) == RESET);
    UART_SendData(SC1_UART, (uint8_t)*s++);
    }
    }
    int main(void)
    {
    UART_InitTypeDef UART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    /* Disable the serial controller interface */
    UART_Cmd(SC1_UART, DISABLE);
    /* Configure (PB1) UART Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    /* Set pull-up on UART Tx pin */
    GPIO_SetBits(GPIOB, GPIO_Pin_1);
    /* Configure (PB2) UART Rx as input with pull-up */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    /* Set pull-up on UART Rx pin */
    GPIO_SetBits(GPIOB, GPIO_Pin_2);
    /* UARTx configured as follow:
    - BaudRate = 115200 baud
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - Hardware flow control disabled (RTS and CTS signals)
    */
    UART_InitStructure.UART_BaudRate = 115200;
    UART_InitStructure.UART_WordLength = UART_WordLength_8b;
    UART_InitStructure.UART_StopBits = UART_StopBits_1;
    UART_InitStructure.UART_Parity = UART_Parity_No;
    UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_Disable;
    /* UART configuration: Set up the parameters specific for the UART operating mode */
    UART_Init(SC1_UART, UART_InitStruct);
    /* Enable the UART peripheral */
    UART_Cmd(SC1_UART, ENABLE);
    while(1)
    outstring(''Welcome to wherever you are!
    
    '');
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    February 27, 2013
    Posted on February 27, 2013 at 16:49

    Or with interrupts, something like this

    // STM32W108 UART1 IRQ TX/RX Loop (PB.1 Tx, PB.2 Rx) sourcer32@gmail.com
    #include ''stm32w108xx.h''
    volatile char StringLoop[] = ''The quick brown fox jumps over the lazy dog
    
    '';
    /**************************************************************************************/
    void SC1_IRQHandler(void)
    {
    static int tx_index = 0;
    static int rx_index = 0;
    if (UART_GetITStatus(SC1_IT, UART_IT_TXE) != RESET)
    {
    /* Write one byte to the transmit data register */
    UART_SendData(SC1_UART, StringLoop[tx_index++]);
    if (tx_index >= (sizeof(StringLoop) - 1))
    tx_index = 0;
    /* Clear the UART_IT_TXE pending interrupt, probably overkill */
    UART_ClearITPendingBit(SC1_IT, UART_IT_TXE);
    }
    if (UART_GetITStatus(SC1_IT, UART_IT_RXNE) != RESET) // Received characters modify string
    {
    /* Read one byte from the receive data register */
    StringLoop[rx_index++] = UART_ReceiveData(SC1_UART);
    if (rx_index >= (sizeof(StringLoop) - 1))
    rx_index = 0;
    /* Clear the UART_IT_RXNE pending interrupt, probably overkill */
    UART_ClearITPendingBit(SC1_IT, UART_IT_RXNE);
    }
    }
    /**************************************************************************************/
    void NVIC_Config(void)
    {
    NVIC_InitTypeDef NVIC_InitStructure;
    /* Enable the SC1 Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = SC1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    }
    /**************************************************************************************/
    int main(void)
    {
    UART_InitTypeDef UART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    NVIC_Config();
    /* Disable the serial controller interface */
    UART_Cmd(SC1_UART, DISABLE);
    /* Configure (PB1) UART Tx as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    /* Set pull-up on UART Tx pin */
    GPIO_SetBits(GPIOB, GPIO_Pin_1);
    /* Configure (PB2) UART Rx as input with pull-up */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    /* Set pull-up on UART Rx pin */
    GPIO_SetBits(GPIOB, GPIO_Pin_2);
    /* UARTx configured as follow:
    - BaudRate = 115200 baud
    - Word Length = 8 Bits
    - One Stop Bit
    - No parity
    - Hardware flow control disabled (RTS and CTS signals)
    */
    UART_InitStructure.UART_BaudRate = 115200;
    UART_InitStructure.UART_WordLength = UART_WordLength_8b;
    UART_InitStructure.UART_StopBits = UART_StopBits_1;
    UART_InitStructure.UART_Parity = UART_Parity_No;
    UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_Disable;
    /* UART configuration: Set up the parameters specific for the UART operating mode */
    UART_Init(SC1_UART, UART_InitStruct);
    /* Enable the UART peripheral */
    UART_Cmd(SC1_UART, ENABLE);
    /* Enable the SC1_IT Transmit interrupt: this interrupt is generated when the
    UART transmit data register is empty */
    UART_TriggerEventConfig(SC1_IT, UART_IT_TXE, SC_TriggerEvent_Level);
    UART_ITConfig(SC1_IT, UART_IT_TXE, ENABLE);
    /* Enable the SC1_UART Receive interrupt: this interrupt is generated when the
    SC1_UART receive data register is not empty */
    UART_ITConfig(SC1_IT, UART_IT_RXNE, ENABLE);
    while(1);
    }
    /**************************************************************************************/

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 27, 2013
    Posted on February 27, 2013 at 17:58

    Thanks for reply. But is it possible to watch the output on tera term terminal ? if yes then plz tell me how?

    Tesla DeLorean
    Guru
    February 27, 2013
    Posted on February 27, 2013 at 19:15

    Thanks for reply. But is it possible to watch the output on tera term terminal ? if yes then plz tell me how?

     

    Sure, I'm working on the premise ''I am using STM32W108CBT6 in which UART having wired connectivity'', so is it wired or not? How?

    Suggest you answer some of my previous questions.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    shaktishekhar789
    Associate III
    February 27, 2013
    Posted on February 27, 2013 at 19:54

    Thanks for reply. Actuall on STM32W108CB  UART is wired connected. But I am not connecting it. I want to show the sended packet on terminal.

    Tesla DeLorean
    Guru
    February 27, 2013
    Posted on February 27, 2013 at 21:42

    To which COM port is it attached? Say COM3, then you'll need to configure Tera Term to COM3 115200 Baud, 8 Bit, No Parity, 1 Stop.

    The STM32 will not interface directly to RS232 ports, it uses 3V CMOS levels, and will either need a CMOS Serial to USB type adapter, or a MAX232 type converter.

    If you are new to all this stuff, I will again, recommend you get a board that has the interfaces on you require, learn how to use that, and then progress to more complicated chip level interfacing. Jumping in the deep end of the pool, and not being able to swim, will likely get you drowned.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..