How do I setup I2C on MOD5270/Mod-Dev-70

Discussion to talk about software related topics only.
arbotic
Posts: 7
Joined: Wed May 19, 2010 12:39 pm

How do I setup I2C on MOD5270/Mod-Dev-70

Post by arbotic »

I’m new to this NetBurner stuff. I’m trying to connect the 5270 to a 3 axis accelerometer. I verified that the accelerometer is working by connecting to a Parallax Propeller.

My NetBurner Connections
J2-39 (SDA)
J2-42 (SCL)
J2-50 (VCC)
J2-49 (GND)

The Propeller requires two 10k pullups on the SCL and SDA lines. I’m assuming that’s not the case for the MOD5270/Mod-Dev-70 but I tried it both ways.

Software
\examples\mod5270\I2C2Serial

I modified main.cpp.; commented #include "i2cmulti.h" and uncommented #include "i2cmaster.h".

Code: Select all

//#include "i2cmulti.h"             //Used for Multi-Master I2C
#include "i2cmaster.h"          //Used for Master Only I2C
Next I ran the program. Through MTTTY I entered

Master Mode send a string to a specified address = 16
TX = 5

The first time through I get error 9. The next time I get error 4.

I hooked up my scope to the data and clock lines. I’m not seeing anything. The code comments state...

Code: Select all

Please note that jumper JP12 should be put on the developement board to enable
the I2C pull up resistors.  Jumper pins 1 and 2 for a 5V I2C bus and jumper
pins 2 and 3 for a 3.3V I2C bus.
I’m not sure where jumper JP12 is located. I have a jumper JP4 though. Any insight is greatly appreciated.
arbotic
Posts: 7
Joined: Wed May 19, 2010 12:39 pm

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by arbotic »

I spent a good portion of my weekend trying to get this guy working. I did a lot of reading on I2C and I pretty much went through all the source code for i2cserial and i2cmaster. I learned a lot. Wife's mad but what can ya do...

All I want to do is successfully initialize the 3 axis accelerometer. To do that, I need to write the value 5 to the register 0x16 of slave device 0x1D.

Address: 0x1D
Register: 0x16
Value: 0x05

I modified i2cserial.cpp so that I could enter these values programmatically. Nothing fancy, just a new menu item so I could execute my debugging code with iprintf etc.

Address = 0x1D
Buffer[0] = 0x16
Buffer[1] = 0x05

