ILikeBread 0 Posted December 27, 2020 Share Posted December 27, 2020 I'm getting started with an MSP-EXP430G2 board with an msp430g2231 on Ubuntu 20.10 groovy (64 bit). I can use Serial.print and Serial.println just fine to print strings. But if I use it to print integers the Serial monitor just shows a lot of backward question marks (⸮⸮⸮⸮⸮⸮⸮⸮). Assuming it was a bug in the print code, I copied print(long, int) and printNumber(long, int) functions into my sketch. To my surprise these work fine! Using Serial.print often goes well up to 9, but breaks when it reaches 10. Sometimes it halts completely (image of serial monitor) I already downloaded energia again to a different disk, but I got the same problem there. I don't know how to debug this any further.. void setup() { Serial.begin(4800); } // Copied from msp430/Print.cpp size_t printNumberCopied(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. char *str = &buf[sizeof(buf) - 1]; *str = '\0'; // prevent crash if called with base == 1 if (base < 2) base = 10; do { unsigned long m = n; n /= base; char c = m - base * n; *--str = c < 10 ? c + '0' : c + 'A' - 10; } while (n); return Serial.write(str); } // Copied from msp430/Print.cpp size_t printCopied(long n, int base) { if (base == 0) { return Serial.write(n); } else if (base == 10) { if (n < 0) { int t = Serial.print('-'); n = -n; return printNumberCopied(n, 10) + t; } return printNumberCopied(n, 10); } else { return printNumberCopied(n, base); } } void loop() { for (int i = 0; i<64; i++){ delay(200); printCopied(i, 10); // <-- works //Serial.print(i, 10); // <-- garbage written into serial port when uncommented Serial.println("hi"); } } Quote Link to post Share on other sites
bluehash 1,581 Posted December 28, 2020 Share Posted December 28, 2020 Seems pretty straight forward. You have the baud rate right at 9600 Try just printing Serial.print(i, DEC) without the other prints(printCoiped, serial.println) Quote Link to post Share on other sites
ILikeBread 0 Posted December 28, 2020 Author Share Posted December 28, 2020 I set the baud rate at 4800 as even "Serial.println("hello");" printed garbage when the monitor was set to 9600, but 4800 works fine when printing text, so I figured it would be better to keep it at 4800. This code here: void setup() { Serial.begin(9600); } void loop() { for (int i = 0; i < 64; i++) { delay(100); Serial.println(i, DEC); } } Prints 0 up to 9 and then halts: https://imgur.com/a/CGrg5Ks (screenshot) I also replaced the msp430g2231 with a msp430g2211, but I see the same problem. Could the MSP-EXP430G2 be broken? I tried downloading the binary from the chip again to compare it with the hex its uploading, as I now suspect the code is fine but some bits are getting flipped. But I could not figure out how (I tried using MSPFlasher). $ ./MSP430Flasher -n msp430g2231 -r [hex.hex, MAIN] -v -i ttyACM0 * -----/|-------------------------------------------------------------------- * * / |__ * * /_ / MSP Flasher v1.3.20 * * | / * * -----|/-------------------------------------------------------------------- * * * Evaluating triggers...done * Checking for available FET debuggers: * Couldn't find any connected USB FETs! * Powering down...done * Disconnecting from device...done * * ---------------------------------------------------------------------------- * Driver : closed (MSP DebugStack not initialized) * ---------------------------------------------------------------------------- */ Quote Link to post Share on other sites
bluehash 1,581 Posted December 28, 2020 Share Posted December 28, 2020 Ok.. As long as you match baud rates. I don't use Energia, so I'm guessing here. What happens if you narrow the prblem. Remove the loop and just print a 10. Serial.println(10, DEC) Quote Link to post Share on other sites
NurseBob 111 Posted December 28, 2020 Share Posted December 28, 2020 Likely a dumb question/observation, but wondering about uint8_t: size_t printNumberCopied(unsigned long n, uint8_t base) Why uint8_t? I believe the Arduino code from which this was likely drawn is an 8-bit mcu. The msp430 are 16-bit. Is the printNumberCopied running into an overflow??? Quote Link to post Share on other sites
ILikeBread 0 Posted December 28, 2020 Author Share Posted December 28, 2020 Thanks for all your responses! Quote What happens if you narrow the prblem. Remove the loop and just print a 10. Just printing 10 works fine. This works perfectly as well: void loop() { int i=10; Serial.println(i, DEC); Serial.println(i, DEC); Serial.println(i, DEC); } But this sometimes prints a line that says 'A'. void loop() { int i=10; Serial.println(i, DEC); Serial.println(i, DEC); Serial.println(i, DEC); Serial.println(i, DEC); } So I think I'll assume I got a hardware problem ¯\_(ツ)_/¯. I uploaded it from my laptop as well, but I got the same problem there. Quote Why uint8_t? I don't know why uint8_t, but I don't think it's overflowing since it only breaks after adding the forth exact same Serial.println. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.