Skip to content

CH32V003 UART issue #119

@castrofernando

Description

@castrofernando

I'm not sure ig it's a issue, althought I've tried to make UART works in CH32V003F4P6-R0 evt board without success using arduino framework. For a reason that I didn't discover yet, TX and RX are not working properly, so I could not receive or transmit anything. Below is the code I'm trying:

#include <Arduino.h>

#define PIN_SERIAL_RX         PD6
#define PIN_SERIAL_TX         PD5

void setup() {
  Serial.begin(115200);
  Serial.setPins(PIN_SERIAL_RX, PIN_SERIAL_TX);
  delay(1000);
  Serial.println("Serial Started");
}

void loop() {
  if(Serial.available() > 0) {
        Serial.print("I have received: ");
        while(Serial.available()) {
            char c = Serial.read();
            Serial.print(c);
        }
        Serial.println();
    }
}

Am I missing something? It's the first time I try this hardware, so I still discoverying it. I also did not found many other examples/tutorials using Serial with arduino framework for this hardware.
I'm sure that I have connected properly TX and RX, because using noneos-sdk the UART is working properly with the code below.

#if defined(CH32V00X)
#include <ch32v00x.h>
#elif defined(CH32V10X)
#include <ch32v10x.h>
#elif defined(CH32V20X)
#include <ch32v20x.h>
#elif defined(CH32V30X)
#include <ch32v30x.h>
#endif
#include <stdio.h>
#include "debug.h"

int main(void)
{
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
	SystemCoreClockUpdate();
	Delay_Init();
	USART_Printf_Init(115200);
	Delay_Ms(1000); // give serial monitor time to open
	printf("SystemClk: %u\r\n", (unsigned)SystemCoreClock);
	#if defined(CH32V30X)
	printf("ChipID: %08x\r\n", (unsigned)DBGMCU_GetCHIPID());
	#else
	printf("DeviceID: %08x\r\n", (unsigned)DBGMCU_GetDEVID());
	#endif
	printf("This is printf example\r\n");

	while (1)
	{
		Delay_Ms(1000);
		printf("Program over, press reset button\r\n");
	}
}

void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void NMI_Handler(void) {}
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void)
{
	while (1)
	{
	}
}

I really appreciate a direction to debug it. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions