Ive attempted some code
I could make one send a message and the other receive it,
then i tried making a call and answer
I have the master sending out then goes into receive mode whats for a response
While the slave waits then receives then goes into send then back to receive
But the code i am running is not receiving the intial message like it did when i had it running in just a single transmission mode.
MASTER:
#include <Stdio.h>
#define dirPin 4
char charArray[5]
uint8_t HeadingData[] = {0x10, 0x01, 0x0A, 0x10, 0x2B};
uint8_t Angle[] = {0x10, 0x02, 0x0B, 0x10, 0x2C};
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
Serial.println(sizeof(HeadingData));
}
void loop()
{
digitalWrite(dirPin, HIGH);
sendMSG(HeadingData);
Serial.println("message sent");
digitalWrite(dirPin, LOW);
while(Serial.available() == 0);;
recieveMSG();
Serial.println("message recieved");
}
void recieveMSG()
{
int charIndex = 0;
while (Serial.available())
{
int recieved = Serial.read();
delay(5);
charArray[charIndex] = recieved; // store everything that was read in charArray byte-by-byte
//charArray[charIndex+1] = '\0'; // add a NULL value
charIndex++;
}
Serial.println(charArray[0], HEX);
Serial.println(charArray[1], HEX);
Serial.println(charArray[2], HEX);
Serial.println(charArray[3], HEX);
Serial.println(charArray[4], HEX);
Serial.flush();
}
void sendMSG(uint8_t Message[])
{
for(int i = 0; i < sizeof(HeadingData); i++)
{
Serial.write(HeadingData[i]);
Serial.println(HeadingData[i], HEX);
}
}
SLAVE:
#include <Stdio.h>
#define dirPin 4
char charArray[5];
uint8_t HeadingData[] = {0x10, 0x01, 0x0A, 0x10, 0x2B};
uint8_t Angle[] = {0x10, 0x02, 0x0B, 0x10, 0x2C};
void setup()
{
Serial.begin(9600);
pinMode(4, OUTPUT);
}
void loop()
{
digitalWrite(dirPin, LOW);
while(Serial.available() == 0);;
if (Serial.available())
{
recieveMSG();
Serial.println("message received");
}
digitalWrite(dirPin, HIGH);
sendMSG(HeadingData);
Serial.println("message sent");
}
void recieveMSG()
{
int charIndex = 0;
int intIndex = 1;
int max_intIndex;
number = 0;
while (Serial.available())
{
int recieved = Serial.read();
delay(5);
charArray[charIndex] = recieved; // store everything that was read in charArray byte-by-byte
//charArray[charIndex+1] = '\0'; // add a NULL value
charIndex++;
}
Serial.println(charArray[0], HEX);
Serial.println(charArray[1], HEX);
Serial.println(charArray[2], HEX);
Serial.println(charArray[3], HEX);
Serial.println(charArray[4], HEX);
Serial.flush();
}
void sendMSG(uint8_t Message[])
{
for(int i = 0; i < sizeof(Angle); i++)
{
Serial.write(Angle[i]);
Serial.println(Angle[i], HEX);
}
the master is receiving this :
D
A
10
31
30
the slave is getting the same thing pretty much except for the last number which isn't 30 but something else.
Any ideas?