4250 views|11 replies

1412

Posts

3

Resources
The OP
 

Urgent help, about the USART serial communication (sp3232) problem of STM32F407VGT6 chip (please help if you pass by) [Copy link]

 

Today I would like to ask you a question about the serial port communication of STM32F407 . Actually, this is a very basic question, but I have to ask you.
1. Problem description
The microcontroller used is STM32F407VGT6 chip, 100 pins. The serial port channel is USART3, and the serial port chip is SP3232 chip. The communication rate is 115200-8-n-1.
When testing the microcontroller, it was found that the received and sent data were garbled and could not be used at all.

2. Troubleshooting
(1) First check the hardware problem.
The hardware circuit diagram is as follows:


The circuit diagram was designed according to the data sheet and the circuit diagram of Atom. The voltages at each point were tested: (16-pin voltage 3.27V, 2-pin voltage 5.89V, 6-pin voltage -5.3V, 1-pin voltage 2.9V, 4-pin voltage 5.56V).
The microcontroller was connected to the PC externally through a USB to TTL tool and a cross connection was made.

(2) Check the debugging tool
. It was suspected that the debugging tool was the problem. Three USB to TTL converters from different manufacturers were tested. The displayed results were the same, and the communication was garbled. The communication tool was ruled out.

(3) Check the serial port assistant
. Three serial port debugging assistants were also replaced, including Atom's serial port assistant. The problem was the same.

(4) Check the communication chip.
a. In view of the fact that there are many fake SP2332s on the Internet and my own experience, the SP3232 tested was replaced with a new one. During this period, it was replaced with MAX232 (the chip voltage was changed to 5V through flying wires), and then replaced with max3232 through regular channels. The same result was garbled communication.
b. Perform a loopback test on SP3232, that is, short-circuit USART3 (pin 9 and pin 10), and send data through the serial port debugging assistant. At this time, the data is sent normally. Short-circuit USART6 (pin 11 and pin 12), and the data is sent normally, indicating that the communication chip is normal.


(5)
The test method for detecting the communication pins of the microcontroller is to remove the SP3232 chip, directly connect the TXD and RXD of USART3 to the RXD and TXD of the USB to TTL tool, and send data through the debugging assistant. It can also send and receive data normally, and the data sent is the same as the data returned.
At this time, re-solder the SP3232 chip, and the communication is still garbled, which is simply unbelievable.

(6) Check the peripheral components of the microcontroller
a. First check for any cold soldering problems.
Re-solder the peripheral components of the microcontroller and repair them
b. Check the circuit problems and carefully verify them against the official schematic diagram and the schematic diagram of the STM32F407VGT6 chip on the Internet. No problems were found.
The schematic diagram is as follows (about the power supply and crystal oscillator):




c. Check the crystal oscillator. The crystal
oscillator is 8MHz and there is no problem with the welding. Test the voltage of the crystal oscillator pins, which are 1.81V and 1.69V respectively.
Remove the crystal oscillator Y3 (32.768KHz).

(7) Check the program problem
. There are two test examples for this test, one is "Experiment 4 Serial Port Experiment" by Atom Brother, and the other is "USART2-USART2 Transmitter" by Wildfire. Don't be surprised, there is really no other way.
a. Atom Brother's "Experiment 4 Serial Port Experiment"
Modify the pin, clock and interrupt configuration :

//Redefine fputc function
int fputc(int ch, FILE *f)
{
while((USART3->SR&0X40)==0);//Loop sending until sending is completed
USART3->DR = (u8) ch;
return ch;
}
#endif

#if EN_USART1_RX //If reception is enabled
//Serial port 1 interrupt service routine
//Note that reading USARTx->SR can avoid inexplicable errors
u8 USART_RX_BUF[USART_REC_LEN]; //Receive buffer, maximum USART_REC_LEN bytes.
//Receive status
//bit15, receive completion flag
//bit14, received 0x0d
//bit13~0, number of valid bytes received
u16 USART_RX_STA=0; //Receive status mark


