HC32L110 serial port variable length reception and some problems with PCA and IRQ

show you the code:

https://gitee.com/yangfei_addoil/hc32-l110-b6-test

Also: The program that uses Pascal nomenclature is copied from the official routine; the program that uses underline nomenclature is the blogger's;

Serial port variable length reception

Note that the serial port needs to be bound/assigned to a timer;

A simple console is implemented in the code base without the help of timers. The specific interfaces can be supplemented by yourself. Currently, there are two simple examples of gpio control and adc acquisition.

The main two functions are as follows (forgive me for using global variables, this microcontroller does not have much space, so it is not too complicated):

/**
  * @brief 简易测试控制台.
  * @note
  * @param *data 交互数据的存放缓存区
  *
  * @retval 0:设置成功 1:设置/读取失败
  * @author yangFei
  * @date   20230814
  * @note   目前没有做数据范围判断,所以可能有异常
  */
uint8_t test_console(char *data)
{
    char temp[20];

    if (strstr(data, "get dac"))  //获取电阻
    {
			  int dac = adc_get[0] + adc_get[1];
			  printf("data: %d\n", dac);
    }
		else if (strstr(data, "gpio"))  //gpio 设置
    {
        uint32_t  io1, io2;
        sscanf((char *)data, "%s %d %d", temp, &io1, &io2);
			  Gpio_SetIO(1, 4, io1);
        Gpio_SetIO(1, 5, io2);
        printf("gpio: %d %d\n", io1, io2);
    }
    else if (strstr(data, "other"))
    {
        __NOP;
    }
    else
    {
        printf("order list:\n");
        printf("get dac\n");
			  printf("gpio\n");
			  printf("other\n");

        return 1;

    }


    return 0;
}

/**
    * @brief  获取串口0接收的内容
    *
    * @param  uart0_data:串口0结果指针; uart0_data_len:读取的长度
    *
    * @retval 1:有数据更新;0:无数据更新
    * @author yangFei
    * @date   20230814
    * @note   使用单字符队列+延时的方式;uart0_data_len不能超过最大长度
    */
uint8_t get_uart0_data(uint8_t *uart0_data, uint8_t uart0_data_len)
{
    if (uart0_rx_flag == 0 || uart0_data_len > 16)
    {
        return 0;
    }
    else
    {

        delay1ms(UART0_RX_LEN);//等待帧接收完成
        memcpy(uart0_data, uart0_rx_data, uart0_data_len);

        //清空队列和标志位
        memset(uart0_rx_data, 0, sizeof(uart0_rx_data));
        uart0_rx_pos = 0;
        uart0_rx_flag = 0;

        return 1;
    }
}

PCA

 

IRQ

GPIO interrupts cannot be detected on alternating edges and can only be triggered on rising or falling edges;

As shown in the figure below, the time from triggering the interrupt to the chip entering the interrupt is 67us.

 The manual explains as follows (currently using the internal 24M crystal oscillator, wait for 16 cycles):

 

Guess you like

Origin blog.csdn.net/Fei_Yang_YF/article/details/132367286