cancel
Showing results for 
Search instead for 
Did you mean: 

how to debug (terminal) a UART modul connected to usart2 ?

sam239955
Associate II
Posted on December 07, 2011 at 02:00

Hi, its me again :)

i have my stm32f103ze USART2 with 38400 baud connected to a bluetooth modul that uses rx, tx, rts, cts.

I must send some commands to the bluetooth device via USART:

    /* USART2 Clock an*/

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    /*Init USART2 USART2: CTS PA0, RTS PA1, TX PA2, RX PA3 */

    

    /* Configure USART2 RTS and USART2 Tx as alternate function push-pull */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    

    /* Configure USART2 CTS and USART2 Rx as input floating */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_3;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    

    USART_InitStructure.USART_BaudRate = 38400;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    USART_InitStructure.USART_Parity = USART_Parity_No;

    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;

    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    USART_Init(USART2, &USART_InitStructure);

    USART_Cmd(USART2, ENABLE);

    /* Init BT */

    IMU_Led1_On();

    Delay(100);

    send_string(''STWMOD=0\r\n'');

    send_string(''STBD=38400\r\n'');

    Delay(200);

    send_string(''STNA=IMU\r\n'');

    

    send_string(''STAUTO=0\r\n'');

    send_string(''STOAUT=1\r\n'');

    send_string(''STPIN=0000\r\n'');

    Delay(200);

    send_string(''INQ=0\r\n'');

    Delay(200);

/* send_string function for BT */

void send_string(const char *str)

{

    while (*str)

    {

        while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

        USART_SendData(USART2, *str++);

    }

}

How can I check the Echo from the Module in my Keil Debugger?

I cant connect the modul to my PC RS232 because its hard mounted (SMD) on the PCB.

And is there a possiblity in the debugger to write commands for testing if the commands that im sending are correct?

with regards

sam

3 REPLIES 3
Posted on December 07, 2011 at 02:30

I tend to use USART1 for the debug terminal, and forward data to that, either directly, or by using printf(),putchar(),scanf() and getchar() with retargeted hosting functions.

If you really can't get to any data out of the USARTs, you could sprintf(), or memcpy, to a buffer in the STM32, and then view that using a JTAG memory view window.

For communicating back, you could use a memory window to type in a message, and then set another variable to indicate/semaphore that your application should examine the data there.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ersan
Associate II
Posted on December 07, 2011 at 22:52

is there a example project to download?

I have got a Keil MCBSTM32 and I'm trying the same.
Posted on December 08, 2011 at 00:44

is there a example project to download? I have got a Keil MCBSTM32 and I'm trying the same.

 

Well there should be a bunch of projects in the \Keil\ARM\Boards\Keil\MCBSTM32 directory. Can you be more precise about what it is you want to do?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..