//Initialize IO Serial port 1
//bound: baud rate
void uart_init(u32 bound){
//GPIO port settings
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); //Enable GPIOA clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //Enable USART1 clock //Serial port 1 corresponding pin multiplexing mapping GPIO_PinAFConfig(GPIOD,GPIO_PinSource8,GPIO_AF_USART3); //GPIOA9 is multiplexed as USART1 GPIO_PinAFConfig(GPIOD,GPIO_PinSource9,GPIO_AF_USART3); //GPIOA10 is multiplexed as USART1 //USART1 port configuration GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; //GPIOA9 and GPIOA10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //Multiplexing function GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //Speed 50MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //Push-pull multiplexing output GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //Pull up GPIO_Init(GPIOD,&GPIO_InitStructure); //Initialize PA9, PA10 //USART1 initialization settings USART_InitStructure.USART_BaudRate = bound; //Baud rate setting USART_InitStructure.USART_WordLength = USART_WordLength_8b;//Word length is 8-bit data formatUSART_InitStructure.USART_StopBits = USART_StopBits_1;//One stop bitUSART_InitStructure.USART_Parity = USART_Parity_No;//No parity bitUSART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//No hardware data flow controlUSART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Transmit and receive modeUSART_Init (USART3, &USART_InitStructure); //Initialize serial port 1 USART_Cmd(USART3, ENABLE); //Enable serial port 1 USART_ClearFlag(USART3, USART_FLAG_TC); #if EN_USART1_RX USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); // Enable related interrupts // Usart1 NVIC configuration































NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; //Serial port 1 interrupt channel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //Preemption priority 3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //Sub-priority 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ channel enable
NVIC_Init(&NVIC_InitStructure); //Initialize VIC registers according to the specified parameters,
#endif } void USART3_IRQHandler(void) //Serial port 1 interrupt service routine { u8 Res; #ifdef OS_TICKS_PER_SEC //If the clock tick number is defined, it means that ucosII is to be used. OSIntEnter(); #endif if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //Receive interrupt (the received data must end with 0x0d 0x0a) { Res =USART_ReceiveData(USART3);//(USART1->DR); //Read received data if((USART_RX_STA&0x8000)==0)//Reception is not completed { if(USART_RX_STA&0x4000)//Received 0x0d { if(Res!=0x0a)USART_RX_STA=0;//Reception error, restart else USART_RX_STA|=0x8000; //Reception is completed } else //Not received 0X0D { if(Res==0x0d)USART_RX_STA|=0x4000; else { USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ; USART_RX_STA++; if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//Receive data error, restart receiving } } } } #ifdef OS_TICKS_PER_SEC //If the clock beat number is defined, it means that ucosII is to be used. OSIntExit(); #endif } After modification in the main function: while(1) { if(USART_RX_STA&0x8000) { len=USART_RX_STA&0x3fff;//Get the length of the data received this time printf("\r\nThe message you sent is:\r\n"); for(t=0;t<len;t++) { USART_SendData(USART3, USART_RX_BUF[t]); //Send data to serial port 1while (USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//Wait for the end of sending }


















































printf("\r\n\r\n");//Insert line
breakUSART_RX_STA=0;
}else
{
times++;
if(times%5000==0)
{
printf("\r\nALIENTEK Explorer STM32F407 Development Board Serial Port Experiment\r\n");
printf(" Punctaneous Atom @ALIENTEK\r\n\r\n\r\n");
}
if(times%200==0)printf("52353535\r\n");
if(times%30==0)LED0=!LED0;//Blink LED to indicate that the system is running.
delay_ms(10);
}
}

View the clock configuration:
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

#if defined (STM32F40_41xxx)
uint32_t SystemCoreClock = 168000000;
#endif /* STM32F40_41xxx */

/************************* PLL Parameters *************************************/
#if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || (STM32F429 _439xx ) || defined(STM32F401xx) || defined(STM32F469_479xx)
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
#define PLL_M

simulation to view the configuration of USART3:


After comparing it with the data sheet, no problems were found.


b. Wildfire's "USART2 - USART2 Transmission"

//Pin definition
/********************************************************/
#define RS232_USART USART3
#define RS232_USART_CLK RCC_APB1Periph_USART3


#define RS232_USART_RX_GPIO_PORT GPIOD
#define RS232_USART_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define RS232_USART_RX_PIN GPIO_Pin_9
#define RS232_USART_RX_AF GPIO_AF_USART3
#define RS232_USART_RX_SOURCE GPIO_PinSource9

#define RS232_USART_TX_GPIO_PORT GPIOD
#define RS232_USART_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define RS232_USART_TX_PIN GPIO_Pin_8
#define RS232_USART_TX_AF GPIO_AF_USART3
#define RS232_USART_TX_SOURCE GPIO_PinSource8

#define RS232_USART_IRQHandler USART3_IRQHandler
#define RS232_USART_IRQ USART3_IRQn
/************************************************************/
//串口波特率
#define RS232_USART_BAUDRATE 115200


/**
* @brief配置嵌套向量中断控制器NVIC
* @param无
* @retval 无
*/
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* 配置中断源 */
NVIC_InitStructure.NVIC_IRQChannel = RS232_USART_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

}


/**
* @briefRS232_USART GPIO 配置,工作模式配置。115200 8-N-1 ,中断接收模式
* @param无
* @retval 无
*/
void Debug_USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd( RS232_USART_RX_GPIO_CLK|RS232_USART_TX_GPIO_CLK, ENABLE);

/* 使能 UART 时钟 */
RCC_APB1PeriphClockCmd(RS232_USART_CLK, ENABLE);

/* 连接 PXx 到 USARTx_Tx*/
GPIO_PinAFConfig(RS232_USART_RX_GPIO_PORT,RS232_USART_RX_SOURCE, RS232_USART_RX_AF);

/*连接 PXx 到 USARTx__Rx*/
GPIO_PinAFConfig(RS232_USART_TX_GPIO_PORT,RS232_USART_TX_SOURCE,RS232_USART_TX_AF);

/* 配置Tx引脚为复用功能*/
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 = RS232_USART_TX_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(RS232_USART_TX_GPIO_PORT, &GPIO_InitStructure);

/* Configure Rx pin as multiplexed function*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = RS232_USART_RX_PIN;
GPIO_Init(RS232_USART_RX_GPIO_PORT, &GPIO_InitStructure); /* Configure serial port RS232_USART mode*/ USART_InitStructure.USART_BaudRate = RS232_USART_BAUDRATE; 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; USART_Init(RS232_USART, &USART_InitStructure); NVIC_Configuration(); /*Configure serial port receive interrupt*/ USART_ITConfig(RS232_USART, USART_IT_RXNE, ENABLE); USART_Cmd(RS232_USART, ENABLE); } //Interrupt receive function extern uint8_t Rxflag; extern uint8_t ucTemp; void RS232_USART_IRQHandler(void) { if(USART_GetITStatus( RS232_USART, USART_IT_RXNE ) != RESET) { Rxflag=1; ucTemp = USART_ReceiveData( RS232_USART ); } } Main function: while(1) { /* Receive data from the DEBUG_USART port, analyze and process it. You can encapsulate this code into a function and call it in other processes of the main program */ if(Rxflag) { if (usRxCount < sizeof(ucaRxBuf)) { ucaRxBuf[usRxCount++] = ucTemp; } else { usRxCount = 0; } /* Simple communication protocol. When a carriage return and line feed character is encountered, it is considered as a command frame. You can add other judgments to implement custom commands*/ /* When a line feed character is encountered, it is considered to have received a command*/ if (ucTemp == 0x0A) /* Line feed character*/ { /*When a carriage return character is detected, the data is returned to the host computer*/ Usart_SendStr_length( RS232_USART, ucaRxBuf, usRxCount ); //Usart_SendString(); usRxCount = 0; } Rxflag=0; } } Similarly, change the system clock to 8MHz and test it. 3. Search for information about various methods mentioned on the Internet, such as changing the file attribute from read-only to editable; such as the frequency division of the system clock, changing the system's total clock to 72Mhz for testing, all ended in failure.

































































