petrdynin

Mik32+UART1+IRQ

Sep 24th, 2025
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | Source Code | 0 0
  1. #include "scr1_csr_encoding.h"
  2. #include "riscv_csr_encoding.h"
  3. #include "mik32_memory_map.h"
  4. #include "power_manager.h"
  5. #include "pad_config.h"
  6. #include "epic.h"
  7. #include "uart.h"
  8.  
  9. volatile uint32_t ddd;
  10.  
  11. void trap_handler(void)
  12. {
  13.  
  14.     if (EPIC->RAW_STATUS & (1<<EPIC_UART_1_INDEX))  {
  15.  
  16.        if(UART_1->FLAGS & UART_FLAGS_RXNE_M)
  17.          {
  18.             ddd = UART_1->RXDATA;
  19.             UART_1->TXDATA = ddd;
  20.          }
  21.     }
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.  
  28.     PM->CLK_APB_M_SET |= PM_CLOCK_APB_M_EPIC_M;
  29.     PM->CLK_APB_P_SET |= PM_CLOCK_APB_P_UART_1_M | PM_CLOCK_APB_P_GPIO_1_M ;
  30.  
  31.     PAD_CONFIG->PORT_1_CFG  = (PAD_CONFIG->PORT_1_CFG  & ~(PAD_CONFIG_PIN_M(8) | PAD_CONFIG_PIN_M(9))) \
  32.                                | PAD_CONFIG_PIN(8,0x01) | PAD_CONFIG_PIN(9,0x01);
  33.  
  34.     UART_1->CONTROL1 = 0;
  35.     UART_1->DIVIDER  = 32000000/115200;
  36.  
  37.     UART_1->CONTROL2 = 0;
  38.     UART_1->CONTROL3 = 0;
  39.     UART_1->CONTROL1 = UART_CONTROL1_TE_M | UART_CONTROL1_RE_M | UART_CONTROL1_M_8BIT_M | UART_CONTROL1_UE_M;
  40.  
  41.     EPIC->MASK_LEVEL_SET = 1 << EPIC_UART_1_INDEX;
  42.  
  43.     UART_1->CONTROL1 |= UART_CONTROL1_RXNEIE_M;
  44.  
  45.     // global interrupt enable
  46.     set_csr(mstatus, MSTATUS_MIE);  // Global interrupt enable
  47.     set_csr(mie, MIE_MEIE);         // Machine External Interrupt Enable
  48.  
  49.     while (1)
  50.     {
  51.  
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment