/* ----------------------------------------------------- v003_uart.h Header fuer rudimentaere UART-Funktionen MCU : CH32V003 Takt : 48 MHz 30.11.2025 R. Seelig ------------------------------------------------------ */ /* CH32V003 A4M6 CH32V003F4P6 +-----------+ +--------------+ PC1 / sda |1 C 16| PC0 PD4 / a7 | 1 20 | PD3 / a4 PC2 / scl |2 H 15| Vdd PD5 / a5 / utx | 2 C 19 | PD2 / a3 PC3 |3 3 14| gnd PD6 / a6 / urx | 3 H 18 | PD1 / swio PC4 |4 2 13| PA2 / osc0 / a0 nrst / PD7 | 4 3 17 | PC7 / miso PC6 / mosi |5 V 12| PA1 / osc1 / a1 PA1 / osc0 / a0 | 5 2 16 | PC6 / mosi PC7 / miso |6 0 11| nrst / PD7 PA2 / osc1 / a1 | 6 V 15 | PC5 / sck / scl PD1 / swio |7 0 10| PD6 / a6 / urx gnd | 7 0 14 | PC4 / a2 PD4 / a7 |8 3 9| PD5 / a5 / utx PD0 | 8 0 13 | PC3 +-----------+ Vdd | 9 3 12 | PC2 / scl +--------------+ */ #ifndef in_v003uart #define in_v003uart #include #include "Arduino.h" class V003uart { #define FUNCONF_SYSTEM_CORE_CLOCK 48000000l #define GPIO_CNF_OUT_PP_AF 8 #define GPIO_CNF_IN_PUPD 8 #define CTLR1_UE_Set ((uint16_t)0x2000) // USART enable mask // -------------------------------------------------------------------- // Prototypenbeschreibung // -------------------------------------------------------------------- public: V003uart(); void begin(uint32_t brate); void putchar(uint8_t ch); uint8_t getchar(void); uint8_t ischar(void); void prints(char *txbuf); void printint(int i, char komma); void readln(char *txbuffer, int maxlen); int readint(void); int readhex(void); void printhex(uint16_t h, char out16); protected: private: uint32_t baudrate; void locase(char *str); uint32_t ahtoi(char *str, char *error); void hexnibbleout(uint8_t b); }; #endif