i2c devices

Questions on control of serial busses
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

thanks Dick, the pull high resistors both using 4.7K (even sparkfun new breakout
board using 10K). this is no problem. To verify the device is okay. I will going
to buy a RS232 to I2C module to test the device again.



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Bingo! Got the reading now. Since the I2C datarate of ARMite is 220Kb. The
device is 100Kb. finally they can make communicate now!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

May be I am happy too earlier, because I found the reading are strangest and
cannot reflect the exact angle. Then,
1) I bought another RS232 to I2C adaptor to check the HMC6352, and found it
works pretty good, all data are correct.
2) connect it again to ARMite and just write a simple instruction to get the
EEPROM data and RAM dat only. However, the data are not what I obtained in the
point one case. Logic sense, I thought there should be somthing wrong but I
cannot tell.
3) My firmware is using 7.36 and the I2Cspeed already set to 100
. All the command only take less then 100us , thus, no Wait() is necessary. The
Program are in the following, Hope you can give me next puzzle to solve this.

#define I2Cspeed100
#include


'Check the compass
'Read the mode and slave address of Compass
DIM shortMessage(10) AS STRING
DIM shortResponse(10) AS STRING

shortMessage(0)=0x67 ' Read Ram address command of the slave device
shortMessage(1)=0x74 ' Address '$74 stored the mode and reading should be $50
PRESENT=I2COUT (0,1,$42,2,shortMessage)'Write the command and address
IF PRESENT=0 THEN PRINT "NO I2C device ***"
I2CIN (0,1,$43,-1,shortMessage,2,shortResponse)' Read the Byte from register
Print "Ram address $74 stored mode is :",shortResponse(0),shortResponse(1)

shortMessage(0)=0x72 'Read from the EEPROM
shortMessage(1)=0x00 'Read the $00 the slave address
I2COUT (0,1,$42,2,shortMessage) ' read the EEPROM address $00 of slave addr $42
I2CIN (0,1,$43,-1,shortMessage,2,shortResponse)
PRINT "The slave address is : $",shortResponse(0),shortResponse(1)

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

> PRESENT=I2COUT (0,1,$42,2,shortMessage)'Write the command and address
> IF PRESENT=0 THEN PRINT "NO I2C device ***"
> I2CIN (0,1,$43,-1,shortMessage,2,shortResponse)' Read the Byte from register

Looking at the spec for the HMC6352, its a slow device. You have slowed the
data rate with the #define

BUT, you also need to wait for HMC part before reading back a data byte.

The spec says 70 uS, as you read nearly after the command, you are probably
waiting less than 5 uS. Remember this is a 60 MHz ARM CPU, its running about
1500 times faster than a BASIC Stamp, and I'm sure much faster than your
RS-232-i2c device.

You can use the WAIT(1) which is overkill at 1 ms

or
starttime = TIMER

while (TIMER - starttime < 70)
loop

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

I agreed your point, But I found the output didn't has any significant changes
after the correction. Here is some information about my current ARMite.

1) #define I2Cspeed100, this is already declared before the #include
2) My ARMite board (2pcs) is ARMite rev 2. (not sure any change of hardware
compare with current supply ARMite)
3) The pins inter connection (ARMite and the I2C device) I am sure should be
fine. The pull up resistors already tried 4.7K and 10K both the same.
4) Both condition of I2C device and ARMite board is Good.
5) Program is refer to my previous mail. 'Wait(1)' already inserted, but no
obvious change of output.

If you have any idea, please let me know and I will try and reply! Further, I
will bought another I2C (real time clock IC) for experiment) see whether is that
only this I2C compass cannot be read.

Brian

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Still not solve the reading problem, any expert who have the experience about
this or encountered similar case. Please comment!

you may give me a big help!

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

I am also have a problem with I2C - using C

The writes fail and read return but with bad data

Tried a lot of code variations without success

Looked at the two pins with a scope and see good high and lows on SDA and
SCL



Bill


//
// Digital Compass HMC6352
// write address 0x42 read address 0x43
// Operational mode ram register address 0x74
// Output ram register address 0x4E
//
//Command Byte; Argument 1 ; Argument 2 ; Response 1 ; Response 2 ;

//ASCII (hex) ; Byte(Binary); Byte(Binary); Byte(Binary); Byte(Binary);
Description

//w (0x77) ; EEPROM Address; Data ; ; ;
Write to EEPROM

//r (0x72) ; EEPROM Address; ;Data ; ;
Read from EEPROM

//G (0x47) ; RAM Address ; Data ; ; ;
Write to RAM Register

//g (0x67) ; RAM Address ; ;Data ; ;
Read from RAM Register

