Hi guys, I am working on a project with Serial. I am sending 2 commands to the slave device, but only the first command appears to be read. The second command executes, albeit appears to execute incorrectly, only when I open the serial monitor. It’s kind of doing what I want…but not quite. Any suggestions would be helpful.
I’m not even sure the first command is quite right. It goes kinda slow, but idk. Maybe that command is supposed to be slower. It’s hard to say.
uint8_t arr[]={0x42, 0x10, 0xcc};
uint8_t new_arr[]={0x43,0x50,0x3F,0x22,0xFF,0xFF};
void setup()
{
Serial.begin(9600);
pinMode(1,OUTPUT);
digitalWrite(1, HIGH); //set high as per the data sheet recommendation to mitigate spurious data
// UCSR0C = UCSR0C | B00000110;
delay(1000);
Serial.write(0x55);
serial_response();
delay(1000);
dostuff(arr, sizeof(arr)); // the name of an array points to the array & you are passing 10 values
dostuff(new_arr, sizeof(new_arr)); // the name of an array points to the array & you are passing 10 values
}
void loop()
{
serial_response();
}
void dostuff(uint8_t *a, int BUF)
{
Serial.write(a, BUF); // Serial.write wants the array pointer and the number of elements
/*more stuff*/
serial_response();
// memset(&a, 0, BUF);
}
void serial_response(){
// // delay(1);
// int incomingByte=0;
// if (Serial.available() > 0) {
// // read the incoming byte:
// incomingByte = Serial.read();
// //if (incomingByte = 0x15)
// // Serial.print("I received: ");
// Serial.println(incomingByte, HEX);
// }
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.