Implementation of UART data reception on 1986VE92U milandr

I work with a debugging board for a domestic microcontroller 1986VE92 from the company Milandr. I implement data reception and transmission via the RS-232C interface (built-in on the debug board), to communicate with the MC and read the received/sent data, I use the program "Terminal" version 1.9 b, to write and debug the firmware "Keil uVision 5". If I figured out the transmission(the transmission speed is definitely changing and it is clear that something is being sent), then I can not figure out the reception in any way I can. I rechecked all the pins several times, tried to change the ports, checked the boot method on the board. The situation has not moved from the dead point: the transmission works, the reception does not. I attach the code in C, on which I am trying to implement the echo mode. When writing, it was based on the video data: Transmission, Reception

#include "MDR32Fx.h"                    // Device header
#include "MDR32F9Qx_rst_clk.h"          // Keil::Drivers:RST_CLK
#include "MDR32F9Qx_port.h"             // Keil::Drivers:PORT
#include "MDR32F9Qx_config.h"           // Keil::Device:Startup
#include "MDR32F9Qx_uart.h"             // Keil::Drivers:UART
#include "MDR32F9Qx_timer.h"            // Keil::Drivers:TIMER

void LED_init(void)
{
    PORT_InitTypeDef PortInit;
    RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTC, ENABLE); // включаем тактирование порта C
    /*** LED 0 ***/
    PortInit.PORT_Pin = PORT_Pin_0; // устанавливаем номер порта 
    PortInit.PORT_OE = PORT_OE_OUT; // устанавливаем направление передачи данных - на выход
    PortInit.PORT_FUNC = PORT_FUNC_PORT; // Режим работы - порт
    PortInit.PORT_MODE = PORT_MODE_DIGITAL; // Режим работы - цифровой
    PortInit.PORT_SPEED = PORT_SPEED_SLOW; // Скорость работы - медленный режим
    PORT_Init(MDR_PORTC, &PortInit); // Передаем структуру порту C
}

uint16_t data;
void UART2_IRQHandler(void)
{
    if(UART_GetITStatusMasked(MDR_UART2, UART_IT_RX) == SET) // если бит прерывания по приему установлен
    {
        UART_ClearITPendingBit(MDR_UART2, UART_IT_RX); // сбросить его
        data = UART_ReceiveData(MDR_UART2); // записать принятые данные в переменную
        UART_SendData(MDR_UART2, data); // выдать выдать их обратно
    }
}

void UART_init(void)
{
    PORT_InitTypeDef GPIO_Init; // инициализировать структуру настроек пина
    UART_InitTypeDef UART_user_Init; // инициализировать структуру настроек UART

    RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTD, ENABLE); // включить тактирования порта A, потому что на порте D - P1 это альтернативный TX, а PD0 - это альтернативный RX
    // настройки пинов
    GPIO_Init.PORT_Pin        = PORT_Pin_1; // TX 
  GPIO_Init.PORT_OE         = PORT_OE_OUT; // ОТПРАВКА
  GPIO_Init.PORT_PULL_UP    = PORT_PULL_UP_OFF;
  GPIO_Init.PORT_PULL_DOWN  = PORT_PULL_DOWN_OFF;
  GPIO_Init.PORT_PD_SHM     = PORT_PD_SHM_OFF;
  GPIO_Init.PORT_PD         = PORT_PD_DRIVER;
  GPIO_Init.PORT_GFEN       = PORT_GFEN_OFF;
  GPIO_Init.PORT_FUNC       = PORT_FUNC_ALTER; // альтернативные функции
  GPIO_Init.PORT_SPEED      = PORT_SPEED_MAXFAST;
  GPIO_Init.PORT_MODE       = PORT_MODE_DIGITAL;
    PORT_Init(MDR_PORTD, &GPIO_Init); // записать в структуру
    ///
    GPIO_Init.PORT_Pin        = PORT_Pin_0; // RX 
  GPIO_Init.PORT_OE         = PORT_OE_IN; // ПРИЕМ
    PORT_Init(MDR_PORTD, &GPIO_Init); // записать второй пин в структуру
    ////////////////
    NVIC_EnableIRQ(UART2_IRQn); // разрешение на общее прерывание по uart

    RST_CLK_PCLKcmd(RST_CLK_PCLK_UART2, ENABLE); // включить тактирование uart2
    // настройки uart2
    UART_BRGInit(MDR_UART2, UART_HCLKdiv1);
    UART_user_Init.UART_BaudRate = 9600; 
  UART_user_Init.UART_WordLength = UART_WordLength8b;
  UART_user_Init.UART_StopBits = UART_StopBits1;
  UART_user_Init.UART_Parity = UART_Parity_No;
  UART_user_Init.UART_FIFOMode = UART_FIFO_OFF;
  UART_user_Init.UART_HardwareFlowControl = UART_HardwareFlowControl_TXE | UART_HardwareFlowControl_RXE;
    // и на прием и на передачу

  UART_Init(MDR_UART2, &UART_user_Init); // записать в структуру

    UART_ITConfig(MDR_UART2, UART_IT_RX, ENABLE); // прерывание

    UART_Cmd(MDR_UART2, ENABLE); // включить uart2
}

int main()
{
    uint16_t count = 0;
    LED_init();
    UART_init();
    while(1)
    {
    }
}

I can not understand what the error is, please help.

My question is about:

Author: Роман Долгих, 2019-10-14

2 answers

