cancel
Showing results for 
Search instead for 
Did you mean: 

Manually assert RS232 flow control signals

Bobo Bobobooobö
Associate II
Posted on September 18, 2017 at 16:08

Hello,

I'm working on a project using a STM32L4

I'm using RS232 on the USART1 (with a MAX2328). I'm connecting the RS232 on my computer using a USB adaptator. And I use a RS232 analyzer with LEDs to monitor the flow control signals.

What I would like to do is manually assert DCD, DSR, DTR and RI with GPIOs but when I read the state of one of the pin associed to one of these signals, it's always 0.

This is how I initialize the GPIOs :

//DTR ----> PA8
 GPIO_InitTypeDef DTR;
 if(Config_RSDTR!=DISABLE)
 {
 if(Config_RSDTR==OUTPUT)
 {
 DTR.Alternate = GPIO_MODE_OUTPUT_PP;
 DTR.Mode = GPIO_MODE_OUTPUT_PP ;
 DTR.Pin = GPIO_PIN_8;
 DTR.Pull = GPIO_NOPULL;
 DTR.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(GPIOA,&DTR);
 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,1);
 }
}
 //DCD ----> PC9
 GPIO_InitTypeDef DCD;
 if(Config_RSDCD!=DISABLE)
 {
 if(Config_RSDCD==INPUT)
 {
 DCD.Pin = GPIO_PIN_9;
 DCD.Mode = GPIO_MODE_INPUT;
 DCD.Pull = GPIO_NOPULL;
 DCD.Speed = GPIO_SPEED_FREQ_LOW;
 DCD.Alternate = GPIO_MODE_INPUT;
 HAL_GPIO_Init(GPIOC, &DCD);
 }
 }
 //DSR -----> PC8
 GPIO_InitTypeDef DSR;
 if(Config_RSDSR!=DISABLE)
 {
 if(Config_RSDSR==INPUT)
 {
 DSR.Pin = GPIO_PIN_8;
 DSR.Mode = GPIO_MODE_INPUT;
 DSR.Pull = GPIO_NOPULL;
 DSR.Speed = GPIO_SPEED_FREQ_LOW;
 DSR.Alternate = GPIO_MODE_INPUT;
 HAL_GPIO_Init(GPIOC, &DSR);
 }
 }
 //RI -----> PC7
 GPIO_InitTypeDef RI;
 if(Config_RSRI!=DISABLE)
 {
 if(Config_RSRI==INPUT)
 {
 RI.Pin = GPIO_PIN_7;
 RI.Mode = GPIO_MODE_INPUT;
 RI.Pull = GPIO_NOPULL;
 RI.Speed = GPIO_SPEED_FREQ_LOW;
 RI.Alternate = GPIO_MODE_INPUT;
 HAL_GPIO_Init(GPIOC, &RI);
 }
 }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Thanks !

#stm32l476 #usart #rs232
4 REPLIES 4
Posted on September 18, 2017 at 16:37

Review the peripheral settings with your debugger. Make sure the GPIO clocks are enabled.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 18, 2017 at 17:04

Sorry, I'm kind of a beginner at this, what do you mean by reviewing the peripheral settings with the debugger ?

The GPIO Clocks are enabled. Also I can control the pin 8 of GPIOA (even though I can't see it on the RS232 tester, write operations seems to work).

Thank you !

Posted on September 18, 2017 at 17:27

Well debuggers from the likes of Keil and IAR have this 'Peripheral' menu that decomposes the internal registers at a bit level for inspection. Review those in the context of the Reference Manual. Review the documentation for your debugger.

Look at the GPIO peripheral for the bank(s) in question, and look at the RCC to confirm the clocks are enable, and that they are enabled prior to your configuring them, and that the configuration setting stick and match those you set up.

At a board/chip level make sure you are not driving other signals into the outputs. You should be able to write into GPIO->ODR and inspect state via GPIO->IDR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 19, 2017 at 10:13

I found the 'peripheral' menu, it's named 'I/O Register' in System Workbench for STM32.

The GPIO and RCC registers contain the same settings that I set up.

When I use the HAL_GPIO_WritePin on one the 3 pins from GPIOC, it correctly sets the corresponding bit of the ODR register to 1 (or 0 depending on what I do) but the value is not driven to the IDR register. Is that normal ?

Thank you !

EDIT : Does the fact that those pins are configured as inputs plays a role in that ? If so, by setting them as outputs will it allow me to control them and will it be the correct way to do what I'm trying to do ? I have not found a lot of information about how to set up a RS232 communication using USART, GPIOs and STM32L476 or how does the STM32L476 handle the RS232 communication.