EmbeddedRelated.com
Forums

I2C Problem

Started by Carmel August 22, 2007
Hi all,

I am trying to drive an I2C device from a windows CE board,
unfortunately without success. I am trying the following test
program...

void I2CStart()
{
// Initialize the unit

// put slave address in ISAR
g_wISAR = 0x20;

// enable desired interrupts in ICR.
// Arbitration loss detect interrupt NOT enabled

g_wICR |= (ICR_ITEIE | ICR_IRFIE | ICR_BEIE | ICR_SSDIE | ICR_SADIE);


// enable i2c and scl
g_wICR |= (ICR_IUE | ICR_SCLE);

// write to motor driver
g_byIDBR = (0xb0);


// disable stop and arbitration in icr
g_wICR &= ~(ICR_STOP | ICR_ALDIE);

// enable start and transfer byte in icr
g_wICR |= ICR_START;
g_wICR |= ICR_TB;


Sleep(100);

PrintI2C();
}

PrintI2C() is a very simple function that lists all the I2C registers.
All but ISR have the expected values; ISR value is 0. I Think that at
this stage it should have had the Transmit Empty flag enabled (?).

Controller I2C supply voltage is 3.3 volts, board is 5V. I am using a
PCA9306 to shift levels.   I have soldered two 2k2 (from SCL and SDA
to supply)  both sides.


Any Ideas please?

Thanks
Best Regards

Carmel Gafa

So what are you observing or not observing?  What's happening that you
don't like?

Actually, I don't know if you need the level shifter.  As long as you
use 3.3 volts for the pullups and make sure your 5 volt device does
not actively drive high, you should have no trouble with mixing 3 and
5 volt devices on the bus.  A small series resistor on the 5 volt
devices will protect everyone in case of a programming error.  BTW, it
is very likely that your board devices are 3.3 volt anyway.  The 5
volts in is likely being converted to 3.3 volts to power most of the
board.  Not much is actually 5 volts these days.

One other comment, I don't know what devices you have on the bus, so I
have no idea what the various control registers do or what the various
constants are.


On Aug 22, 7:58 pm, Carmel <carmelg...@gmail.com> wrote:
> Hi all, > > I am trying to drive an I2C device from a windows CE board, > unfortunately without success. I am trying the following test > program... > > void I2CStart() > { > // Initialize the unit > > // put slave address in ISAR > g_wISAR = 0x20; > > // enable desired interrupts in ICR. > // Arbitration loss detect interrupt NOT enabled > > g_wICR |= (ICR_ITEIE | ICR_IRFIE | ICR_BEIE | ICR_SSDIE | ICR_SADIE); > > // enable i2c and scl > g_wICR |= (ICR_IUE | ICR_SCLE); > > // write to motor driver > g_byIDBR = (0xb0); > > // disable stop and arbitration in icr > g_wICR &= ~(ICR_STOP | ICR_ALDIE); > > // enable start and transfer byte in icr > g_wICR |= ICR_START; > g_wICR |= ICR_TB; > > Sleep(100); > > PrintI2C(); > > } > > PrintI2C() is a very simple function that lists all the I2C registers. > All but ISR have the expected values; ISR value is 0. I Think that at > this stage it should have had the Transmit Empty flag enabled (?). > > Controller I2C supply voltage is 3.3 volts, board is 5V. I am using a > PCA9306 to shift levels. I have soldered two 2k2 (from SCL and SDA > to supply) both sides. > > Any Ideas please? > > Thanks > Best Regards > > Carmel Gafa
On Aug 23, 2:21 pm, rickman <gnu...@gmail.com> wrote:
> So what are you observing or not observing? What's happening that you > don't like? > > Actually, I don't know if you need the level shifter. As long as you > use 3.3 volts for the pullups and make sure your 5 volt device does > not actively drive high, you should have no trouble with mixing 3 and > 5 volt devices on the bus. A small series resistor on the 5 volt > devices will protect everyone in case of a programming error. BTW, it > is very likely that your board devices are 3.3 volt anyway. The 5 > volts in is likely being converted to 3.3 volts to power most of the > board. Not much is actually 5 volts these days. > > One other comment, I don't know what devices you have on the bus, so I > have no idea what the various control registers do or what the various > constants are. > > On Aug 22, 7:58 pm, Carmel <carmelg...@gmail.com> wrote: > > > > > Hi all, > > > I am trying to drive an I2C device from a windows CE board, > > unfortunately without success. I am trying the following test > > program... > > > void I2CStart() > > { > > // Initialize the unit > > > // put slave address in ISAR > > g_wISAR = 0x20; > > > // enable desired interrupts in ICR. > > // Arbitration loss detect interrupt NOT enabled > > > g_wICR |= (ICR_ITEIE | ICR_IRFIE | ICR_BEIE | ICR_SSDIE | ICR_SADIE); > > > // enable i2c and scl > > g_wICR |= (ICR_IUE | ICR_SCLE); > > > // write to motor driver > > g_byIDBR = (0xb0); > > > // disable stop and arbitration in icr > > g_wICR &= ~(ICR_STOP | ICR_ALDIE); > > > // enable start and transfer byte in icr > > g_wICR |= ICR_START; > > g_wICR |= ICR_TB; > > > Sleep(100); > > > PrintI2C(); > > > } > > > PrintI2C() is a very simple function that lists all the I2C registers. > > All but ISR have the expected values; ISR value is 0. I Think that at > > this stage it should have had the Transmit Empty flag enabled (?). > > > Controller I2C supply voltage is 3.3 volts, board is 5V. I am using a > > PCA9306 to shift levels. I have soldered two 2k2 (from SCL and SDA > > to supply) both sides. > > > Any Ideas please? > > > Thanks > > Best Regards > > > Carmel Gafa- Hide quoted text - > > - Show quoted text -
Rickman, Thanks for reply. I am trying to connect an Arcom Viper to an MD22 motor driver board by robot-electronics., http://www.robot-electronics.co.uk/htm/md22tech.htm I have found several articles where it is suggested to include a shifter, i agree with you, both pins are al 0V unless pulled up..... Problem is that contents of ISR is 0 all the time. I would like , if possible, some verification that the code is correct..... Thank you, Best Regards Carmel
On Aug 23, 2:53 pm, Carmel <carmelg...@gmail.com> wrote:
> On Aug 23, 2:21 pm, rickman <gnu...@gmail.com> wrote: > > > > > > > So what are you observing or not observing? What's happening that you > > don't like? > > > Actually, I don't know if you need the level shifter. As long as you > > use 3.3 volts for the pullups and make sure your 5 volt device does > > not actively drive high, you should have no trouble with mixing 3 and > > 5 volt devices on the bus. A small series resistor on the 5 volt > > devices will protect everyone in case of a programming error. BTW, it > > is very likely that your board devices are 3.3 volt anyway. The 5 > > volts in is likely being converted to 3.3 volts to power most of the > > board. Not much is actually 5 volts these days. > > > One other comment, I don't know what devices you have on the bus, so I > > have no idea what the various control registers do or what the various > > constants are. > > > On Aug 22, 7:58 pm, Carmel <carmelg...@gmail.com> wrote: > > > > Hi all, > > > > I am trying to drive an I2C device from a windows CE board, > > > unfortunately without success. I am trying the following test > > > program... > > > > void I2CStart() > > > { > > > // Initialize the unit > > > > // put slave address in ISAR > > > g_wISAR = 0x20; > > > > // enable desired interrupts in ICR. > > > // Arbitration loss detect interrupt NOT enabled > > > > g_wICR |= (ICR_ITEIE | ICR_IRFIE | ICR_BEIE | ICR_SSDIE | ICR_SADIE); > > > > // enable i2c and scl > > > g_wICR |= (ICR_IUE | ICR_SCLE); > > > > // write to motor driver > > > g_byIDBR = (0xb0); > > > > // disable stop and arbitration in icr > > > g_wICR &= ~(ICR_STOP | ICR_ALDIE); > > > > // enable start and transfer byte in icr > > > g_wICR |= ICR_START; > > > g_wICR |= ICR_TB; > > > > Sleep(100); > > > > PrintI2C(); > > > > } > > > > PrintI2C() is a very simple function that lists all the I2C registers. > > > All but ISR have the expected values; ISR value is 0. I Think that at > > > this stage it should have had the Transmit Empty flag enabled (?). > > > > Controller I2C supply voltage is 3.3 volts, board is 5V. I am using a > > > PCA9306 to shift levels. I have soldered two 2k2 (from SCL and SDA > > > to supply) both sides. > > > > Any Ideas please? > > > > Thanks > > > Best Regards > > > > Carmel Gafa- Hide quoted text - > > > - Show quoted text - > > Rickman, > > Thanks for reply. > > I am trying to connect an Arcom Viper to an MD22 motor driver board by > robot-electronics.,http://www.robot-electronics.co.uk/htm/md22tech.htm > > I have found several articles where it is suggested to include a > shifter, i agree with you, both pins are al 0V unless pulled up..... > > Problem is that contents of ISR is 0 all the time. I would like , if > possible, some verification that the code is correct..... > > Thank you, > Best Regards > > Carmel- Hide quoted text - > > - Show quoted text -
Hi, I think that problem is software related.... I connected a scope to monitor the SCL/SDA activity; and it was flat, nothing is happening. I will greatly appreciate any help Thanks
On Aug 23, 4:29 pm, Carmel <carmelg...@gmail.com> wrote:
> On Aug 23, 2:53 pm, Carmel <carmelg...@gmail.com> wrote: > > > > > On Aug 23, 2:21 pm, rickman <gnu...@gmail.com> wrote: > > > > So what are you observing or not observing? What's happening that you > > > don't like? > > > > Actually, I don't know if you need the level shifter. As long as you > > > use 3.3 volts for the pullups and make sure your 5 volt device does > > > not actively drive high, you should have no trouble with mixing 3 and > > > 5 volt devices on the bus. A small series resistor on the 5 volt > > > devices will protect everyone in case of a programming error. BTW, it > > > is very likely that your board devices are 3.3 volt anyway. The 5 > > > volts in is likely being converted to 3.3 volts to power most of the > > > board. Not much is actually 5 volts these days. > > > > One other comment, I don't know what devices you have on the bus, so I > > > have no idea what the various control registers do or what the various > > > constants are. > > > > On Aug 22, 7:58 pm, Carmel <carmelg...@gmail.com> wrote: > > > > > Hi all, > > > > > I am trying to drive an I2C device from a windows CE board, > > > > unfortunately without success. I am trying the following test > > > > program... > > > > > void I2CStart() > > > > { > > > > // Initialize the unit > > > > > // put slave address in ISAR > > > > g_wISAR = 0x20; > > > > > // enable desired interrupts in ICR. > > > > // Arbitration loss detect interrupt NOT enabled > > > > > g_wICR |= (ICR_ITEIE | ICR_IRFIE | ICR_BEIE | ICR_SSDIE | ICR_SADIE); > > > > > // enable i2c and scl > > > > g_wICR |= (ICR_IUE | ICR_SCLE); > > > > > // write to motor driver > > > > g_byIDBR = (0xb0); > > > > > // disable stop and arbitration in icr > > > > g_wICR &= ~(ICR_STOP | ICR_ALDIE); > > > > > // enable start and transfer byte in icr > > > > g_wICR |= ICR_START; > > > > g_wICR |= ICR_TB; > > > > > Sleep(100); > > > > > PrintI2C(); > > > > > } > > > > > PrintI2C() is a very simple function that lists all the I2C registers. > > > > All but ISR have the expected values; ISR value is 0. I Think that at > > > > this stage it should have had the Transmit Empty flag enabled (?). > > > > > Controller I2C supply voltage is 3.3 volts, board is 5V. I am using a > > > > PCA9306 to shift levels. I have soldered two 2k2 (from SCL and SDA > > > > to supply) both sides. > > > > > Any Ideas please? > > > > > Thanks > > > > Best Regards > > > > > Carmel Gafa- Hide quoted text - > > > > - Show quoted text - > > > Rickman, > > > Thanks for reply. > > > I am trying to connect an Arcom Viper to an MD22 motor driver board by > > robot-electronics.,http://www.robot-electronics.co.uk/htm/md22tech.htm > > > I have found several articles where it is suggested to include a > > shifter, i agree with you, both pins are al 0V unless pulled up..... > > > Problem is that contents of ISR is 0 all the time. I would like , if > > possible, some verification that the code is correct..... > > > Thank you, > > Best Regards > > > Carmel- Hide quoted text - > > > - Show quoted text - > > Hi, I think that problem is software related.... I connected a scope > to monitor the SCL/SDA activity; and it was flat, nothing is > happening. > > I will greatly appreciate any help > > Thanks
If you see no activity is the line high or low? A high line could be nearly anything, but if it is alway low, you either have no pullup resistor or one of the chips is misprogrammed and driving low all the time. It would likely be easiest to test this by separating the units to verify each one independently. See if your master can write and you see a correct sequence. Then connect your slave and see if the bus gets clobbered. If it is correct with just the master and connecting the slave clobbers it, then you likely have a hardware problem with the slave. Else, you need to look harder at the master. If the problem is in the master, try simplifying the code to directly control the output and toggle it. Keep breaking the system down to simpler pieces until it is obvious what is wrong.