I do not know the details, but I can give general recommendations on how to learn how to work with COM ports.

  1. It does not happen that you have selected the parameters of the COM port for writing, but they do not work for reading. They are always the same.
  2. You should always start by trying to READ:
  3. Connect the ARM COM port to the port of your PC.
  4. On the PC, we run Putty, or something like that.
  5. In the Putty settings, set the lowest frequency.
  6. Enabling ARM
  7. If in the window Putty some symbols fell down - so we guessed the frequency.
  8. If you didn't guess correctly, turn off the ARM, raise the frequency, and repeat everything
  9. Byte size (today) - almost 100% equal to 8 bits
  10. It remains to choose the stop bit and parity. Only 4 combinations.
  11. After the readable characters appear on the screen, we enter the uBoot dialog (by pressing any key in the first 3 seconds) and CONFIGURE the COM port parameters as we want.
  12. Remember the settings and we will use them in the future.
 1
Author: Sergey, 2019-10-15 02:14:52

The problem is solved, the question is settled. I attach the code to receive data from the "Terminal". The answer was found on the developer's forum, at this link: Topic

/* Includes ------------------------------------------------------------------*/
#include "MDR32F9Qx_config.h"
#include "MDR32Fx.h"
#include "MDR32F9Qx_uart.h"
#include "MDR32F9Qx_port.h"
#include "MDR32F9Qx_rst_clk.h"
#include "MDR32F9Qx_eeprom.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static PORT_InitTypeDef PortInit;
static UART_InitTypeDef UART_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Main program.
  * @param  None11
  * @retval None
  */
int main (void)
{
   RST_CLK_HSEconfig(RST_CLK_HSE_ON);
   while(RST_CLK_HSEstatus() != SUCCESS);

   /* Configures the CPU_PLL clock source */
   RST_CLK_CPU_PLLconfig(RST_CLK_CPU_PLLsrcHSEdiv1, RST_CLK_CPU_PLLmul10);

   /* Enables the CPU_PLL */
   RST_CLK_CPU_PLLcmd(ENABLE);
   if (RST_CLK_CPU_PLLstatus() == ERROR) {
      while (1);
   }

   /* Enables the RST_CLK_PCLK_EEPROM */
   RST_CLK_PCLKcmd(RST_CLK_PCLK_EEPROM, ENABLE);
   /* Sets the code latency value */
   EEPROM_SetLatency(EEPROM_Latency_3);

   /* Select the CPU_PLL output as input for CPU_C3_SEL */
   RST_CLK_CPU_PLLuse(ENABLE);
   /* Set CPUClk Prescaler */
   RST_CLK_CPUclkPrescaler(RST_CLK_CPUclkDIV1);

   /* Select the CPU clock source */
   RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3);

  /* Enables the HSE clock on PORTF */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_PORTF,ENABLE);

  /* Fill PortInit structure*/
  PortInit.PORT_PULL_UP = PORT_PULL_UP_OFF;
  PortInit.PORT_PULL_DOWN = PORT_PULL_DOWN_OFF;
  PortInit.PORT_PD_SHM = PORT_PD_SHM_OFF;
  PortInit.PORT_PD = PORT_PD_DRIVER;
  PortInit.PORT_GFEN = PORT_GFEN_OFF;
  PortInit.PORT_FUNC = PORT_FUNC_OVERRID;
  PortInit.PORT_SPEED = PORT_SPEED_MAXFAST;
  PortInit.PORT_MODE = PORT_MODE_DIGITAL;

  /* Configure PORTF pins 1 (UART2_TX) as output */
  PortInit.PORT_OE = PORT_OE_OUT;
  PortInit.PORT_Pin = PORT_Pin_1;
  PORT_Init(MDR_PORTF, &PortInit);

  /* Configure PORTF pins 0 (UART2_RX) as input */
  PortInit.PORT_OE = PORT_OE_IN;
  PortInit.PORT_Pin = PORT_Pin_0;
  PORT_Init(MDR_PORTF, &PortInit);


  /* Select HSI/2 as CPU_CLK source*/
  //RST_CLK_CPU_PLLconfig (RST_CLK_CPU_PLLsrcHSIdiv2,0);

  /* Enables the CPU_CLK clock on UART2 */
  RST_CLK_PCLKcmd(RST_CLK_PCLK_UART2, ENABLE);

  /* Set the HCLK division factor = 1 for UART2*/
  UART_BRGInit(MDR_UART2, UART_HCLKdiv1);

  /* Initialize UART_InitStructure */
  UART_InitStructure.UART_BaudRate                = 115000;
  UART_InitStructure.UART_WordLength              = UART_WordLength8b;
  UART_InitStructure.UART_StopBits                = UART_StopBits1;
  UART_InitStructure.UART_Parity                  = UART_Parity_No;
  UART_InitStructure.UART_FIFOMode                = UART_FIFO_ON;
  UART_InitStructure.UART_HardwareFlowControl     = UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE;

  /* Configure UART2 parameters*/
  UART_Init (MDR_UART2,&UART_InitStructure);

  /* Enables UART2 peripheral */
  UART_Cmd(MDR_UART2,ENABLE);

  uint8_t tmp_data;

  while (1)
  {
    /* Check TXFE flag */
    while (UART_GetFlagStatus (MDR_UART2, UART_FLAG_RXFE) == SET);

    tmp_data = UART_ReceiveData(MDR_UART2);

    UART_SendData(MDR_UART2, tmp_data);

    while (UART_GetFlagStatus (MDR_UART2, UART_FLAG_TXFE) != SET);
  }
}
 1
Author: Роман Долгих, 2019-10-15 08:33:28