November 24, 2024, 12:46:36 AM

STM32-P407 RS232

Started by radu, June 21, 2013, 05:55:45 PM

Previous topic - Next topic

radu

---Edit---
Hi again,

I noticed the Rx and Tx pins of COM2 are physically only connected to GPIOD - the one I cannot use because of the external memory.

From COM1 only USART6 Rx seems to be connected to GPIOG pin 9. This is working, I receive interrupts. But what do I do about Tx?

If I solder RX_BOOT_E and TX_BOOT_E, can I use COM1 -> USART3 -> GPIOC pins 10 and 11? Like:

    ...
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); /* Tx  */
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3); /* Rx  */
    ...
If this works, would it affect other functionality of the system?

Thanks,
Radu


---original message---
Hi,

I want to use USART3 for serial communication with my PC. The only example I found that worked uses GPIOD (see code below).

The problem is, I can't use GPIOD in my application because I also use the external memory and FSMC needs GPIOD. So I tried GPIOB and GPIOC for USART3 but none worked (no interrupt is triggered on Rx, nothing received on the terminal when the board transmits).

In the example I only replaced GPIOD with GPIOB or GPIOC and changed the pins for Tx/Rx from 8/9 (on D) to 10/11 (on B or C).

Did I forget something?

BRs,
Radu


void USART_Initialize()
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    USART_ClockInitTypeDef USART_ClockInitstructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    /* Enable GPIOB clock */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    /* Enable USART clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

    /* Connect pins to usart */
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); /* Tx  */
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); /* Rx  */

    /* Configure USART */
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8 | GPIO_Pin_9;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

      /* serial settings */
    USART_InitStructure.USART_BaudRate   = 115200;
    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_None;
    USART_InitStructure.USART_Mode       =  USART_Mode_Rx | USART_Mode_Tx;

      /* clock settings  */
    USART_ClockInitstructure.USART_Clock   = USART_Clock_Disable ;
    USART_ClockInitstructure.USART_CPOL    = USART_CPOL_High ;
    USART_ClockInitstructure.USART_LastBit = USART_LastBit_Disable;
    USART_ClockInitstructure.USART_CPHA    = USART_CPHA_1Edge;

    USART_Init(USART3, &USART_InitStructure);
    USART_ClockInit(USART3, &USART_ClockInitstructure);

    /* interrupt configuration */
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // enable the USART3 receive interrupt
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);                           

    /* Enable USART */
    USART_Cmd(USART3, ENABLE);
}

LubOlimex

#1
Hey radu,

Have you tried USART6 on PORT G that goes to RS232_1 and UEXT pins 3 and 4?

Note that for USART6_TX to work properly, the camera has to be disconnected (since USART6_TX and DCMI_D0 are multiplexed).

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

radu

Hi Lub,

thanks for the answer.

I have tried USART6 on port G (P9 Rx, P14 Tx) with both RS232_1 and UEXT: Rx works, Tx doesn't.

For the camera, I moved the 2 jumpers to B1_1 and B0_1. I even pulled the connector out :) Is there anything else I have to do "disconnect" the camera?

BRs,
Radu

LubOlimex

Hey radu,

You also have to initialize the pin as UART on software level. It is defined as GPIO/CAM. There should be a ready function for such initialization.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

radu

Hey Lub,

I think I did that... should be the bold lines in the code below (RS232_1 -> USART6 -> GPIOG).

I managed to send "something" using UEXT -> USART3 -> GPIOC. What I receive in the terminal on the PC however is rubbish. I send the letters 'a', 'b', ... should be hex 61, 62, ... What I receive is (for 'a' to 'j'):

4F 27 4E 93 93 26 4C 49 C9 49

I don't see any pattern for the error in the output... Any idea?

Cheers,
Radu


void USART_Initialize()
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    USART_ClockInitTypeDef USART_ClockInitstructure;
    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable GPIOG clock */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);

    /* Enable USART clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);

    /* Connect pins to usart */
    GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_USART6); /* Tx  */
    GPIO_PinAFConfig(GPIOG, GPIO_PinSource9, GPIO_AF_USART6); /* Rx  */


    /* Configure USART */
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_14 | GPIO_Pin_9;
    GPIO_Init(GPIOG, &GPIO_InitStructure);

      /* serial settings */
    USART_InitStructure.USART_BaudRate   = 115200;
    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_None;
    USART_InitStructure.USART_Mode       =  USART_Mode_Rx | USART_Mode_Tx;

      /* clock settings  */
    USART_ClockInitstructure.USART_Clock   = USART_Clock_Disable ;
    USART_ClockInitstructure.USART_CPOL    = USART_CPOL_High ;
    USART_ClockInitstructure.USART_LastBit = USART_LastBit_Disable;
    USART_ClockInitstructure.USART_CPHA    = USART_CPHA_1Edge;

    USART_Init(USART6, &USART_InitStructure);
    USART_ClockInit(USART6, &USART_ClockInitstructure);

    /* interrupt configuration */
    USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);                           

    /* Enable USART */
    USART_Cmd(USART6, ENABLE);

}

billr

Do you have a RS-232 level translator to shift the 0 to +3.3V signal up to +/-12V? What happens if you loop back the TX line to the RX line on the P407 (with the PC disconnected)? Do you see the characters you transmitted? Are you sure the clock rate in the board config file matches the crystal frequency on the board?

I suspect it's a baudrate of voltage level problem.