I have 10k pull-ups on SDA and SCK. Again, I can wire up the accelerometer (http://gadgetgangster.com/find-a-projec ... ectnum=322) to a Parallax Propeller no problem.

The only other thing that I did that might be a problem is I soldered pin headers to the Mod-Dev-70. The joints look good. I see +3.3 V on J2-39 (SDA) and J2-42 (SCL) after initializing i2cserial.

If anyone has a known good schematic and sample source code for ANY I2C device, that would be greatly appreciated. I need some direction.
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by seulater »

Without a scope its going to be difficult to catch the problem.
All i can offer you at the moment is some of my code that maybe will help you see if there is anything you are doing differently, I am also using the MOD5270 with I2C on the same pins.

#include "i2cmaster.h"
#define PCA9554_MANUF_CODE 0x40 // manufacturer address code
#define PCA9554_ERROR 1
#define PCA9554_OK 0

extern BYTE i2cStatus;


After things get going in main i call: I2CInit(0x16);

I have a PCA9554 part connected to my board. So then i call this:

if( Init_PCA9554(0x00,0xff) == PCA9554_ERROR )
{
//error
}


****************
Maybe there is something here that can shed some light for you.



Code: Select all

//*********************************************************************
//************************  INITIALIZE PCA9554  ***********************
//*********************************************************************
SHORT Init_PCA9554(BYTE address, BYTE dir)
{                                                           // 0 = ouput; 1 = input
	i2cStatus = I2CStart( address | PCA9554_MANUF_CODE, I2C_START_WRITE );
   	i2cStatus += I2CSend( 0x03 );
   	i2cStatus += I2CSend( dir );
   	i2cStatus += I2CStop();
   	
   	if(CheckErrorI2C() == I2COMM_ERROR)
   	{
   		return PCA9554_ERROR;
   	}
   	
   	printf("PCA9554 Init ok...\r\n");
   	return PCA9554_OK;
   	   		
}
//*********************************************************************
//***************************  WRITE PCA 9555  ************************
//*********************************************************************
void Write_PCA9554(BYTE address, BYTE data)
{
   	sim.i2c.sr = 0;  //clears all interupts and previous i2c conditions
   	sim.i2c.cr = 0;  //clears all interupts and previous i2c conditions

	i2cStatus = I2CStart( address | PCA9554_MANUF_CODE, I2C_START_WRITE );
   	i2cStatus += I2CSend( 0x01 );
   	i2cStatus += I2CSend( data );
   	i2cStatus += I2CStop();
}
//*********************************************************************
//****************************  READ PCA9555  *************************
//*********************************************************************
BYTE Read_PCA9554(BYTE address)
{

	BYTE Read_buffer[1];
   	
   	sim.i2c.sr = 0;  //clears all interupts and previous i2c conditions
   	sim.i2c.cr = 0;  //clears all interupts and previous i2c conditions

	i2cStatus = I2CStart( address | PCA9554_MANUF_CODE, I2C_START_WRITE );
   	i2cStatus += I2CSend( 0x00 );
   	i2cStatus += I2CRestart( address | PCA9554_MANUF_CODE, I2C_START_READ );
   	i2cStatus += I2CReadBuf(address | PCA9554_MANUF_CODE, Read_buffer, 1);    
   	i2cStatus += I2CStop();
      
    return Read_buffer[0];
}
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by lgitlitz »

When I connect up a new I2C device and it fails to communicate I will usually do a scan through all valid addresses to see if any respond (I2CStart returns without error). You should first test this code without your accelerometer connected to the dev-board, the RTC should repond. Then connect your device and see if both devices respond.

for( int x =0; x<128; x++)
{
if( I2CStart( x, I2C_START_READ ) < I2C_TIMEOUT )
iprintf("We have a %X on the bus\r\n", x );
I2CStop();
}
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by seulater »

Great Tip Larry, i do the exact same thing, i should have mentioned that.
arbotic
Posts: 7
Joined: Wed May 19, 2010 12:39 pm

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by arbotic »

Thanks lgitlitz and seulater

I get 0 devices when I run the loop. I can set the RTC using the time project. Checked that this weekend. So I thought that the I2C bus was working, right?

From MTTTY and time project

Code: Select all

Enter the following numbers to perform clock tasks:
(1) Get NTP time and set both system and RTC clocks.
(2) Manually set both the system and RTC time.
(3) Read Real Time and System Clocks
(4) Manually set Real Time Clock
(5) Get the time from the RTC and set the system time
(?) To display this menu
3
RTC Time = Mon May 24 17:28:07 2010
---System Time----
GMT Time = Thu Jan  1 00:00:15 1970
Local Time = Wed Dec 31 17:00:15 1969

Getting time form I/O board
System Time is now set
3
RTC Time = Mon May 24 17:28:17 2010
---System Time----
GMT Time = Mon May 24 17:28:18 2010
Local Time = Mon May 24 10:28:18 2010


                                                                               S
I might have messed up soldering the pin headers. Not sure...
Last edited by arbotic on Mon May 24, 2010 5:29 pm, edited 2 times in total.
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by seulater »

I think something is wrong with your loop code.
If you scanned from 0 to 255 you should have seen the RTC pop up.
arbotic
Posts: 7
Joined: Wed May 19, 2010 12:39 pm

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by arbotic »

Good point I've been messing around with the code. I'll start from scratch and post the code here is a few minutes.

If I can set the RTC, then the I2C bus is ok, right?
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by seulater »

yup
arbotic
Posts: 7
Joined: Wed May 19, 2010 12:39 pm

Re: How do I setup I2C on MOD5270/Mod-Dev-70

Post by arbotic »

Well, I guess I should have asked this... What is the address of the RTC? Been looking through the manuals but...

When I loop from 0 to 255 I get a response from 0x00 and 0x80

Code: Select all

if( I2CStart( x, I2C_START_WRITE ) < I2C_TIMEOUT )
   iprintf("We have a %X on the bus\r\n", x );
   I2CStop(); 
If I do this I get a response from 0, 57, 6F, 80, D7, and EF

Code: Select all

if( I2CStart( x, I2C_START_READ ) < I2C_TIMEOUT )
   iprintf("We have a %X on the bus\r\n", x );
   I2CStop(); 
Is this correct? Thanks all.
Post Reply