I2C

Hi, I'm back with new Question regarding the I2C. I am trying to interface my Arduino with a Propeller Flip and i need to know if the I2C address for the Arduino is written as 0x4 or in a binary code.

The slave address, you mean? It only exists when the Arduino is running the I2C slave commands, and the address can be configured in software. You can write numbers in any base you like on a computer, but they always end up in binary. Even a string representation of a number is composed of symbols that are represented inside the computer as binary. So if you meant something else, you have to refine the question.

In I2C Protocol, the address is always 7-bit. For example -- the slave address is: 0000100. Is it 4 or 0x4 or 0x04? I have reservation to say -- yes! Why?

Sometimes, it is said that the write mode slave address is 0x08; where the slave address is still 7-bit -- the upper 7-bit of 0x10 (00001000) which is 0000100.

Sometimes, it is said that the read mode slave address is 0x09; where the slave address is still 7-bit -- the upper 7-bit of 0x09 (00001001) which is 0000100.

So, writing slave address as 0x4 or 0x04 (00000100) could be confusing as someone might take the 7-bit address as: 0000010 which is not.

Therefore, it is safe (at least for me) to write the slave address in plain 7-bit format.

When does it appear as 8-bit?
During the execution of the following codes (where data moves from from Master to Slave -- the write mode), the protocol shifts the 7-bit address to the left by 1-bit and then appends LOW (0) at the rightmost bit position.

Wire.beginTransmission(0b0000100);
Wire.write(0x23);
Wire.endTransmission();

Similarly, during the execution of the following codes (where data moves from from Slave to Master -- the write mode), the protocol shifts the 7-bit address to the left by 1-bit and then appends HIGH (1) at the rightmost bit position.

Wire.requestFrom(0b0000100, 2);

You could also download the standard I2C scanner and you will see the I2C address in the correct format for your attached device.

i need to know if the I2C address for the Arduino is written as 0x4 or in a binary code.

It simply doesn’t matter how you specify it.
4 - this is decimal
0x4 - this is hex
04 - this is octal
They all produce the same bit pattern in the computer.
Number bases are for humans, all the computer knows about is bit patterns, we then put meaning on those bit patterns according to what we want them to stand for.

What I am looking for is the slave address when arduino is the slave and the flip is the master.
I am going to try using the binary "0b0001001. would this be equivalent to the "4" as used in the chapter for using 2 arduinos ("arduino cookbook ,chapter13.9 ") Freq is only 5MHz.

Telescopeman:
would this be equivalent to the "4" as used in the chapter for using 2 arduinos

The post immediately before this one, and also reply #1, both answered that question... except that the decimal value of 0b00001001 is 9, not 4.

It's silly to use binary notation for I2C addresses, as they are really assigned by humans, and therefore read by humans.

I am switching from using i2c and going to try using serial since the propeller is incapable of being a slave but it can use serial.. my problem is I can't find an example of sending bytes to a different microcontroller.

Can you post a link to the propeller flip device you are attempting to interface with.
You can see an example of an Arduino configured as an I2C slave here: Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino

Tried to locate a link but unable to find one. Try www.parallax.com/product/32123. It's in the parallax web page. They say that the propeller cannot be used as a slave in I2C, One has to use serial to send data from an arduino master. I just need to see how the serial to another microcontroller. I am not using a terminal in the actual system. "arduino + propeller"flip".

They say that the propeller cannot be used as a slave in I2C

You can use an SPI protocol and bit bang the information over. You can drive that in either direction or both.

Here is how to bit bang a byte from the Arduino end:-

void SPIbang(int val) { // bit bang SPI so it is interruptible
  for ( int i = 0; i < 8; i++) {
    if ( (val & 0x80) == 0) {
      digitalWrite(SDIPIN, LOW);
    }
    else {
      digitalWrite(SDIPIN, HIGH);
    }
    digitalWrite(SCKPIN, HIGH); // toggle clock
    digitalWrite(SCKPIN, LOW);
    val = val << 1;
  }
}

And this is how to receive something from an Arduino by bit banging

byte readByte(){ // MSB first
  byte byteIn;
     byteIn = 0x1 & digitalRead(data); // get first bit
     for(int i=0; i<7;i++){ // get the rest of the byte
        while(digitalRead(ck) == LOW) { } // hold until clock is high
        while(digitalRead(ck) == HIGH) { } // hold until clock is low 
        byteIn = byteIn << 1; // make room for new bit
        byteIn |= 0x1 & digitalRead(data); // add new bit 
   }
   return byteIn;   
  }

You can use any set of pins to do the sending and receiving. I am sure you can translate this into spin language.

My system uses a 4 pin connector on the transmission line, two pins are for the power leaving 2 pins for communication . Sorry, need serial.

I can't find an example of sending bytes to a different microcontroller.

Can you send bytes to the serial monitor? It is the same as sending to a different microcontroller.

The serial input basics tutorial may be of interest.

Telescopeman:
My system uses a 4 pin connector on the transmission line, two pins are for the power leaving 2 pins for communication . Sorry, need serial.

SPI uses only 2 digital lines, clock and data. There is a device select, but it's optional.

If you want to send data to output pin(s) and you are not using"print" what would you use instead.?

aarg:
SPI uses only 2 digital lines, clock and data. There is a device select, but it's optional.

According to SPI Protocol, the SPI Port consists of:

SS/: Salve Select Line
MOSI: Master-out Serial-in Line (Data Out line)
MISO: Master-in Slave-out Line (Data In Line)
SCK: Serial Clock Line

For Atmega328P MCU, these lines get fixed with the following DPins (digital pins) of Fig-1 after the inclusion of the following codes in the sketch:

#include<SPI.h>
SPI.begin();

spi328x.png
Figure-1:

Most of the slave devices exchange data with Master using SPI Port; hence, MISO is an important line.

There are some slave devices like MAX7219 (display controller) etc. which do not send back any data/status to the Master; here, there is no use of MISO line.

spi328x.png

According to SPI Protocol, the SPI Port consists of:

Yes but we are not talking about the full SPI protocol only transferring data across.

Telescopeman:
If you want to send data to output pin(s) and you are not using"print" what would you use instead.?

Waggle the data line up and down interspersed with waggling a clock signal like I showed you.

Or just waggle the data line up and down with some protocol like a 1 wire bus protocol.

The mounting panel is cut for a 6p6c modular jack, a 4p4c modular jack and for a 8p8c modular jack. The 4p4c jack is for the hand controller. I don't want to change any of those, and the brains of the mount is not an arduino but a propeller 'flip' which has 8 microprocessors in the chip and it cannot work as a slave but it can use the serial bus.I don't want to use SPI.

and the brains of the mount is not an arduino

So why are you posting in an Arduino forum?

don't want to use SPI.

Any actual rational reason? Or is it you don’t understand it?