News:

Let's find out together what makes a PIC Tick!

Main Menu

How to scan for a MC3422 address

Started by Yves, Today at 09:31 AM

Previous topic - Next topic

Yves

I'm looking for a simple routine that scan the address for for MC3422 a/d converter. I'm using the PIC 18F26k22.
Many thanks in advance.

Cheers

Yves

Yves

Frizie

Ohm sweet Ohm | www.picbasic.nl

Yves

Yves

Frizie

Below is a demo, adjust a few things to suit your situation:

(*Compiler versie V4.0.2.1                    

                               MCP3422:                         +---v---+                                       
                                                          CH1+ >[       ]< CH2-
                                                          CH1- >[       ]< CH2+
                                                       +5V VDD >[       ]< Vss GND
                                        +5V---[4k7]--- I2C SDA<>[       ]< I2C SCL (4k7 niet nodig: I2C_BUS_SCL = ON)
                                                                +-------+                                       



                               PIC18F4xK22:                     +---v---+                                       
                                                 MCLR/Vpp/*/E3 >[       ]<>B7/*/PGD/ IOC3
                                                        AN0/A0<>[       ]<>B6/*/PGC/ IOC2
                                                        AN1/A1<>[       ]<>B5/*/AN13/IOC1/CCP3/T1G/T3CKI(alternat.)
                                           DACOUT/Vref-/AN2/A2<>[       ]<>B4/*/AN11/IOC0/T5G
                                                  Vref+/AN3/A3<>[       ]<>B3/*/AN9 /CCP2(alternat.)
                                T0CKI(TMR0 clk-in)/SRQ/CCP5/A4<>[       ]<>B2/*/AN8 /INT2
                                               SRNQ/SS1/AN4/A5<>[       ]<>B1/*/AN10/INT1
                                        CCP3(alternat.)/AN5/E0<>[       ]<>B0/*/AN12/SRI/INT0
                                                        AN6/E1<>[       ]< +5V
                                                   CCP5/AN7/E2<>[       ]< GND
                                                           +5V >[       ]<>D7/AN27/DT2/RX2  --[4k7]-- +5V
                                                           GND >[       ]<>D6/AN26/CK2/TX2
                                                  CLKI/OSC1/A7<>[       ]<>D5/AN25
                                                  CLKO/OSC2/A6<>[       ]<>D4/AN24/SDO2
                                                  T1CKI/T3G/C0<>[       ]<>C7/AN19/DT1/RX1  --[10k]-- +5V  (misschien nodig)
                                                       CCP2/C1<>[       ]<>C6/AN18/CK1/TX1
                                            T5CKI/CCP1/AN14/C2<>[       ]<>C5/AN17/SDO1
                                             SCK1/SCL1/AN15/C3<>[       ]<>C4/AN16/SDI1/SDA1
                                             SCK2/SCL2/AN20/D0<>[       ]<>D3/AN23/SS2
                                        SDI2/SDA2/CCP4/AN21/D1<>[       ]<>D2/AN22
                                                                +-------+                                       
          * = Interne pull-up mogelijkheid *)
    

DEVICE = 18F45K22
CONFIG_START
  FOSC    = HSHP 'HSMP ' (Medium Power) 4-16MHz) HSHP 'INTIO67           ;High Speed High Power (>16MHz) 'Internal oscillator block
  PLLCFG  = OFF               ;Oscillator used directly
' PLLCFG  = ON                ;Oscillator multiplied by 4
  PRICLKEN = OFF 'ON          ;Primary clock enabled
  FCMEN   = OFF               ;Fail-Safe Clock Monitor disabled
  IESO    = OFF               ;Oscillator Switchover mode disabled
  PWRTEN  = ON                ;Power up timer enabled
  BOREN   = SBORDIS           ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
  BORV    = 190               ;VBOR set to 1.90 V nominal
  WDTEN   = ON                ;Watch dog timer is always enabled. SWDTEN has no effect.
  WDTPS   = 2048              ; 1:1024 is te kort wanneer 'ExterneEEPROMinstellen()' geactiveert wordt (dit gebeurt in geval het programma een lege externe 24C512 EEPROM aantreft)
  CCP2MX  = PORTC1            ;CCP2 input/output is multiplexed with RC1
  PBADEN  = OFF               ;PORTB<5:0> pins are configured as digital I/O on Reset
  CCP3MX  = PORTB5            ;P3A/CCP3 input/output is multiplexed with RB5
  HFOFST  = off 'ON                ;HFINTOSC output and ready status are not delayed by the oscillator stable status
  T3CMX   = PORTB5            ;T3CKI is on RB5
  P2BMX   = PORTD2            ;P2B is on RD2
  MCLRE   = INTMCLR 'EXTMCLR 'INTMCLR           ;RE3 input pin enabled; MCLR disabled                       
  STVREN  = ON                ;Stack full/underflow will cause Reset
  LVP     = OFF               ;Single-Supply ICSP disabled                                                             
  XINST   = OFF               ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
  DEBUG   = OFF               ;Disabled
  CP0     = OFF               ;Block 0 (000800-003FFFh) not code-protected
  CP1     = OFF               ;Block 1 (004000-007FFFh) not code-protected                                                                                                                                                                                         
  CP2     = OFF               ;Block 2 (008000-00BFFFh) not code-protected                                                                                                                                                                                          
  CP3     = OFF               ;Block 3 (00C000-00FFFFh) not code-protected
  CPB     = OFF               ;Boot block (000000-0007FFh) not code-protected
  CPD     = OFF               ;Data EEPROM not code-protected 
  WRT0    = OFF               ;Block 0 (000800-003FFFh) not write-protected
  WRT1    = OFF               ;Block 1 (004000-007FFFh) not write-protected
  WRT2    = OFF               ;Block 2 (008000-00BFFFh) not write-protected
  WRT3    = OFF               ;Block 3 (00C000-00FFFFh) not write-protected
  WRTC    = OFF               ;Configuration registers (300000-3000FFh) not write-protected
  WRTB    = OFF               ;Boot Block (000000-0007FFh) not write-protected
  WRTD    = OFF               ;Data EEPROM not write-protected
  EBTR0   = OFF               ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
  EBTR1   = OFF               ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
  EBTR2   = OFF               ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
  EBTR3   = OFF               ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
  EBTRB   = OFF               ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
CONFIG_END

DECLARE OPTIMISER_LEVEL = 0                             

DECLARE XTAL           = 22   ;Kristal 22.1184 MHz  (40 = 44MHz: Kristal 11.0592 x 4xPLL)
DECLARE ALL_DIGITAL    = TRUE


;============ I C ============
'ECLARE SCL_PIN        = PORTC.3        ;Serial Clock pin van I C componenten met PORTC.3 verbinden
'ECLARE SDA_PIN        = PORTC.4        ;Serial Data  pin met I C componenten met PORTC.4 verbinden
'ECLARE I2C_SLOW_BUS   = ON             ;Langzame snelheid gebruiken voor de I C bus (anders kan het te snel gaan voor het PCF8583 RTC IC)
DECLARE I2C_BUS_SCL    = ON             ;Geen pull-up op de print aanwezig voor de kloklijn (ook niet plaatsen!)
DECLARE HBUS_BITRATE   = 100            ;Langzame snelheid (100kHz) gebruiken voor de I C hardware bus (anders kan het te snel gaan voor het RTC IC)

SYMBOL MCP3422_ADR  = 0b11010000 ;I2C adres (device code van de MCP3422/3/4 is 1101, gevolgd door 3 adres-bits afhankelijk van het MCP3422 bestelde typenr. zie pag.55 datasheet), en als laatst het r/w bit(zie pag.20 datasheet)
SYMBOL MCP3422_SCL  = PORTC.3 ;Q: Serial Clock (for I2C)
SYMBOL MCP3422_SDA  = PORTC.4 ;IQ:Serial Data (for I2C)

DIM ADC_Value       AS WORD   ;Bevat een ontvangen waarde van de ADC - For 12, 14 and 16-bit resolution
'IM ADC_Value       AS LONG   ;Bevat een ontvangen waarde van de ADC - For 18-bits resolution
DIM MCP3422_CFG     AS BYTE   ;MCP3422 configuration byte

DELAYMS 250
CLEAR
CLS                           ;CLear Screen (display)


DO
  CLRWDT                      ;CLeaR Watch Dog Timer

 'I2COUT  MCP3422_SDA, MCP3422_SCL, MCP3422_ADR, [0b10000000] ;For CH1, one shot, 12-bit, gain x1 (xnnxxxxx nn=channel. xxxnxxxx n=conversion mode. xxxxnnxx nn=resolution. xxxxxxnn nn=gain factor)
 'I2COUT  MCP3422_SDA, MCP3422_SCL, MCP3422_ADR, [0b10000100] ;For CH1, one shot, 14-bit, gain x1 (xnnxxxxx nn=channel. xxxnxxxx n=conversion mode. xxxxnnxx nn=resolution. xxxxxxnn nn=gain factor)
  I2COUT  MCP3422_SDA, MCP3422_SCL, MCP3422_ADR, [0b10001000] ;For CH1, one shot, 16-bit, gain x1 (xnnxxxxx nn=channel. xxxnxxxx n=conversion mode. xxxxnnxx nn=resolution. xxxxxxnn nn=gain factor)
 'I2COUT  MCP3422_SDA, MCP3422_SCL, MCP3422_ADR, [0b10001100] ;For CH1, one shot, 18-bit, gain x1 (xnnxxxxx nn=channel. xxxnxxxx n=conversion mode. xxxxnnxx nn=resolution. xxxxxxnn nn=gain factor)
 
  REPEAT             
    I2CIN  MCP3422_SDA, MCP3422_SCL, MCP3422_ADR, [ADC_Value, MCP3422_CFG]  ;Note: Declare 'ADC_Value' as LONG with 18-bit resolution
  UNTIL MCP3422_CFG.7 = 0

  IF ADC_Value >  32767 THEN ADC_Value = 0  ;Option: Extra safety when input is used as single ended input - For 12, 14 and 16-bit resolution
 'IF ADC_Value > 131071 THEN ADC_Value = 0  ;Option: Extra safety when input is used as single ended input - For 18 bit resolution

  PRINT AT 1, 1, DEC5 ADC_Value             ;For 12, 14 and 16-bit resolution (= WORD)
 'PRINT AT 1, 1, DEC8 ADC_Value             ;For 18 bit resolution            (= LONG)
  PRINT AT 2, 1, BIN8 MCP3422_CFG
 
  DELAYMS 250
LOOP
Ohm sweet Ohm | www.picbasic.nl

Yves

Sorry but I do have a working driver for the MCP3422

My inquiry was if anyone has a simple routine that scan the MCP3422 and display its address.
Yves

RGV250

#5
Hi,
If you look at page 54 of the datasheet you can see the address from the marking.
Look at page 38 for more information.

Bob

Pepe

Does this work?

flosigud

I use this to find 11c addresses:
    Dim bAddress As Byte
    Dim bAddresses As Byte
    Dim bReply

    Dim sI2CScanner[13]      As Code = " I2C Scanner ",0   
    Dim sReply[25]           As Code = " Reply at address ",0
    Dim sNumberOfReplies[11] As Code = " Replies = ",0
    DelayMS 1000
    Output PORTB
    HRSOut CStr sI2CScanner,13,13

    bAddresses = 0
    For bAddress = 1 To 255
        bReply = HBusIn bAddress
        If bReply < 255 Then
            HRSOut CStr sReply, Hex bAddress,13
            Inc bAddresses
        EndIf
    Next
    HRSOut CStr sNumberOfReplies , Dec bAddresses,13

    Do
        Toggle PORTB.1.
    Loop                    

You can substitude

RGV250

#8
Hi,
Seems like a lot of work when the datasheet details it.
Now I am back home here is the information.

The device code is 1101
Address 1.JPG

and the address bits are dependant on the 2 characters after the part number. The Default is A0 (000)
Address 2.JPG

Example.
Address 3.JPG

So it is a good guess the address is 1101000

Regards,
Bob