16bit Binary

Hopefully I do not come across as too silly on this one. I have an eeprom which is 16X16 serial and I have been able to sucessfully read it and get the 16bit's of binary from each of the 16 address's. But I dont know what to do from there what do I do with all the bits to be able to print it as a decimal number. I hope someone can help me and I hope that made sense.

Thanks

l and I have been able to sucessfully read it and get the 16bit's of binary from each of the 16 address's.

If you post the sketch we can see what form you have read it in, there is not enough information in this post to enable people to see what is happening.

Everything is working with this code all 16 bits are being output on the serial, I need to know how I can collect those bits and convert them to a decimal number.

int SS1 = 10; // set slave select pin
int CLK = 13; // set clock pin
int MOUT = 11; // set master out, slave in pin
int val = 0;

byte rcl = B10000101; // Recall Eeprom data
byte wren = B10000100; // Write Enable Latch 
byte add = B11100111; // READ



/* SETUP */

void setup() { 

// setup function begins here
Serial.begin(9600);
Serial.println("Start");
pinMode(SS1, OUTPUT); // set CS pin to output
pinMode(CLK, OUTPUT); // set SCK pin to output
pinMode(MOUT, OUTPUT); // set MOSI pin to output
digitalWrite(SS1, LOW); // hold slave select 1 pin LoW, so that chip is not selected to begin with

}
//////////////////////////////////////////////////////////////////////////////////////////



void spi_transfer(byte working) {

// function to actually bit shift the data byte out

for(int i = 1; i <= 8; i++) { // setup a loop of 8 iterations, one for each bit

if (working > 127) { // test the most significant bit

digitalWrite (MOUT,HIGH); // if it is a 1 (ie. B1XXXXXXX), set the master out pin high

}

else {

digitalWrite (MOUT, LOW); // if it is not 1 (ie. B0XXXXXXX), set the master out pin low

}

digitalWrite (CLK,HIGH); // set clock high, the eeprom will read the bit into its register

working = working << 1;

digitalWrite(CLK,LOW); // set clock low, the pot IC will stop reading and prepare for the next iteration (next significant bit

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void spi_read(byte working) {

; // function to actually bit shift the data byte out

for(int i = 1; i <= 7; i++) { // setup a loop of 7 iterations, one for each bit

if (working > 127) { // test the most significant bit

digitalWrite (MOUT,HIGH); // if it is a 1 (ie. B1XXXXXXX), set the master out pin high

}

else {

digitalWrite (MOUT, LOW); // if it is not 1 (ie. B0XXXXXXX), set the master out pin low

}

digitalWrite (CLK,HIGH); // set clock high, the pot IC will read the bit into its register

working = working << 1;

digitalWrite(CLK,LOW); // set clock low, the pot IC will stop reading and prepare for the next iteration (next significant bit

}


digitalWrite (CLK,HIGH);
pinMode(MOUT, INPUT); // set MOSI pin to Input
digitalWrite(CLK,LOW);
val = digitalRead(MOUT); // Reading the first bit 
Serial.println (val);

for(int i = 1; i <= 15; i++) { // reading the other 15 bits

digitalWrite (CLK,HIGH); //brings the next byte
val = digitalRead(MOUT); // read the byte 
Serial.println (val); // Print the byte    = HELP HERE PLEASE !!!!!
digitalWrite (CLK,LOW);

}
pinMode(MOUT, OUTPUT);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void spi_out(int SS, byte cmd_byte) { // SPI tranfer out function begins here

digitalWrite (SS, HIGH); // set slave select high to enable 

work = cmd_byte; // let the work byte equal the cmd_byte, defined in the argument in the main loop

spi_transfer(work); // transfer the work byte, which is equal to the cmd_byte, out using spi

digitalWrite(SS, LOW); // set slave select low 

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void spi_out1(int SS, byte cmd_byte) { // SPI tranfer out function begins here

digitalWrite (SS, HIGH); // set slave select high

work = cmd_byte; // let the work byte equal the cmd_byte, defined in the argument in the main loop

spi_read(work); // transfer the work byte, which is equal to the cmd_byte, out using spi

digitalWrite(SS, LOW); // set slave select low

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop () {


spi_out(SS1, rcl ); // send out data 
spi_out(SS1, wren ); // send out data
spi_out1(SS1, add ); // send out data 

delay(500000); // delay


}

marca404,

I am guessing that you are trying to re-assemble the binary bits together back to the number they represents. If this is the case, you can use the following method:

num = i1<<7 | i2 <<6 | i3 <<5 | i4 <<4 | i5 <<3 | i6 << 2 | i7 <<1 | i8

Also this is the eeprom i am accessing

I see what your getting at but the numbers I am dealing with is 16bit

can you just start from the 15th bit then?

num = i1 << 15 | .... i15 << 1 | i16

num = i1 << 15 | .... i15 << 1 | i16

I'm not really understanding what is happening there I am pretty new to this.

I'm not really understanding what is happening there I am pretty new to this.

It is bit manipulation, see:-

http://www.arduino.cc/playground/Code/BitMath

OK thanks, looks like I got a bit of reading to do for working this one out.