Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:11 07 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : I2C READ

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1982
Posted: 05:42pm 06 Oct 2014
Copy link to clipboard 
Print this post

I have a program that reads from a BMP085 sensor. I recently upgraded MMBASIC in my Maximite to V4.5 and so had to change the I2C commands.
The code I was using
TEMP: ' Get temperature from BMP085
I2CSEND BMP085_ADDRESS,0,2,&HF4,&H2E
Pause 5
I2CRCV BMP085_ADDRESS,0,2,buffert(0),1,&HF6
temp_uc=(buffert(0)*256)+buffert(1)
Return

PRES: ' Get presure
I2CSEND BMP085_ADDRESS,0,2,&HF4,&HF4
Pause 26
I2CRCV BMP085_ADDRESS,0,3,buffert(0),1,&HF6
pres_uc=Int(((buffert(0)*65536)+(buffert(1)*256)+buffert(2)) /32)
Return

I altered the I2CSEND TO I2C WRITE
and I2CRCV to I2C READ
So now the line reads
I2C READ BMP085_ADDRESS,0,2,buffert(0),1,&HF6
but gives me a syntax error, the same happens with the other I2C READ.
Can anyone help.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 05:58pm 06 Oct 2014
Copy link to clipboard 
Print this post

Paul
The syntax is
I2C READ addr, option, rcvlen, rcvbuf

Maybe it is objecting to the extra two characters on the end ,1,&HF6

Bob
Edited by BobD 2014-10-08
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 07:09pm 06 Oct 2014
Copy link to clipboard 
Print this post

Yes, as Bob says Paul, just the four parameters now. I'm using the following line from JMan's DS1307 routines OK for V4.5 on the MicroMite but I think it's the same for the Maximite now.

I2C READ i2caddr,0,8, RTCbuff(0) 'Normal ctrl, 8 bytes, rec'v var

Greg
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1982
Posted: 07:36pm 06 Oct 2014
Copy link to clipboard 
Print this post

Thanks, that worked.
I don't understand I2C all that well, will have to study further.
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 11:33am 07 Oct 2014
Copy link to clipboard 
Print this post

Hang in there, Paul. If not for the encouragement of members here such as MOBI(anyone heard from him lately, BTW?), I too would have given up on I2C. Now that I have got the hang of talking to it, I would not think twice about using it, and once you ARE familiar with it, it opens up a whole plethora of extra chips you can interface to the uM.

EDIT: Whatever happened with your VGA-composite problem? Did you get that fixed?Edited by Grogster 2014-10-08
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1982
Posted: 06:53pm 07 Oct 2014
Copy link to clipboard 
Print this post

No I put the colour monitor on the back burner, using it in mono at the moment. I bought another monitor will try it with that when I get some time. Gee it's busy when you're retired.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1982
Posted: 11:21pm 08 Oct 2014
Copy link to clipboard 
Print this post

Still having problems reading I2C values
I have now tried with a HH10D humidity sensor that worked OK before.
The old code I used was
100 Dim hcal(4)
110 I2CEN 100,400
120 I2CRCV &h51,0,4,hcal(0),1,10
130 I2CDIS
140 If MM.I2C <> 0 Then
150 Print "Error during EEPROM read - error code: ";MM.I2C
160 End
170 EndIf
180 hsens = hcal(0) * 256 + hcal(1):Print "Sensitivity: ";hsens
190 hoffset = hcal(2) * 256 + hcal(3):Print "Offset: ";hoffset
200 SetPin 11,3
210 Do
220 Pause 5000
230 humidity = (hoffset - Pin(11)) * hsens / 4096
240 Print "Humidity: ";humidity;"%"
250 Loop


I have changed to
100 Dim hcal(4)
110 I2C OPEN 100,400
120 I2C READ &h51,0,4,hcal(0)
130 I2C CLOSE
140 If MM.I2C <> 0 Then
150 Print "Error during EEPROM read - error code: ";MM.I2C
160 End
170 EndIf
180 hsens = hcal(0) * 256 + hcal(1):Print "Sensitivity: ";hsens
190 hoffset = hcal(2) * 256 + hcal(3):Print "Offset: ";hoffset
200 SetPin 15,3
210 Do
220 Pause 5000
230 humidity = (hoffset - Pin(15)) * hsens / 4096
240 Print "Humidity: ";humidity;"%"
250 Loop

I know what the calibration values should be, but this code is not giving me those values.
In the original code the read line is
120 I2CRCV &h51,0,4,hcal(0),1,10
can someone tell me what the 1,10 at the end is, the new code won't let me use it.
I am trying to get 2 values from the eprom, "sensitivity" and "offset"
Paul.

"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:47pm 08 Oct 2014
Copy link to clipboard 
Print this post

  palcal said  
In the original code the read line is
120 I2CRCV &h51,0,4,hcal(0),1,10
can someone tell me what the 1,10 at the end is, the new code won't let me use it.
I am trying to get 2 values from the eprom, "sensitivity" and "offset"
Paul.



That was to write 1 byte with the value of 10 before the read

So the new code should look like this
I2C Write &H51, 0, 1, 10
I2C Read &H51, 0, 4, hcal(0)

Regards
Jman
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1982
Posted: 11:18am 09 Oct 2014
Copy link to clipboard 
Print this post

Thanks Jman I will try that. It makes sense, 10 is the eprom address of the first value I am trying to read.
Paul.

It worked OK. I think I'm starting to get my head around this I2C stuff now.
Thanks all,
Paul.

Just one more thing that is puzzling me, the original code was written by Seco61 back in Jan 2012 in response to a post from me. Nowhere in the datasheet for the HH10D sensor is the I2C address of &h51, so where would this address have come from.

Edit.
The datasheet says the eeprom physical address is fixed at 01 so this is probably a mistake and should read 81.Edited by palcal 2014-10-10
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025