4. I really have no other choice but to ask for emergency help
. I hope that friends who see this post can give me some suggestions on something that I have not noticed. Thank you very much.

This post is from stm32/stm8

Latest reply

There are two types of USB to serial cables, one is TTL level and the other is RS232 level. The difference between the two circuits is whether there is a 232 interface chip inside. If there is a 232 interface chip on the board, you must use a USB serial cable with a built-in 232 interface chip.   Details Published on 2019-8-8 17:38
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 

1w

Posts

142

Resources
From 11
 

There are two types of USB to serial cables, one is TTL level and the other is RS232 level. The difference between the two circuits is whether there is a 232 interface chip inside. If there is a 232 interface chip on the board, you must use a USB serial cable with a built-in 232 interface chip.

This post is from stm32/stm8

赞赏

1

查看全部赞赏

 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 

650

Posts

8

Resources
2
 

Have you checked the voltage level of SP3232 with an oscilloscope?

This post is from stm32/stm8

Comments

I haven't seen this. I'm about to use an oscilloscope to check it. First of all, is there anything wrong with my software or hardware?  Details Published on 2019-8-5 14:25
 
 

1412

Posts

3

Resources
3
 
29447945 Published on 2019-8-5 13:43 Have you checked the voltage level of SP3232 with an oscilloscope?

I haven't seen this. I'm about to use an oscilloscope to check it. First of all, is there anything wrong with my software or hardware?

This post is from stm32/stm8
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

1w

Posts

142

Resources
4
 

If you don't use SP3232, directly use the USB to serial port to interconnect with the STM32 serial port. If the data is correct, it means the problem is with 3232. Pay attention to the capacity of the charge pump energy storage capacitor, and use 0.1uF, 1uF and 10uF for replacement tests.

This post is from stm32/stm8

Comments

There is no problem with the 3232 chip loopback test! I will try to change the capacitor  Details Published on 2019-8-6 11:49
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1412

Posts

3

Resources
5
 
chunyang posted on 2019-8-5 16:36 If you don't use SP3232, and directly use the USB-to-serial port to interconnect with the STM32 serial port, if the data is correct, it means the problem lies in 3232. Pay attention to the charge pump...

There is no problem with the 3232 chip loopback test! I will try to change the capacitor

This post is from stm32/stm8

Comments

Disconnect the MCU from the 232 interface chip, short the TTL side transmit and receive pins of the 232 interface chip, and then test it with the RS232 interface of the PC. Set the baud rate to the same as the MCU. Only when the data is correct can the 232 interface chip be judged to be OK. If the MCU and the 232 interface chip are OK when tested separately, but the MCU and the interface chip as a whole have problems  Details Published on 2019-8-6 12:07
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

1w

Posts

142

Resources
6
 
annysky2012 posted on 2019-8-6 11:49 There is no problem with the 3232 chip loopback test! I will try to change the capacitor

Disconnect the connection between MCU and 232 interface chip, short-circuit the TTL side transmit and receive pins of 232 interface chip, and then test it with the RS232 interface of PC. Set the baud rate to be the same as MCU. Only when the data is correct can it be determined that there is no problem with 232 interface chip.

If the MCU and 232 interface chip are tested separately and there is no problem, but the MCU and the interface chip as a whole have problems, either the transceiver is connected in reverse or the voltage level is incompatible. Also note that some USB-to-serial ports have compatibility issues, so it is best to test based on the native RS232 serial port.

This post is from stm32/stm8

Comments

