Jump to content
leetrieu

[Help] How to make 2 devices working together using I2C??

Recommended Posts

I suggest you start a new topic for your problems.

 

Hello everybody !!

I have a problem with I2C. I don't known how to make 2 devices working together using the same I2C bus. 
this is my code to interface with RTC(BQ32000)
//*************************
void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  conf_io();
  conf_lcd(0);
  conf_clock();
  i2c_init(0x68); //initialization I2C BQ32000
  
  i2c_write(0x00,8,datawrite);   //Set Time for BQ32000
  
  while(1)
  {
     read_bq32000();//readtime from BQ32000
     display_time(); //Show Time on LCD
     display_date();//Show Date on LCD 
  }
}

and code interface with EEPROM 24C04

#include "msp430g2553.h"
#include "I2C.c"
unsigned char datawrite[4]={0x4f,0x48,0xab,0x13};
unsigned char dataread[4];
unsigned char tmp1,tmp2,tmp3,tmp4;
void main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  P1DIR |= 0x0f;
  P1SEL |= BIT6 + BIT7;     // Assign I2C pins to USCI_B0 
  P1SEL2|= BIT6 + BIT7;
  i2c_init(0x50);
  i2c_write(0x01,5,datawrite);//write 3 value from datawrite to 0x01,0x02 and 0x03 registers
  __delay_cycles(50000);
  i2c_read(0x01,2,dataread);//First read
  while(1)
  { 
    i2c_read(0x01,5,dataread);//read 3 regiters: 0x01,0x02 and 0x03
    tmp1=dataread[0]; //0x01 -> tmp1
    tmp2=dataread[1]; //0x02 -> tmp2 
    tmp3=dataread[2]; //0x03 -> tmp3
    tmp4=dataread[3]; // read 0x04
    _NOP(); 
  }
}

I only can interface with RTC or 24C04, but I can't make it working together?? Please guide me how to do it?
Thanks all so much !!

Share this post


Link to post
Share on other sites

All you need is to change I2C device ID before you talk to it.

i2c_init(0x50);
do stuff with EEPROM
i2c_init(0x68);
do stuff with RTC

Or maybe there is function in your I2C.c just for that instead of full init.

Share this post


Link to post
Share on other sites

All you need is to change I2C device ID before you talk to it.

i2c_init(0x50);
do stuff with EEPROM
i2c_init(0x68);
do stuff with RTC

Or maybe there is function in your I2C.c just for that instead of full init.

Thanks you so much ! Maybe I understands your idea !!

Share this post


Link to post
Share on other sites

All you need is to change I2C device ID before you talk to it.

i2c_init(0x50);
do stuff with EEPROM
i2c_init(0x68);
do stuff with RTC

Or maybe there is function in your I2C.c just for that instead of full init.

There is no smaller function in their i2c code, but the slave address is simply set with

UCB0I2CSA = sla_add;

Where sla_add is a 7 bit i2c address. 

Share this post


Link to post
Share on other sites

That is discouraged, since you're mixing the i2c abstraction from Energia with the bare metal interface. This makes you both dependent on the Energia framework and restricts portability because you bypass the library.

Share this post


Link to post
Share on other sites

That is discouraged, since you're mixing the i2c abstraction from Energia with the bare metal interface. This makes you both dependent on the Energia framework and restricts portability because you bypass the library.

Ive seen their code from what they shared in the last topic. It's not Energia. It's a foreign site's simple USCI based i2c code.

Share this post


Link to post
Share on other sites

All you need is to change I2C device ID before you talk to it.

i2c_init(0x50);
do stuff with EEPROM
i2c_init(0x68);
do stuff with RTC

Or maybe there is function in your I2C.c just for that instead of full init.

 

 

There is no smaller function in their i2c code, but the slave address is simply set with

UCB0I2CSA = sla_add;

Where sla_add is a 7 bit i2c address. 

 

 

That is discouraged, since you're mixing the i2c abstraction from Energia with the bare metal interface. This makes you both dependent on the Energia framework and restricts portability because you bypass the library.

HI all !!

Please guide me, how to makes 2 Msp430g2553 working together ????

I don't understand when i using i2C to interface, what is slave address?? and what is master address?? 

Thanks you so much !!

Share this post


Link to post
Share on other sites

HI all !!

Please guide me, how to makes 2 Msp430g2553 working together ????

I don't understand when i using i2C to interface, what is slave address?? and what is master address?? 

Thanks you so much !!

If you are using two msp430s as i2c devices, figuring one as master one as slave, the slave's address is defined by you. See TI;s slaa383 pdf, and zip with code. http://www.ti.com/general/docs/lit/getliterature.tsp?literatureNumber=slaa383&fileType=pdf

Share this post


Link to post
Share on other sites

Master is the one in charge, and asks slave to do something or asks slave to send a value back to the master.

I2C can have multiple masters, and sometimes a 'master' might be a 'slave' and the 'slave' might be a 'master'.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...