Hi,
I am using hifive1 mcu which is an arduino compatible board. I have done many projects in this using arduino ide. I have created a new projects where it contains a "String variable", when i try to print the variable in the serial monitor It is not printing ! i dont know why, previously it was working well.Suddenly i am facing this weird issue.
The same sample code when i run in arduino uno it is working well, when it comes to my Hifive1 it doesn't print the String variable alone all the other println are printing.
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("\n\nString charAt() and setCharAt():");
}
void loop() {
// make a String to report a sensor reading:
String reportString = "SensorReading: 456";
Serial.println(reportString);
// the reading's most significant digit is at position 15 in the reportString:
char mostSignificantDigit = reportString.charAt(15);
String message = "Most significant digit of the sensor reading is: ";
Serial.println(message + mostSignificantDigit);
// add blank space:
Serial.println();
// you can also set the character of a String. Change the : to a = character
reportString.setCharAt(13, '=');
Serial.println(reportString);
// do nothing while true:
while (true);
}
It is doing exactly what you are telling it to do - look carefully at your code.
As you have only posted a snippet I have no idea what you are hoping it would do. Post a complete program that illustrates the problem.
Separately, and not directly related to your problem, it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Actually i have given the complete code. Scroll down in the code box to see the loop().
The issue is it is not printing the Serial.println()'s which is in the loop().
That board seems to have plenty of RAM, so I don't think that use of Strings (bad idea though it is) can be the issue.
That it works on an Arduino (it certainly does on my Uno) suggests that the problem lies with the hifive1 or more likely, the toolchain you're using to program it.
I suspect there is a problem in the run-time code provided for the Freedom E310 processor of your HiFive1 board. I'd try putting the code into setup() and leaving loop() empty in case there is a problem caused by the while(1);
Yes , that is "Sifive".
I have put this query in their forum as well. Assumed that the people who worked with the board which i am using may also there in this forum as the board is an Arduino compatible one.
No i didn't modify the code. Even i guess the same.
Don't know what happened in between! because i have done many projects and used these Strings before.
i am trying to find out the issue.If you are able to sort out the issue kindly let me know.So that i will mention the topic as [Resolved]