Re: [uCsimm] I2C

From: Herve BOTERMAN (hboterman@nordnet.fr)
Date: Thu Oct 26 2000 - 15:47:35 EDT


You can't use SPI port to connect I2C chips.
There is a good tips I use to connect directly I2C chips to uCsimm, without
open collector drivers:
Simply use the fact that you can configure each pin of uCsimm ports as input
or output at any time. The two state of an open collector output device
is -high impedance- or -sinking current-. You can do the same with uCsimm.
Configure the pin as an input and the pin will be in a -high impedance-,
configure the pin as an output with a 0 value and the pin will -sink
current- !
I wrote I2C routine for uCsimm with this tips and it works very well !
Note that the I2C chips can be 5V powered even if uCsimm is 3,3V. Just
connect the two pull-up bus resistors to the 3,3V supply (not to the 5V
one), there is no danger because open collector devices and I2C chips can't
source current !
I use PC.1 as SDA and PC.2 as SCL. Connect a 4,7 KOhms pullup resistor
between PC1 and VDD (3,3V) and another one between PC2 and VDD (3,3V). You
can also use two 47 ohm resistor to connect each I2C devices on this bus,
this improve speed accuracy but it's optionnal on small PCB design (connect
the first on between SDA's bus line and SDA's chip pin, the other one
between SCL's bus line and SCL's chip pin, this for each I2C device you
connect on the bus. Place this resistors near the I2C chips).

Here is my sources, have fun !

Herve BOTERMAN
+33 673 299 848
FRANCE.

--------------------------------------------------------------
#include <asm/MC68EZ328.h>
#include <stdio.h>

void i2c_start(void),i2c_stop(void);
unsigned char i2c_putc(unsigned char),i2c_getc(unsigned char);
#define i2c_ack 0
#define i2c_nack 1

void i2c_start()
{
 PCDIR|=1; /* SDA=0 */
 PCDIR|=1;
 PCDIR|=2; /* SCL=0 */
 PCDIR|=2;
 return;
}

void i2c_stop()
{
 PCDIR|=1; /* SDA=0 */
 PCDIR&=0xFD; /* SCL=1 */
 PCDIR&=0xFD;
 PCDIR&=0xFE; /* SDA=1 */
 PCDIR&=0xFE;
}

unsigned char i2c_putc(unsigned char c)
{
 register unsigned char j;

 for(j=128;j;j=j>>1)
  {
   if(c&j) /* set SDA */
    PCDIR&=0xFE;
   else
    PCDIR|=1;
   PCDIR|=2;
   PCDIR&=0xFD; /* SCL=1 */
   PCDIR&=0xFD;
   PCDIR|=2; /* SCL=0 */
  }
 PCDIR&=0xFE; /* release SDA */
 PCDIR&=0xFD; /* SCL=1 */
 PCDIR&=0xFD;
 c=PCDATA&1;
 PCDIR|=2; /* SCL=0 */

 return c;
}

unsigned char i2c_getc(unsigned char ack)
{
 register unsigned char c,i;

 for(i=0;i<8;i++)
  {
   PCDIR&=0xFD; /* SCL=1 */
   PCDIR&=0xFD;
   c=c<<1;
   c|=PCDATA&1;
   PCDIR|=2; /* SCL=0 */
   PCDIR|=2;
  }
 if(ack) /* set ACK/NACK */
  PCDIR&=0xFE;
 else
  PCDIR|=1;
 PCDIR&=0xFD;
 PCDIR&=0xFD;
 PCDIR|=2; /* SCL=0 */
 PCDIR&=0xFE;
 return c;
}
---------------------------------------------------
Here is an example to program a TDA 8444 (octal 6bits DACs)

void TDA8444_set_dac(char dac,char data)
{
 i2c_start();
 if(!i2c_putc(0x40)) /* send a write command and go on if it is acknowledged
*/
  {
   i2c_putc(dac & 0x0F); /* write DAC address*/
   i2c_putc(data); /* write data */
  }
 i2c_stop(); /* send stop command */
}

>
> Hi,
>
> Does anyone know if ucsimm SPI port is compatible with
> I2C bus ?
>
> Where could I find the ucsimm schematics ?
> (with all the connections between the ICs)
>
> Thanks for ypur help.
>
> best regards.
>
> +++++++++++
> Eric
>
>
>
>
> =====
> **************************************
> GIRAULT Eric
> Tornihaukantie 6-8 D17
> 90250 OULU FINLAND
> +358 8 531 5106
>

This message resent by the ucsimm@uclinux.com list server http://www.uClinux.com/



This archive was generated by hypermail 2b30 : Sun Apr 07 2002 - 00:01:38 EST