Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:49 20 Nov 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 : PicoMite I2C problems: Invalid configuration, Manual confusion

Author Message
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 719
Posted: 02:15pm 13 Feb 2022
Copy link to clipboard 
Print this post

Hello again,

since I am trying to interface my ADS1115 (external 16bit ADC module) I am getting an error with the I2C configuration.

I tried different configurations, some result in the error "Invalid configuration" seems to give no proper voltage value at all.

Here is the code I used (I modified it from somewhere in the forum, since I am new to basic I hope this sould generally work?)


'Testprogram for ADS1115 module
'I2C used: SDA=20, SCL=21

Option explicit
SETPIN 20,21, I2C

I2C open 100,5000
Dim float adc0,getvolts,wait=100

DO
Print "Volts A0  is "; Str$(adc0,0,3)
LOOP

Sub ADC ' ADC reading
Local cfreg,cnv,cfhi,cflo

cfreg = &h01: cnv =&h00   ' rate 128 sps no comp operations

cfhi = &hC3 : cflo= &h81 ' reading single Ain0,FS= +/- 4.096 , 128 sps
I2C write &H48,0,3,cfreg,cfhi,cflo 'adr 48 point to config reg
I2C write &h48,0,1,cnv ' adr 48 point to conversion reg
getadc
adc0 = (getvolts+adc0)/2

End Sub

Sub  getadc
Local adcv
Local integer adcrd(2) 'to receive 2 bytes

Pause wait/2
I2C read &h48,0,2,adcrd()

adcv= (adcrd(0)<<8) Or adcrd(1)
If adcv > &H7fff Then adcv = adcv - &HFFFF
getvolts = adcv *(4.096/32768.0)

End Sub


With this I2C configuration I get: "Invalid configuration"
I also tried:


SETPIN 26,27, I2C


With this the code does execute, but the reading is wrong (always 0.0000)

Then I tried:


SETPIN 26,27, I2C2


I got: "Invalid configuration"

The manual seems to be wrong, because on page 116 it says: "I2C2: (...) SDA:26,SCL:27" and on I2C there is SCL: 27 too. So available via both ports? I am confused as a newbe... Maybe one could help me out?

-Daniel
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 02:20pm 13 Feb 2022
Copy link to clipboard 
Print this post

You are confusing pin numbers and GP numbers. You are specifying pin numbers but mean GP numbers

eg.
SETPIN GP26,GP27,I2C2 = SETPIN 31,32,I2C2
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 719
Posted: 02:32pm 13 Feb 2022
Copy link to clipboard 
Print this post

With

SETPIN GP26,GP27,I2C2  / I2C2 = SETPIN 31,32,I2C2

I get: "I2C1 in use for SYSTEM I2C"

This is not true, because "OPTION LIST" gives me:

OPTION SYSTEM I2C GP10,GP11
(his is my RTC)

In the Manual on page 116, PIN 27 is allocated to I2C1 AND I2C2 - is this correct?

But you are right I confused the Pins nevertheless! Thank you for this hint.
So I changed to GP20 and GP21 (works without error) but my program doesn't give the right values, always "0.0000" ...

Does anyone have experience with interfacing the ADS1115 or a working testprogram?

-Daniel
Edited 2022-02-14 00:40 by Amnesie
 
wolfme
Newbie

Joined: 26/10/2021
Location: Germany
Posts: 31
Posted: 02:37pm 13 Feb 2022
Copy link to clipboard 
Print this post

DO
Print "Volts A0  is "; Str$(adc0,0,3)
LOOP


There is no sub call for the ADC reading...
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 719
Posted: 02:49pm 13 Feb 2022
Copy link to clipboard 
Print this post

  wolfme said  


There is no sub call for the ADC reading...


Thank you so much! Problem solved! :)

But I think in the manual is a fault anyway, because it seems that GP27 is allocated to both I2C ports... I2C1 & I2C2 or is this correct? With none of this configs it will work and give always an error. So I switched to GP20 / GP21, this works fine!

Just for reference and the search function, this code works well (even if it might be far from perfect):



'Testprogram for ADS1115 module
'I2C used: SDA=GP20, SCL=GP21

Option explicit

SetPin  GP20,GP21, I2C
I2C open 100,5000
Dim float adc0,getvolts,wait=100

SetTick 1*wait,ADC,4

DO
Print "Volts A0  is "; Str$(adc0,0,3)

LOOP


Sub ADC ' ADC reading
Local cfreg,cnv,cfhi,cflo

cfreg = &h01: cnv =&h00   ' rate 128 sps no comp operations

cfhi = &hC3 : cflo= &h81 ' reading single Ain0,FS= +/- 4.096 , 128 sps
I2C write &H48,0,3,cfreg,cfhi,cflo 'adr 48 point to config reg
I2C write &h48,0,1,cnv ' adr 48 point to conversion reg
getadc
adc0 = (getvolts+adc0)/2

End Sub


Sub  getadc
Local adcv
Local integer adcrd(2) 'to receive 2 bytes

Pause wait/2
I2C read &h48,0,2,adcrd()

adcv= (adcrd(0)<<8) Or adcrd(1)
If adcv > &H7fff Then adcv = adcv - &HFFFF
getvolts = adcv *(4.096/32768.0)

End Sub



-Daniel
Edited 2022-02-14 01:00 by Amnesie
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 03:04pm 13 Feb 2022
Copy link to clipboard 
Print this post

  Quote  But I think in the manual is a fault anyway, because it seems that GP27 is allocated to both I2C ports


Well spotted. I'll ask Geoff to fix it
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 719
Posted: 03:10pm 13 Feb 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote  But I think in the manual is a fault anyway, because it seems that GP27 is allocated to both I2C ports


Well spotted. I'll ask Geoff to fix it



But what is the reason for the ERROR "I2C1 in use for SYSTEM I2C"
when I try your suggested configuration:


SETPIN GP26,GP27,I2C2


Because it isn't used for my SYSTEM I2C.. I used:

OPTION LIST



OPTION SYSTEM I2C GP10,GP11


-Daniel
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 03:21pm 13 Feb 2022
Copy link to clipboard 
Print this post

  Quote  But what is the reason for the ERROR "I2C1 in use for SYSTEM I2C"


Should really say ERROR "I2C2 in use for SYSTEM I2C"

Because each I2C controller can only be used on one set of pins. If you are using them for SYSTEM I2C you can't use the same I2C controller (RP2040 I2C1 controller) for other things.

However, you can connect other devices to the system I2C in which case don't use SETPIN and don't open the I2C as it is already open
Edited 2022-02-14 01:32 by matherp
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 719
Posted: 03:44pm 13 Feb 2022
Copy link to clipboard 
Print this post

Ahhh I understand, thank you for this explanation!

Greetings
-Daniel
 
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