Regarding the first question, I short-circuited the 232 transceiver side and tested it. The baud rate was set the same as that of the MCU. Is there any problem with the data transmission and reception? Regarding the second question, I checked the pins many times according to the data sheet, and there is no problem with the transceiver wiring. Is it a problem of level incompatibility? How can I confirm this?  Details Published on 2019-8-6 14:32
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1412

Posts

3

Resources
7
 
chunyang posted on 2019-8-6 12:07 Disconnect the connection between MCU and 232 interface chip, short the TTL side receiving and sending pins of 232 interface chip, and then test it with the RS232 interface of PC. The baud rate setting should be the same as MCU...

Regarding the first question, I short-circuited the 232 transceiver side and tested it. The baud rate was set the same as that of the MCU. Is there any problem with sending and receiving data?

Regarding the second question, I checked the pins many times according to the data sheet, and there is no problem with the transceiver wiring. Is it a problem of level incompatibility? How can I be sure about this?

This post is from stm32/stm8

Comments

SP3232 is supposed to be a 3V TTL interface standard. If the STM32 is powered by 3V or 3.3V, the levels should be compatible. If you want to check, use an oscilloscope.  Details Published on 2019-8-6 15:11
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

1w

Posts

142

Resources
8
 
annysky2012 posted on 2019-8-6 14:32 Regarding the first question, I short-circuited the 232 transceiver side and tested it. The baud rate was set the same as that of the MCU. Is there any problem with the data transmission and reception? Regarding the second question...

SP3232 is supposed to be a 3V TTL interface standard. If the STM32 is powered by 3V or 3.3V, the levels should be compatible. If you want to check, use an oscilloscope.

This post is from stm32/stm8

Comments

Suddenly I figured it out. There was no problem with the circuit of the development board, and there was no problem with the circuit I designed. The key problem was that after the microcontroller was connected to SP3232, it was converted to 232 level, and the tool I used was a USB to TTL (PL2303) test tool, so the test results were all garbled. To put it bluntly, the levels were incompatible.  Details Published on 2019-8-8 13:28
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1412

Posts

3

Resources
9
 
chunyang posted on 2019-8-6 15:11 SP3232 is supposed to be a 3V TTL interface standard. If STM32 is powered by 3V or 3.3V, the level should be compatible. If you want to check, use an oscilloscope.

Suddenly I figured it out. There was no problem with the circuit of the development board, and there was no problem with the circuit I designed. The key problem was that after the microcontroller was connected to SP3232, it was converted to 232 level, and the tool I used was a USB to TTL (PL2303) test tool, so the test results were all garbled. To put it bluntly, the levels were incompatible. I continued to test it at night. If the communication was successful, it would be a bloody lesson.

This post is from stm32/stm8

Comments

Wow, this is a very low-level error. Moreover, the 232 level added to the TTL device is far beyond the range that the device IO can withstand. If the power regulator cannot absorb it, it may destroy the device.  Details Published on 2019-8-8 17:36
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

1w

Posts

142

Resources
10
 
annysky2012 posted on 2019-8-8 13:28 Suddenly I figured it out. There is no problem with the circuit of the development board, and there is no problem with the circuit I designed. The key problem is that after the microcontroller is connected to SP3232, the conversion...

Wow, this is a very low-level error. Moreover, the 232 level added to the TTL device is far beyond the range that the device IO can withstand. If the power regulator cannot absorb it, it may destroy the device.

This post is from stm32/stm8

Comments

The problem has been solved. It was indeed this problem. I only blame myself for not seeing the relationship between the various levels clearly. I spent more than ten days on it. Thank you for helping me solve it.  Details Published on 2019-8-9 10:25
 
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 

1412

Posts

3

Resources
12
 
chunyang posted on 2019-8-8 17:36 Wow, this error is very low-level, and the 232 level added to the TTL device is far beyond the range that the device IO can withstand. The power regulator is not...

The problem has been solved. It was indeed this problem. I only blame myself for not seeing the relationship between the various levels clearly. I spent more than ten days on it. Thank you for helping me solve it.

This post is from stm32/stm8
 
Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list