I would like to switch between digitalWrite() and serial1.write() in Arduino Due.
However, Serial1.write() from digitalWrite() will not be able to communicate properly.
If you send serial data, the first transmission will succeed, but 0 will be sent after the second transmission.
By the way, Arduino Mega can switch and communicate.
I would like to know the cause and how to make the following ideal reception data.
この This target Due is communicating with another Due, Serial1 tx/rx, and the other Due is sending the data received in Serial1 to the serial monitor of the PC connected by a USB cable in hexadecimal.
void setup(){
const byte txData[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
// Serial1.write (1st time)
Serial1.begin(9600);
Serial1.write(txData, 6);
Serial1.end();
delay(1000);
// digitalWrite
pinMode(18, OUTPUT);
digitalWrite (18, LOW);
delay(50);
digitalWrite (18, HIGH);
delay(100);
// Serial1.write (second and later)
for (byte i=0; i<5;i++)
{
Serial1.begin(9600);
Serial1.write(txData,3);
Serial1.flush();
Serial1.end();
delay(1000);
}
}
void loop() {
}
AA BB CC DD EFF
AA BBCC
AA BBCC
AA BBCC
AA BBCC
AA BBCC
AA BB CC DD EFF
00
dArduino Due <
https://store-usa.arduino.cc/collections/boards/products/arduino-due
https://content.arduino.cc/assets/A000056-full-pinout.pdf
https://teratail.com/questions/h3km9w6nkmhjgm
https://qiita.com/alyn/questions/78d9963e81f53ab13f75
About switching between digitalWrite() and Serial1.write()
If you rewrite it as follows, it seems that you can make it work the same way.
It's not a fundamental solution, but I'll fix it now.
before change:
digitalWrite(18,LOW);delay(50);
after modification:
uint8_t Zero[1]={0};Serial1.begin(160);Serial1.write(Zero,1);
© 2024 OneMinuteCode. All rights reserved.