Replies: 3 comments 4 replies
-
A bit of a long shot, but it might be best to not assume that implicit type casting is going to do what you expect. E.g. see: https://forum.arduino.cc/t/typecasting-trouble-converting-from-int-to-unsigned-long/184740 millis() returns unsigned long, which fair enough, is equivalent to uin32_t, but you're also relying on the compiler to correctly handle casting a uint16_t to unint32_t, and treating a literal constants as uint32_t, without specifying that it is. It seems like that should do what you'd expect, but maybe it isn't. E.g. you could say 100ul instead of just 1000 to make it clearer. Personally, I try to stick to all variables involved in calculations / comparisons with millis() or micros() having the same type that is returned - unsigned long. Comparisons with millis() are normally pretty safe, however you do them, because it takes 50 days (allegedly) to return to zero. Ones with micros() are more of a problem - taking about 70 minutes, IIRC. However, if the compiler were to mess up the casting of types, you may get a different answer all together, e.g. it could go wrong after about 30 seconds, if one side of the comparison gets cast to an int16_t, somehow. Since comparisons with millis() or micros() involve modulo (clock) arithmetic, it's generally best to do a subtraction of the last time it had to do something with millis() / micros, and compare that with the interval - but keep it all in unsigned longs, and either specify constants as ul, or use a variable or declare a const to put them in, that's defined as unsigned long. e.g. instead of
Try:
That may well not be the cause of the problem though :) It's just something to try. The comparison part is most likely to go wrong if interval isn't automatically cast to an unsigned long, or uint32_t. Doing it as a subtraction instead of an addition is best practice, for modulo arithmetic, but couldn't have any effect before millis() resets / wraps around to zero. |
Beta Was this translation helpful? Give feedback.
-
Yes, that's certainly mysterious. Does Linux have power saving settings for USB ports? In Windows, it's only on root hubs, IIRC.. and "Generic USB Hub"s, on the Power Management tab for their driver in Device manager. I have that turned off because it can cause problems with USB thumb drives and card readers. It can decide to turn the USB ports off mid file transfer, otherwise. |
Beta Was this translation helpful? Give feedback.
-
Check out #1407. There seems to be an Ubuntu kernel thing in some bleeding edge releases that makes serial ports disappear after a delay of a few seconds. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I'm having some weird trouble with Serial and I wanted to check if; 1. I'm doing anything stupid, and 2. Who to submit the bug report to 😁
If I wait more than two or three seconds between serial prints, the serial terminal doesn't register the new data coming through. If you unplug and re-plug (pico is powered separate from the USB cable) you'll see the next message come through, but nothing again after that. If you send a newline every second as a "Keepalive", the code works as expected, just with lots of stray newlines. On a Windows machine with IDE 1.8.x the code works as expected. The LED in the keepalive routine flashes continuously, so the MCU hasn't crashed.
Any ideas? I have tried multiple cables, ports, and MCUs, and the problem only occurs on my workstation. I've included some relevant info and my test code below.
Thanks!
Code:
Received data:
uname -a:
Linux [HOSTNAME] 5.15.0-71-generic #78~20.04.1-Ubuntu SMP Wed Apr 19 11:26:48 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Beta Was this translation helpful? Give feedback.
All reactions