I'm using an ADC wich is 24-bits resolution. So I save each byte in a different addres of the EEPROM. Now I want to read the data from the EEPROM and show it out using the arduino serial port monitor. So I take the 3 bytes and mix them to get a 24-bit numer. For example:
I'm using an ADC with a 24-bits resolution. So I save each byte in a different EEPROM address. Now I want to read the data from the EEPROM and show it out using the arduino serial port monitor. So I take the 3 bytes and mix them to get a 24-bit numer. For example:
byte 1=1F
byte 2=2F
byte 3=FF
So I get----> 1F 2F FF
I'm using this code:
#include <EEPROM.h>
int address = 1;
byte value;
bool flag=0;
byte Valor[3];
int Val = 0;
void loop()
{
// read a byte from the current address of the EEPROM
for(int i=1;i<=3;i++){
value = EEPROM.read(address);
Valor*=value;*
address = address + 1;*
}*
Val=(Valor[1] << 16)+(Valor[2] << 8)+Valor[3];
Serial.print("Val=");*
Serial.print(Val);*
Serial.print(";Valor[1]=");*
Serial.print(Valor[1]);*
Serial.print(";Valor[2]=");*
Serial.print(Valor[2]);*
Serial.print(";Valor[3]=");*
Serial.print(Valor[3]);*
Serial.println();* if (address == EEPROM.length()) {
flag=1;*
while(flag=1){}*
}*
delay(5);* } I notice that if the variable I'm sending through the serial port is more than 16 bits does not work(the value I visulaize is "0"). There is any possibility to visualize a 24 bit variable in the serial port monitor? Thank you in advance
I don't have problems in reading the EEPROM(I saved some values in the EEPROM first and I read them well). In fact if I do what you propose I would be reading all the time the same three registers address. My address start at 1 so the sequens would be: 1,2,3 and start again 1,2,3. I need to increment the address by one every time I read from the EEPROM.
Danois90:
The way you read your EEPROM is wrong, look at this approach:
What is your 8 bit value going to look like after you've shifted it 16 places to the left?
You need to cast Valor[n] to an unsigned long BEFORE applying the shift operator to it.
Yes, you are right I did not think about that...I declared Valor[n] as unsigned long but now the serial port monitor is not working...
Do you know the reason?
Joaremi:
I don't have problems in reading the EEPROM(I saved some values in the EEPROM first and I read them well). In fact if I do what you propose I would be reading all the time the same three registers address. My address start at 1 so the sequens would be: 1,2,3 and start again 1,2,3. I need to increment the address by one every time I read from the EEPROM.
You do know that the first byte in EEPROM start at address 0? If you want to incrementally read 3 bytes for each iteration of "loop()" then just do:
But this code is not safe (neither is the code you posted), you may end up reading beyond size of EEPROM. You could avoid this by making the first line in "loop()" look like this:
wildbill:
It's not valor that needs to be unsigned long but rather val. You're still using the wrong indices too.
I changed both(val,valor) before send the las post(I did not say it, sorry). I don't understand why the indices are wrong, I start "i" with 1 and end it with 3, so I get three values: Valor[1],Valor[2] and Valor[3]...