Sorry guys, I thought the Data Log explained it all.
When using the wire library and you tell it NOT to send a Stop "P" but do a Repeated Start "Sr"
I should not see any Stops "P" or Starts "S" in the data Log. (until it is acknowledged)
We have to go back in time 20 years using cheap processors, I think this is a Elan EM78P459 processor (as requested I won't put a link to the data sheet).
Oh, may be this may help. I am trying to add an Arduino to an existing robot that is working perfectly.
It has several processors in it that talk to each other via I2C, a very slow I2C, but as it is clock based it should not be a problem.
Why do I want to add an Arduino? Because I want to add Bluetooth or Wi-Fi, Currently it is IR.
@ Koepel
Do what you preach, did you test your code?
This is the result after fixing your code.
I didn't realize upload was for IMG images, thought it was for code files. (hope it is I don't see preview as I write)
I put my post in Libraries because I don't think the library is correct.
![Capture258](https://europe1.discourse-cdn.com/arduino/original/4X/e/3/9/e39bac73d7295fb59427fcb49f6907ad315d495b.png)
So back to my whole code.
#include <Wire.h>
#define MOTOR_ADDRESS_L 0x4B
#define MOTOR_ADDRESS_R 0x48
byte x = 0;
byte WriteState = 0;
byte BytesWritten = 0;
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setTimeout(250);
Wire.setClock(1250);
/*
Speed Tests
Target = 23 - 44
10000 = 250 - 4
5000 = 125 - 8
2500 = 63 - 16
1250 = 31 - 32
625 = 31 - 32
There are some interesting aspects to the endTransmission() function. First, it returns a byte value to let you know what the status of the data transmission was�
Value Returned Name Description
0 SUCCESS The attempt to write to your slave component was successful.
1 DATA EXCEEDS BUFFER LENGTH You are attempting to send more than 32 bytes of data.
2 NACK ON ADDRESS TRANSMIT Either the component you're attempting to talk to is offline, or you mistyped the I2C address for it. Which do you think is more likely?
3 NACK ON DATA TRANSMIT The slave component responded to its address with an ACK, but did not respond that it received the data successfully.
4 OTHER ERROR This means your I2C write request to the slave component failed in some other fashion, most likely dealing with gremlins.
*/
}
void loop()
{
//x = 7;
x = B00000111;
WriteState = 0;
BytesWritten = 0;
Wire.beginTransmission(MOTOR_ADDRESS_L);
BytesWritten = Wire.write(x);
WriteState = Wire.endTransmission(false); // false = Do NOT send a Stop, do a repeat start.
while (WriteState == 2) { // Wait untill acknolages master. write state = 0
Wire.write(x);
WriteState = Wire.endTransmission(false); // false = Do NOT send a Stop, do a repeat start.
/*
The delay does not need to be here.
Its just so the data loger does not get over tasked.
The resut should be the same.
I still should not be seeing any stops in this section.
*/
delay(10);
}
Wire.write(x); // dose not matter that I send again.
WriteState = Wire.endTransmission(true); // when slave replies, write state = 0. finish with a Stop.
delay(500); // Delay before trying again.
}
Notes before you say:
I2C clock, You will see in comments I tested clock speeds to see how Slow I could get it. (Old processor remember)
This is what I am trying to achieve:
The robot is working perfectly, it is doing wat it is supposed to.
You can see that the master is keeps sending until the slave responds.
You will see that the master does NOT send any STOPs.
There is a REPEAT START between each attempt to send the data.
There is only a STOP after the slave sends an ACK.
It is what I am trying to get with my code, but I am getting.
This is stuck in the loop (while).
You will see, every time it attempts to send data it finishes with a STOP "P", according to the
Wire Library, the Boolean
false = DONT send a STOP.
In the loop (while) in my code if no Stop "P" was sent, then the START "S" would be a Start repeat "Sr".
It looks to me like the Wire Library, when you tell it not to send a stop, it just flags the code to remember the address so that you don't have to use the "beginTransmission" while you continue to write data to that address.
The screenshots show signals on the wires.
It's the Wire Library that controls that.
Difference between a Start "S" and Start repeat "Sr". There is no Stop "P" before a Start repeat "Sr".
If my code is wrong and it should be sending Stops, please explain why.
I think the slave, when it looks at the I2C, it checks to see if it is being used, if so, it waits for a new start and then checks to see if it is for the slave.
I think there is some bespoke stuff on this robot.
All my data logs of the robot communication have had a least two attempts to send data before an acknowledgement.
This is why having a Stop at the end of each attempt (Arduino Library) to contact the slave does not work.
Having a stop, releases the bus, so the slave, when it comes to check if the bus is in use, it see that it is not, and goes of about its other tasks.