Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing mcp3422 with microcontroller

Status
Not open for further replies.

Arya Kumar

Member level 4
Joined
Aug 25, 2013
Messages
73
Helped
11
Reputation
22
Reaction score
11
Trophy points
8
Activity points
713
Hello all,
i am doing this project to learn about I2c protocol. i have earlier interfaced eeprom with controller and that was easy .
I have problem inerfacing it to mcp3422 Analogue module.

I am using MIKROC IDE , controller is PIC16f877a and coding in c.
Objective - to read anlogue value with default configurations

Code:
void main(){
  PORTB = 0;
  TRISB = 0;                 // Configure PORTB as output
    while(1)
  {
  
  I2C1_Init(100000);         // initialize I2C communication    \



  I2C1_Start();              // issue I2C start signal

  I2C1_Wr(0xd0);             // send byte via I2C  (device address + W) // device identifer is 1101 and MCP3422 has no external Address line + write (0)
                                         // 1101 000 0 = 0xD0


  //I2C1_Wr(0x55);                // send byte (data address)     // no idea what to put here.. i am usig same format as i did for eeprom
                                         // i see no regiser address to read or write


  I2C1_Repeated_Start();     // issue I2C signal repeated start

  I2C1_Wr(0xd1);             // send byte (device address + R) write address +1

  PORTB = I2C1_Rd(1u);       // Read the data // no idea how to read more than 8 bits.  ???
  PORTB = I2C1_Rd(1u);      // have to read 3 bytes of data from module
  PORTB = I2C1_Rd(1u);


  I2C1_Stop();               // issue I2C stop signal
  delay_ms(1);
  }
}

I have attached code and proteus simulations :-|

Please help as u all always do. Till then i will try to explore problem by myself,
Thanks and Regards,
Arya Kumar:thumbsup:
 

Attachments

  • i2c_perpherals.zip
    89.7 KB · Views: 50

i am unable to read ADC value from I2C1_Rd(1u);
it always returns 0x00;
 

hello,

You need to do some initialisation for your ADC MCP3222 .. befor getting a result


i used this for a MCP3224 and PIC18F258 with MikroC ..maybe it can help you

Code:
#define MCP3424_Adr 0xD0
unsigned long M=0 ;          // mesure ADC 18 bits
unsigned short MCPCfg;
unsigned short MCP_CH;
unsigned short MCP_Resol;
unsigned short MCP_Gain;


//--------- ADC 18 bits --------------------
unsigned long read_adc_value()
{  unsigned short erreur;
  unsigned short EtatCf;
  unsigned long value=0L;
  unsigned char *pV;
  pV=&value;
     erreur=0;
  // RDY=1 init One Shoot conversion
  // MCP_CH * 32  (bit 6-5)  numero de chanel  0 à 3
  // MCP_Resol    (Bits 3-2) 0x11  0C-> 18bits 3.75SPS
  // MCP_Gain=0   bits 1-0  0x00
  MCPCfg= 128 + MCP_CH + MCP_Resol + MCP_Gain;
  Soft_I2C_Start();
  erreur=Soft_I2C_Write(MCP3424_Adr);    // 0xD0
  erreur=Soft_I2C_Write(MCPCfg);
     //Soft_I2C_Write(0x88);   // 0x8C=140 pour 18 bits    0x88= 136 pour 16 bits
  Soft_I2C_Stop();
  Soft_I2C_Start();
  erreur=Soft_I2C_Write(0xD1);     // LECTURE adresse fixe + 000 + R=1
  *(pV+3)=0;
  *(pV+2)= Soft_I2C_Read(1); // lit et renvoi  ACK
  *(pV+1)= Soft_I2C_Read(1);  // lit et renvoi ACK
  *(pV+0)= Soft_I2C_Read(1); // lit et renvoi  ACK
  EtatCf=  Soft_I2C_Read(0); // lit et renvoi NACK
  Soft_I2C_Stop();
  return value;
 }

MCP register initilized in the main program
the result is a long inter 32 bits ...
 

ok i have added default configuration to my code.
Still no fruits. If u can just send ur full project with simulation. That will make my day.
Code:
void main(){
  PORTB = 0;
  TRISB = 0;                 // Configure PORTB as output
    while(1)
  {
  
  I2C1_Init(100000);         // initialize I2C communication    \


  I2C1_Start();              // issue I2C start signal
  I2C1_Wr(0xd0);             // send byte via I2C  (device address + W)
  
[B][COLOR="#FF0000"]  I2C1_Wr(0x90);                // writing default configuration   1001 0000[/COLOR][/B]
  
  I2C1_Repeated_Start();     // issue I2C signal repeated start
  I2C1_Wr(0xd1);             // send byte (device address + R)
  
  PORTB = I2C1_Rd(1u);       // Read the data      /// by default we are in 12 bit mode
  delay_ms(100);
  PORTB = I2C1_Rd(1u);
  delay_ms(100);
  
  I2C1_Stop();               // issue I2C stop signal
  delay_ms(1);
  }
}

Capture.PNG
 

hello,


What voltage level do you apply on CH1 Analog MCP entry ?
+VCC ??
put a value corresponding to half of the scale measurment to do tests ..

I don't have PROTEUS neither simulator, i only work in real world .. even with breadboard
i think it is more easy to debug .

some explanation (sorry ,in French) on MCP3224 and other ADC via **broken link removed** ..
 

I know it must not be 5 volt. But as of now i just want any value other than zero on the I2c bus. I have changed it to other levels still it return zero.
I dont know but above link is banned in India
 

Hi,

in your I2C debug you don´t show 3rd and 4th byte.
4th byte is the config byte and may give additional information.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top