Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial.available() does not work on CH32x035 #142

Open
joraguero opened this issue Sep 8, 2024 · 15 comments
Open

Serial.available() does not work on CH32x035 #142

joraguero opened this issue Sep 8, 2024 · 15 comments

Comments

@joraguero
Copy link

Hi everyone, when I call Serial.available() to see if there is any data in the reception buffer, it always returns -1.

@maxint-rd
Copy link
Contributor

Hi, this is because it hasn't been implemented (yet).

For my CH32V003 projects I've implemented interrupt driven Serial1. Because I only have the v003 I couldn't test any other CH32 chips. Perhaps you want to test this?
My changes add support for available() and peek() and improve read(0 by adding a buffer to avoid loosing bytes when doing other stuff.

To test it shoukd be sufficient to replace these two files:

  • cores/arduino/HardwareSerial.h
  • cores/arduino/HardwareSerial.cpp

Would be nice if it also works for the CH32x035, but I have not examined that, so no guarantees....

@vuhazu
Copy link

vuhazu commented Sep 11, 2024

Hi, this is because it hasn't been implemented (yet).

For my CH32V003 projects I've implemented interrupt driven Serial1. Because I only have the v003 I couldn't test any other CH32 chips. Perhaps you want to test this? My changes add support for available() and peek() and improve read(0 by adding a buffer to avoid loosing bytes when doing other stuff.

To test it shoukd be sufficient to replace these two files:

  • cores/arduino/HardwareSerial.h
  • cores/arduino/HardwareSerial.cpp

Would be nice if it also works for the CH32x035, but I have not examined that, so no guarantees....

it works for CH32x035, I'm tested

@maxint-rd
Copy link
Contributor

Good to read that CH32x035 works too. A moment ago I submitted PR #145 to add working Serial.available(), Serial.peek() and improve Serial.read(). Would be nice if that PR could also be tested for other CH32 chips.

@atollminsk
Copy link

Hi, this is because it hasn't been implemented (yet).
For my CH32V003 projects I've implemented interrupt driven Serial1. Because I only have the v003 I couldn't test any other CH32 chips. Perhaps you want to test this? My changes add support for available() and peek() and improve read(0 by adding a buffer to avoid loosing bytes when doing other stuff.
To test it shoukd be sufficient to replace these two files:

  • cores/arduino/HardwareSerial.h
  • cores/arduino/HardwareSerial.cpp

Would be nice if it also works for the CH32x035, but I have not examined that, so no guarantees....

it works for CH32x035, I'm tested

Hi, this is because it hasn't been implemented (yet).

For my CH32V003 projects I've implemented interrupt driven Serial1. Because I only have the v003 I couldn't test any other CH32 chips. Perhaps you want to test this? My changes add support for available() and peek() and improve read(0 by adding a buffer to avoid loosing bytes when doing other stuff.

To test it shoukd be sufficient to replace these two files:

  • cores/arduino/HardwareSerial.h
  • cores/arduino/HardwareSerial.cpp

Would be nice if it also works for the CH32x035, but I have not examined that, so no guarantees....

its work for CH32V208WB. tested.

@maxint-rd
Copy link
Contributor

@atollminsk - Excellent. Thank you for testing.

@atollminsk
Copy link

Hi, this is because it hasn't been implemented (yet).

For my CH32V003 projects I've implemented interrupt driven Serial1. Because I only have the v003 I couldn't test any other CH32 chips. Perhaps you want to test this? My changes add support for available() and peek() and improve read(0 by adding a buffer to avoid loosing bytes when doing other stuff.

To test it shoukd be sufficient to replace these two files:

  • cores/arduino/HardwareSerial.h
  • cores/arduino/HardwareSerial.cpp

Would be nice if it also works for the CH32x035, but I have not examined that, so no guarantees....

I checked today with CH32V203C8T6 - it works. CH32V307VCT6 - it doesn't work.

@maxint-rd
Copy link
Contributor

@atollminsk - thank you for your additional testing. Unfortunately I don't have a CH32V307VCT6 so I cannot do further analysis/debugging.

@atollminsk
Copy link

atollminsk commented Sep 26, 2024

I found the problem, the reason for not working with CH32V307 - I used the command pinMode(x, OUTPUT). With other controllers, the same code worked. I use pinMode(x, OUTPUT_OD). Mismatch pin map of real electrical circuit.
EVT 307VCT6

@maxint-rd
Copy link
Contributor

@atollminsk - Hmm... So you have tested it working now?
I'm not quite sure what you meant by "Mismatch pin map". Do you mean you used pinMode on the pin you also used for Serial? Or was it an unrelated pin that had an effect on serial communication. (I'm not quite familiar with the pinout of the CH32V307).

@atollminsk
Copy link

@maxint-rd Yes, i used to pinMode pin also for Serial. working with CH32V307)

@blopa1961
Copy link

Serial.available() does not work with the CH32V003 either, but Serial.read() returns a 16 bit -1 value if no byte is pending in the serial port.
So you can use:
mySerialInput= Serial.read();
if (mySerialInput != -1) { etc }

This is a workaround, but I hope this bug is fixed soon!

@maxint-rd
Copy link
Contributor

maxint-rd commented Oct 1, 2024

This is a workaround, but I hope this bug is fixed soon!

I already fixed it. See earlier comments and PR #145. That PR also improves Serial.read() to prevent lost data when doing other stuff. (It re-introduces the read-buffer). Works for CH32V003, X035, V203, V208, V307 and perhaps others as well.

@blopa1961
Copy link

I already fixed it.

Great!
I tested it when I forced the Board Manager and it didn't work, maybe the old version was catched...
Which file(s) do I need to overwrite to fix Serial.available() ?

@atollminsk
Copy link

atollminsk commented Oct 2, 2024

@blopa1961 see this post

@maxint-rd
Copy link
Contributor

maxint-rd commented Oct 2, 2024

@blopa1961 - when you open PR #145 you see several tabs. The rightmost lists the files that were changed. In this case two files changed.
(As mentioned in my first reply of this issue these are HardwareSerial.cpp and its .h)

Please note that PR #145 has not been merged yet, so just cloning the master branch won't give you these changed files. Also review the other PR's to see if there is anything you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants