Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

interfacing ADS1115

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
bjornj

Bascom Member



Joined: 30 Apr 2009
Posts: 14

sweden.gif
PostPosted: Mon Feb 08, 2016 11:56 am    Post subject: interfacing ADS1115 Reply with quote

Hello

I have tried to interface the 16 bit AD converter ADS1115 with very little succes.
I only get ones, FF FF, when reading the chip.
I have used data from the quick start guide in texas instruments datasheet.
I recently put in some delays and start/stop conditions, but that didn't help either.
Perhaps somebody with experience in this can figure out what i'm doing wrong.

/Björn Johansson

(BASCOM-AVR version : 2.0.7.7 , Latest : 2.0.7.8 )
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2111

netherlands.gif
PostPosted: Mon Feb 08, 2016 1:03 pm    Post subject: Reply with quote

Hi,

Try the 12cscan.bas example from your Bascom directory to test if the hardware is working fine and if the i2c address matching your settings.

Code:

Print "Scan start"
For B = 0 To 254 Step 2                                     'for all odd addresses
  I2cstart                                                  'send start
  I2cwbyte B                                                'send address
  If Err = 0 Then                                           'we got an ack
     Print "Slave at : " ; B ; " hex : " ; Hex(b) ; " bin : " ; Bin(b)
  End If
  I2cstop                                                   'free bus
Next
Print "End Scan"
End
 

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 690

poland.gif
PostPosted: Mon Feb 08, 2016 3:47 pm    Post subject: Reply with quote

Is the 90s8515 really chip You want to run this code or maybe You have Mega8515 that need "m8515.dat"?
Why don`t You use some chip with TWI. Even on Atmega8 You can use $lib "I2c_twi.lib" and then use Portc.4 and Portc.5
With really old chip`s where I2C was not implemented because it is a Philips patent or when I2C pins are occuped then software I2C make sens.
You should consider using dedicated I2C pin of some newer chip.
Back to top
View user's profile Visit poster's website
bjornj

Bascom Member



Joined: 30 Apr 2009
Posts: 14

sweden.gif
PostPosted: Mon Feb 08, 2016 4:37 pm    Post subject: Reply with quote

Thanks.
I tried the scan program and the result was 144 or Hex90
just like i should.
perhaps I could modify the program and see if I get an ack
when reading from the ADS.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 932
Location: France

france.gif
PostPosted: Mon Feb 08, 2016 5:46 pm    Post subject: Reply with quote

you need 2R 4.7k pull up on the I2C lines
did you put them ?
jp
Back to top
View user's profile Visit poster's website
bjornj

Bascom Member



Joined: 30 Apr 2009
Posts: 14

sweden.gif
PostPosted: Mon Feb 08, 2016 7:37 pm    Post subject: Reply with quote

Yes, I have a ready made little pcb with the ADS soldered on it.
It has all the pullups and some filtering capacitors.
Also the oscilloscope shows fine pulses 2x8 at the scl line
and 2x high at ada line when reading msb and lsb.
I also tried to capture the ack when reading the chip
with the scan program but it never came.
result 255.
perhaps this is where the problem sits, or did I make a poor
modification of the program.

part of the modified scan program.

I2cstart

I2cwbyte 144
I2cwbyte 0

For B = 1 To 254 Step 2

I2cwbyte B
I2crbyte lbyte, ack
If Err = 0 Then
cls 'we got an ack
lcd "Slave at"
lowerline
lcd B," ";
End If
I2cstop 'free bus
Next
cls
lcd "end ";B
End
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Mon Feb 08, 2016 9:39 pm    Post subject: Reply with quote

Hi,

did you see datasheet

Write to Config register:
First byte: 0b10010000 (first 7-bit I2C address followed by a low read/write bit) (H90/H91 OK)

Second byte: 0b00000001 (points to Config register)
Third byte: 0b10000100 (MSB of the Config register to be written)
Fourth byte: 0b10000011 (LSB of the Config register to be written)

Write to Pointer register:
First byte: 0b10010000 (first 7-bit I2C address followed by a low read/write bit) (H90/H91 OK)
Second byte: 0b00000000 (points to Conversion register)

Read Conversion register:
First byte: 0b10010001 (first 7-bit I2C address followed by a high read/write bit)
Second byte: the ADS1113/4/5 response with the MSB of the Conversion register
Third byte: the ADS1113/4/5 response with the LSB of the Conversion register

Try code:
Code:
Config Portd.0 = Output

Dim High_low As Integer
Dim Hibyte As Byte At High_low Overlay
Dim Lobyte As Byte At High_low + 1 Overlay
Dim W_addr As Byte
Dim R_addr As Byte

'addr_pin grounded

'address for  write to ads1115
W_addr = &H90

'address for  read from ads1115
R_addr = &H91


' Configure pins to to use for the I²C bus

Config Scl = Portc.0                                        'Is serial clock SCL
Config Sda = Portc.2                                        'Is serial data SDA
I2cinit


'Const Config_high = &B11000000                             '6144
'Const Config_high = &B11000010                             '4096
Const Config_high = &B11000100                              '2048
'Const Config_high = &B11000110                             '1024

Const Config_low = &B00000000


I2cstart
I2cwbyte W_addr
I2cwbyte &B00000001
I2cwbyte Config_high
I2cwbyte Config_low
I2cstop

Waitms 25
'******************************************
Do

   Gosub Read_ad
   Cls
   Lcd High_low
   Lowerline
 
Lcd Hex(Hibyte) ;" ";Hex(Lobyte)
   Waitms 600
Loop
End

Read_ad:
   I2cstart                                                 ' Generate start code
   I2cwbyte W_addr                                          ' send address
   I2cwbyte 0
   I2cstart                                                 ' start condition
   I2cwbyte R_addr                                          ' slave address
   I2crbyte Lobyte , Ack
   I2crbyte Hibyte , Nack
   I2cstop
Return

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
bjornj

Bascom Member



Joined: 30 Apr 2009
Posts: 14

sweden.gif
PostPosted: Tue Feb 09, 2016 11:02 am    Post subject: Reply with quote

Thank you very much Kim.
Your example worked very well.
I compared it with my code and as far as I can see
the differens is that every read must be precded by a
I2Cstart and followed by a I2Cstop.
with that also my code worked.
Thanks again for all help
Björn
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Feb 09, 2016 8:48 pm    Post subject: Reply with quote

Yes its the "repeated START" and the "Ack /Nack" that works for the ADS1115

datasheet pages 17/18

Quote:
WRITING/READING THE REGISTERS modes.
To access a specific register from the ADS1115,
the master must first write an appropriate value to the Pointer register.
The Pointer register is written directly after the slave address byte, low R/W bit,
and a successful slave acknowledgment.
After the Pointer register is written, the slave acknowledges and the master issues a STOP or a repeated START condition.


Code:
   I2cstart                                                
   I2cwbyte W_addr                                          
   I2cwbyte 0
   I2cstart  '****** STOP or a repeated START                                            
   I2cwbyte R_addr                                          
   I2crbyte Lobyte , Ack '*****
   I2crbyte Hibyte , Nack '*****
   I2cstop

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum