Added USB-Serial baud rate selection

This commit is contained in:
Kevin Santo Cappuccio 2024-01-12 12:25:34 -08:00
parent 4272a69aec
commit f9e199d687
3 changed files with 38 additions and 3 deletions

View File

@ -29,6 +29,14 @@ void initArduino(void) // if the UART is set up, the Arduino won't flash from it
delay(1);
}
void setBaudRate(int baudRate)
{
Serial1.end();
delay(1);
Serial1.begin(baudRate);
delay(1);
}
void arduinoPrint(void)
{
}

View File

@ -18,7 +18,7 @@ void arduinoPrint(void);
void uploadArduino(void);
void setBaudRate(int baudRate);

View File

@ -121,6 +121,7 @@ char input;
int serSource = 0;
int readInNodesArduino = 0;
int baudRate = 115200;
void loop()
{
@ -139,7 +140,7 @@ menu:
Serial.print("\tw = waveGen\n\r");
Serial.print("\tv = toggle show current/voltage\n\r");
Serial.print("\tf = load formatted nodeFile\n\r");
Serial.print("\tp = paste new Wokwi diagram\n\r");
Serial.print("\tu = set baud rate for USB-Serial\n\r");
Serial.print("\tl = LED brightness / test\n\r");
Serial.print("\td = toggle debug flags\n\r");
Serial.print("\tr = reset Arduino\n\r");
@ -391,6 +392,30 @@ skipinput:
break;
case 'u':
Serial.print("\n\r");
Serial.print("enter baud rate\n\r");
while (Serial.available() == 0)
;
baudRate = Serial.parseInt();
Serial.print("\n\r");
Serial.print("setting baud rate to ");
Serial.print(baudRate);
Serial.print("\n\r");
setBaudRate(baudRate);
break;
case 'd':
{
debugFlagInit();
@ -622,6 +647,7 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
char ch = USBSer1.read();
Serial1.write(ch);
}
if (Serial1.available())
@ -644,13 +670,14 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
char ch = USBSer1.read();
Serial1.write(ch);
// Serial.print(ch);
}
if (Serial1.available())
{
char ch = Serial1.read();
USBSer1.write(ch);
// Serial.print(ch);
//Serial.print(ch);
if (ch == 'f' && connectFromArduino == '\0')
{