View previous topic :: View next topic |
Author |
Message |
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
Address with the DS2438 battery monitor |
Posted: Mon Mar 27, 2006 6:39 am |
|
|
Hello,
I'm using the DS2438 for monitoring a 10V NiMh battery, i need to read the voltage register and the current register.
So in the datasheet, the current register is in the page 0 byte 3 and 4. So i don't know how to wrote the address in my program the page is the first byte and the byte the second;
0x03 for page 0 byte 3
0x12 for page 1 byte 2
This is my code to read the voltage register :
void ReadVoltage (void)
{
if(!Reset())
{
WriteByte(SkipNetAdress); // SkipNetAdress Command
WriteByte(Read); // Read Registers Command
WriteByte(0x03); // Voltage Register Address
Voltage=ReadByte();
Voltage= Voltage<<8;
Voltage = Voltage+ReadByte();
Tension=((float)Voltage)*1/100; //10mV volt/bit, la pr飩sion n'est
}
} |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Mar 27, 2006 9:39 am |
|
|
I think you are confusing a nibble and a byte.
Quote: | the page is the first byte and the byte the second; |
above where you state 0x03 is page0 byte 3, I think you want
0x0003
And in the code you would have an extra writebyte()
it would be
Code: |
WriteByte(SkipNetAdress); // SkipNetAdress Command
WriteByte(Read); // Read Registers Command
WriteByte(0x00); // Voltage Register Address
WriteByte(0x03); // Voltage Register Address
Voltage=ReadByte();
Voltage= Voltage<<8;
Voltage = Voltage+ReadByte();
|
|
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Wed Mar 29, 2006 1:46 am |
|
|
it doesn't working, i already use this code for the DS2770, i think i can use the same code, i just need to modify the adress. I don't know why it's not working. |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Fri Mar 31, 2006 1:38 am |
|
|
Its now working, this is the code that we need to use, first read all the register, and to recover the data, we need to read the scratchpad:
if(!Reset())
{
WriteByte(0xCC); //skip ROM
WriteByte(0x44); //read temperature slot
}
if(!Reset())
{
WriteByte(0xCC); //skip ROM
WriteByte(0xB4); //read voltage slot
}
if(!Reset())
{
WriteByte(0xCC); //skip ROM
WriteByte(0xB8); //call memory page 00
WriteByte(0x00);
}
if(!Reset())
{
WriteByte(0xCC); //skip ROM
WriteByte(0xBE); //read page 00
WriteByte(0x00);
}
if(!Reset())
{
WriteByte(0xCC); //skip ROM
WriteByte(0xBE); //read scratchpad
WriteByte(0x00);
}
//read 9 bytes of data
Variable1=ReadByte();
Variable2=ReadByte();
Variable3=ReadByte();
Variable4=ReadByte();
Variable5=ReadByte();
Variable6=ReadByte();
Variable7=ReadByte();
Variable8=ReadByte();
Variable9=ReadByte(); |
|
|
|