bit write on an Arduino Uno

I am using an Arduino Uno…
Trying to read a ADC (LTC2400) :
along my sketch:

for (int Ctr =0; Ctr <32; Ctr ++) {
digitalWrite (LTC_SCK, LOW);

…As soon as I write the following:

“valu bit (0) = bitRead (LTC_MISO, Ctr);”
so that I can deal with the answer, the compiler tells me
“Error compiling for board Arduino/Genuino Uno”

I don’t get the meaning of this message
I have loaded a similar app (Application Demo: 7 digit voltmeter) which seems to utilise similar (if not exactly) and it uploads perfectly (???)
Can anyone help please?
Robert B

There was more to the error message than that. You left out the part where it says what the error is.

valu bit (0)  = bitRead   (LTC_MISO, Ctr);

What is that supposed to be on the left hand side of the equal sign. I can’t even figure out what you mean by that. The compiler won’t even try to figure it out, it’s not legal code so it spits out an error.

Maybe posting all the code instead of just one line would help someone to figure out what you are trying to do here.

for (int Ctr =0; Ctr <32; Ctr ++) {
      digitalWrite  (LTC_SCK, LOW);

What’s the use in writing the same pin low 32 times in a row. Are you afraid that the first 31 might not take?

Along the way I tried different ways of writing the corresponding bit of the variable “valu” which I have declared as “int valu;”
I have tried also changing the declaration by “long”, or “long long” and even “unsigned long”…

Wath I’m trying to do is to read very small voltage valu…

Cybergo: Along the way I tried different ways of writing the corresponding bit of the variable "valu" which I have declared as "int valu;"

Instead of guessing a bunch of different things that don't work, why not check the reference section for the right way. Reading is a lot more effective than guessing.

I mean why not just use this function: https://www.arduino.cc/en/Reference/BitWrite

You could also use bit math. Again see the reference for any parts of this you don’t understand.

valu = valu | 1 << 8;  // Sets the 9th bit in valu to 1
valu = valu & ~1<<8;  // clears the 9th bit in valu

I started at Reference before getting to the forum…

From the LTC2400 datasheet: It specifies “Internal Serial Clock, Continuous Operation” and goes to a bit 0 to bit 31 loop: I programmed that way:

void loop() {
digitalWrite (LTC_CS, LOW);

for (int Ctr =0; Ctr <32; Ctr ++) {
digitalWrite (LTC_SCK, LOW);
valu bit (0) = bitRead (LTC_MISO, Ctr);
// Serial.print (valu bit (0));
//bitWrite (LTC_MISO, Ctr, valu);
digitalWrite (LTC_SCK, HIGH);
}
digitalWrite (LTC_CS, HIGH);
Serial.println ();
delay (100);
}
I have tried different ways to specifie the corresponding bit from variable “valu” but I always end-up with the same compiler error message ???

Cybergo: I have tried different ways to specifie the corresponding bit from variable "valu" but I always end-up with the same compiler error message ???

Yes, but have you tried the function I linked you to from the reference? Why just make up nonsense and hope the compiler will understand? It won't.

Can you describe what you want to happen in the end? All this stuff you're writing makes no sense. You're reading bits from pin numbers? If you want to get anywhere it is time to post some details about your project and post ALL the code so that maybe someone can try to make some sense out of this nonsense. Post some details about what you're doing, and I mean detailed as if you think nobody here knows anything about it. Telling us something we already know is a lot less harmful to your chances than leaving out something we don't.

Over my ol' head but here's a link that might help:

http://interface.khm.de/index.php/lab/interfaces-advanced/connect-a-ltc2400-high-precision-24-bit-analog-to-digital-converter/

Are you trying to read the bit value from LTC_MISO and write that same value at the same bit location in valu? If so, this is what I got from a quick look at the Reference.

bitWrite(valu, Ctr, bitRead(LTC_MISO, Ctr));

Cybergo:
I have loaded a similar app (Application Demo: 7 digit voltmeter) which seems to utilise similar (if not exactly) and it uploads perfectly (???)
Can anyone help please?
Robert B

Are you talking about that code?

seriously, where do you see them do something even remotely “similar (if not exactly)” to your valu bit (0)  = bitRead  (LTC_MISO, Ctr);

 digitalWriteFast(LTC_CS, LOW);             // LTC2400 CS Low
 delayMicroseconds(1);
 if (!(digitalReadFast(LTC_MISO))) {    // ADC Converter ready ?
   //    cli();
   ltw=0;
   sig=0;
   //delayMicroseconds(1);

   b0 = SPI.transfer(-1);             // read 4 bytes adc raw data with SPI
   if ((b0 & 0x20) ==0) sig=1;  // is input negative ?
   //b0 &=0x1F;                   // discard bit 25..31
   ltw |= (b0 & 0x1F);
   ltw <<= 8;
   b1 = SPI.transfer(-1);
   ltw |= b1;
   ltw <<= 8;
   b2 = SPI.transfer(-1);
   ltw |= b2;
   ltw <<= 8;
   b3 = SPI.transfer(-1);
   ltw |= b3;

   //delayMicroseconds(1);

   //digitalWriteFast(LTC_CS, HIGH);           // LTC2400 CS Low
   
   if (sig) ltw |= 0xf0000000;    // if input negative insert sign bit
   ltw=ltw/16;                    // scale result down , last 4 bits have no information
   volt = ltw * v_ref / 16777216; // max scale
   char tmp[10];
   dtostrf(volt,6,6,tmp);
   tmp[8]='V';
   tmp[9]='\n';
  Serial.print(cnt++);
  Serial.print(";  ");
  printFloat(volt,6);           // print voltage as floating number
  Serial.println("  ");
 }

I’m a bit :o :o :o

You got it right evanmars

regards...

Delta_G first, tank's to look over but evedently, "Ctr" have been defined in the declaration: "#define Ctr (byte)"

I have started the project by defining a "bit" size to put the temporary valu in and then transfer that valu in the end long word... and that's where my headache started..

By the way, why when I declare a "bit" it rights it in a red color when all the other are in a light blue color? There is surely a meaning for that

Regards

There's no meaning to colors in arduino IDE. It just means someone put that word in a keywords file somewhere.

The rest of that post makes no sense to me. You're going to have to explain what bit you want to go where. And post all the damned code or I'm not reading any more of this thread. I don't like guessing what your variables are referring to.

My impression is that he's reimplementing shiftIn(), but with opposite clock polarity, and for a 32-bit value