//S (0x53) ; ; ; ; ;
Enter Sleep Mode (Sleep)

//W (0x57) ; ; ; ; ;
Exit Sleep Mode (Wakeup)

//O (0x4F) ; ; ; ; ;
Update Bridge Offsets (S/R Now)

//C (0x43) ; ; ; ; ;
Enter User Calibration Mode

//E (0x45) ; ; ; ; ;
Exit User Calibration Mode

//L (0x4C) ; ; ; ; ;
Save Op Mode to EEPROM

//A (0x41) ; ; ;MSB Data ;LSB Data ;
Get Data. Compensate and Calculate New Heading

//
//
//EE Address (hex) Byte Description Factory Default
//0x00 I2C Slave Address 42(hex)
//0x01 Magnetometer X Offset MSB factory test value
//0x02 Magnetometer X Offset LSB factory test value
//0x03 Magnetometer Y Offset MSB factory test value
//0x04 Magnetometer Y Offset LSB factory test value
//0x05 Time Delay (0 - 255 ms) 01(hex)
//0x06 Number of Summed measurements(1-16) 04(hex)
//0x07 Software Version Number > 01(hex)
//0x08 Operation Mode Byte 50(hex)
//
//

int sda = 5, scl = 6;

//INPUT(sda);
//INPUT(scl); // allow pull up to + 5 volts ??

char message[1];
message[0] = 65; // 'A'
int responseLength = 2;

char response[responseLength];
int s;

I2CSPEED(100);

s = I2COUT(sda, scl, 0x42, 1, 0x57);
if(s == 0)
printf("Wakeup failed\n\n");
WAIT(500);

while(1)
{
s = I2COUT(sda, scl, 0x42, 1, message);
if(s == 0)
printf("Write A failed\n\n");
WAIT(500);
I2CIN(sda, scl, 0x43, -1, -1, -1, -1, -1, responseLength,
response);
WAIT(500);
printf(" MSB %03d", (int)response[0]);
printf(" LSB %03d\n\n", (int)response[1]);
}

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

An add note is that if I remove the +5 pull up voltage - I2COUT never
returns.



Bill

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Hi chris,
thanks your comment, In fact, i already change the code to read a more simple
data, the factory default 'operation mode'. since the data is 0x50, if the read
out is like this, that means I am success. But the reading is not. also, every
command only take 70usec, I already place a 1msec in between and supposed the
delay should be enough.
since the reading not correct, I am not sure this symptom can given any hints.
According to the HMC6352, the first byte should be the High 8 bits reading.
however, in any command the first byte read in usually is 0x00.
so the reading in the following program is
Ram address $74 stored mode is :0 67--> should be 50 XX
The slave address is : 0 11-->should be 42 XX
'XX' means any characters

Now my Kernel is 7.36 and the hardware board is ARMite Rev2. Not sure this
problem related with any hardware config.

here is the code:
#define I2Cspeed100
#include


'Check the compass
'Read the mode and slave address of Compass
DIM shortMessage(10) AS STRING
DIM shortResponse(10) AS STRING

shortMessage(0)=0x67 ' Read Ram address command of the slave device
shortMessage(1)=0x74 ' Address '$74 stored the mode and reading should be $50
PRESENT=I2COUT (0,1,$42,2,shortMessage)'Write the command and address
IF PRESENT=0 THEN PRINT "NO I2C device ***"
wait(1)
I2CIN (0,1,$43,-1,shortMessage,2,shortResponse)' Read the Byte from register
wait(1)
Print "Ram address $74 stored mode is :",shortResponse(0),shortResponse(1)

shortMessage(0)=0x72 'Read from the EEPROM
shortMessage(1)=0x00 'Read the $00 the slave address
I2COUT (0,1,$42,2,shortMessage) ' read the EEPROM address $00 reading shoudl be
addr $42
wait(1)
I2CIN (0,1,$43,-1,shortMessage,2,shortResponse)
wait(1)
PRINT "The slave address is : $",shortResponse(0),shortResponse(1)

**********************************
This is the video link for my scope view and the output signal of SDA, SCL. the
result looking good, but the data read not exactly.


http://www.youtube.com/watch?v=8WD5WXDAt68

Cheers!

Brian

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: i2c devices

Post by YahooArchive »

Hi chris,

1) Will try use back to 3.3V and revert. But the case I use the RS232 -->I2C
module case, I use both 5V supply seems alright.
2) You are right, but read one byte usually got '0x00' read out, therefore,
i read one more byte see any result. Well, if the output is wrong, no matter
one byte or 2 bytes still wrong. will change back take one byte reading only
in the new try!

this couple days will got a 24LC04 and try whether this is working well.
Solve this problem by logic! Hummm.

Brian

Post Reply