Hello folks, hope you are having a great day if the sun is still up in your part of the world; else, hope all is still ok.
I just built an I2C experiment to get myself more familiar with it. The point of the experiment is to make myself familiar with all the I2C data that is generated on my OScope.
The process is very simple as you can see. The User turns on the button on the Master and the signal goes through the I2C lines and turns on the LED on the slave. ( Both Master and Slave are NANOs in this case. )
Here comes the main point:
I hooked up the I2C bus to my OScope. You can see the OScope screenshots below.
-
In Pic 1 below, In the top left corner, what does the -14.9340us mean?
-
In Pic 1 below, In the top left corner, what does the address 0x10 ( in green ) mean?
-
In Pic 1 below, In the top center, what does the 0x64 mean? ( This 0x64 is shown under the data column)
-
As you can see in the Master sketch, we are writing either 100 or 101 to the slave. Are the '100' and '101' some how being represented by the pink square waves?
-
If you look closely at the "DATA" column in Pic 1 and Pic 2, the value changes from 0x64 to 0x65. Why does it change and what does it mean? Does it mean it is transitioning from 'case 100' to 'case 101'? ( The cases are in the slave sketch)
-
The slave address is 0X08 in the slave code. Is it supposed to show up, somewhere at all?
Other refernce pics are also included below.
Thank you for your replies!
Above is PIC # 1
Above is PIC #2.
Above is PIC # 3
Above is PIC#4
// MASTER CODE BEGINS BELOW.
#include <Wire.h>
const int signalSwitch = 4;
int switch1State = 0;
void setup()
{
Wire.begin();
pinMode(4, INPUT); // Sets pin 4 as input.
}
void loop()
{
switch1State = digitalRead(4);
// send command to start blinking
if (switch1State == HIGH) {
Wire.beginTransmission( 0x08);
Wire.write( 100);
Wire.endTransmission();
delay(2000);
}
else (switch1State == LOW); {
// send command to stop blinking
Wire.beginTransmission( 0x08);
Wire.write( 101);
Wire.endTransmission();
delay(2000);
}
}
// MASTER CODE ENDS HERE.
// SLAVE CODE BEGINS BELOW
#include <Wire.h>
volatile bool enableBlinking = false;
void setup()
{
Wire.begin(0x08); // join I2C bus as Slave with address 0x08
Wire.onReceive( receiveEvent);
pinMode( 13, OUTPUT);
}
void loop()
{
if ( enableBlinking)
{
digitalWrite( 13, HIGH);
delay( 100);
digitalWrite( 13, LOW);
delay( 100);
}
}
void receiveEvent( int howMany)
{
if ( howMany == 1) // extra safety check, expecting just one byte
{
int x = Wire.read();
switch ( x)
{
case 100:
enableBlinking = true;
break;
case 101:
enableBlinking = false;
break;
}
}
}
// SLAVE CODE ENDS HERE.