1

i just started using Arduino IDE for my XMC1100XMC2Go. Information about the microcontroller can be found here: https://github.com/Infineon/XMC-for-Arduino/wiki/XMC-2Go

I now started with my first codes and want to print things on the serial monitor with this code:

*/
/* For on board LEDs */
#include <LED.h>

/* Create an LED object */
LED Led;

//#define SERIAL_DEBUG 1

int p_LED = 5;
int p_Button = 4;
int i_stateButton = 0;

void setup()
{
  Led.Add(LED1);            // Configure the LEDs
  Led.Add(LED2);
  pinMode(p_LED, OUTPUT);
  pinMode(p_Button, INPUT);

  // Set default state of LEDs
  Led.On(LED2);
  Led.Off(LED1);

  digitalWrite(p_LED, LOW);
  Serial.print("Hello World!");

  Serial.begin(9600);
}


void loop()
{
  Serial.write("Hello World!");
  Serial.println(i_stateButton);
  delay(200);
  Led.Toggle (LED2);
  Led.Toggle(LED1);

  i_stateButton = digitalRead(p_Button);
  //digitalToggle(p_LED);
  digitalWrite(p_LED, i_stateButton);
}

I checked under tools that SerialOutput is set to PC (https://github.com/Infineon/XMC-for-Arduino/blob/master/variants/XMC1100/config/XMC1100_XMC2GO/pins_arduino.h#L54)

There are two Ports, COM1 and COM3. I can send new sketches to the microcontroller using COM3. I checked my Serial Monitor and it is set to COM3, too.

Baudrate is for both the same (code and monitor)

Now that i send the above sketch to the microcontroller it stops working. one LED is on and the other is off. But they do no longer change the state. Nothing appears on the monitor. When i remove the both lines Serial.write("Hello World!"); Serial.println(i_stateButton); and send the sketch, the LEDs start flashing again.

I'm pretty sure it's a kind of configuration problem, but i cannot find out what it is. Does anyone have an idea?

7
  • 1
    Maybe you should avoid printing to Serial before calling Serial.begin(). – Edgar Bonet Oct 6 '20 at 8:26
  • serial.begin() is in the setup part. Or does this belong to the loop? – Stack Oct 6 '20 at 8:44
  • 1
    What do you have right before Serial.begin()? – Edgar Bonet Oct 6 '20 at 8:45
  • 1
    Ouch. Thank you – Stack Oct 6 '20 at 8:46
  • 1
    There was a Serial.print("Hello World!"); before Serial.begin(9600); Thanks @Edgar Bonet – Stack Oct 6 '20 at 8:47
1

In the setup(), you have:

Serial.print("Hello World!");
Serial.begin(9600);

One should avoid printing to the serial port before enabling it with Serial.begin().

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.