2421 views|4 replies

1455

Posts

1

Resources
The OP
 

【GD32307E-START】+Serial communication function test [Copy link]

 This post was last edited by jinglixixi on 2020-11-9 22:20

The official website provides a routine for serial communication function, but the weird thing is the hardware design. Since the GD-Link prompt is printed on the board, there will be no confusion when using it. In terms of power supply, the switch is marked with "DC" and "Link". However, the use of the virtual serial port is weird. It is not possible to use the USB of the virtual serial port for power supply, nor can it use GD-Link to form a virtual serial port. The result is that two USB cables are required to complete a simple serial communication test, as shown in Figure 1.

Before you understand these, you will never be able to tinker with the virtual serial port!

Figure 1 Serial communication test connection

After tinkering with the virtual serial port, testing is relatively simple. After compiling and downloading the program, you can see the content shown in Figure 2, that is, every time the USER key is pressed, LED1 lights up, and at the same time a "USART printf example" is output through the serial port.

Figure 2 Serial port output content

So how is the program designed?

To light up LED1, it needs to be defined and initialized. The initialization function is:

void led_init(void)
{
 gd_eval_led_init(LED1);
}

The function that makes LED1 flash is as follows:

void led_flash(int times)
{
 int i;
 for(i=0; i<times; i++)
 {
 /* delay 400 ms */
 delay_1ms(400);
 /* turn on LEDs */
 gd_eval_led_on(LED1);
 /* delay 400 ms */
 delay_1ms(400);
 /* turn off LEDs */
 gd_eval_led_off(LED1);
 }
}

That is to say, the state is switched every 400 milliseconds.

For serial communication, it involves sending and receiving. The redirected printf statement is used for sending, and the fputc function is used for receiving. The content is as follows:

int fputc(int ch, FILE *f)
{
 usart_data_transmit(EVAL_COM1, (uint8_t)ch);
 while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TBE));
 return ch;
}

Finally, let's take a look at the main program. It has few functions but is very bloated. Its contents are as follows:

int main(void)
{
 /* initialize the LEDs */
 led_init();
 /* configure systick */
 systick_config();
 /* flash the LEDs for 1 time */
 led_flash(1);
 /* configure EVAL_COM1 */
 gd_eval_com_init(EVAL_COM1);
 /* configure TAMPER key */
 gd_eval_key_init(KEY_WAKEUP, KEY_MODE_GPIO);
 /* output a message on hyperterminal using printf function */
 printf("\r\n USART printf example: please press the User key \r\n");
 /* wait for completion of USART transmission */
 while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TC)){
 }
 while(1)
 {
 /* check if the user key is pressed */
 if(RESET == gd_eval_key_state_get(KEY_WAKEUP))
 {
 delay_1ms(50);
 if(RESET == gd_eval_key_state_get(KEY_WAKEUP))
 {
 delay_1ms(50);
 if(RESET == gd_eval_key_state_get(KEY_WAKEUP))
 {
 /* turn on LED1 */
 gd_eval_led_on(LED1);
 /* output a message on hyperterminal using printf function */
 printf("\r\n USART printf example \r\n");
 /* wait for completion of USART transmission */
 while(RESET == usart_flag_get(EVAL_COM1, USART_FLAG_TC)){
 }
 }
 else
 {
 /* turn off LED1 */
 gd_eval_led_off(LED1);
 }
 }
 else
  {
  /* turn off LED1 */
 gd_eval_led_off(LED1);
 }
 }
 else
 {
 /* turn off LED1 */
 gd_eval_led_off(LED1);
 }
 }
}

This post is from Domestic Chip Exchange

Latest reply

This is very uncomfortable, and you have to connect two data lines   Details Published on 2020-11-10 09:41
 
 

7462

Posts

2

Resources
2
 

Thanks for sharing!

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1455

Posts

1

Resources
3
 
freebsder posted on 2020-11-9 22:38 Thank you for sharing!

This post is from Domestic Chip Exchange
 
 
 

1942

Posts

2

Resources
4
 

This is very uncomfortable, and you have to connect two data lines

This post is from Domestic Chip Exchange

Comments

Yes! In addition, the routine is also difficult to use, no wonder the brothers in front of me were killed.  Details Published on 2020-11-10 10:41
 
 
 

1455

Posts

1

Resources
5
 
w494143467 posted on 2020-11-10 09:41 This is very uncomfortable, and you have to connect two data cables

Yes! In addition, the routine is also difficult to use, no wonder the brothers in front of me were killed.

This post is from Domestic Chip Exchange
 
 
 

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