Trevor Switkowski

I2C Help

Discussion created by Trevor Switkowski on May 13, 2006
Latest reply on Jun 17, 2010 by Supparerk Saikaew
Hi everyone,

I am starting my first experience with I2C! I am trying to communicate with a MAXIM keypad controller, and am using the following function to send an array of 4 bytes:


void I2CsendString(uint8 *data, uint16 length, uint8 address, uint8 id)
{
uint16 i;
MCF_I2C_I2CR |= MCF_I2C_I2CR_MTX; //become master

MCF_I2C_I2CR |= MCF_I2C_I2CR_MSTA; //send start bit
MCF_I2C_I2DR = id; //send slave addr
while( !(MCF_I2C_I2SR & MCF_I2C_I2SR_IIF )); //wait till xfer is done
MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF; //clear flag
MCF_I2C_I2DR = address; //send register addr
while( !(MCF_I2C_I2SR & MCF_I2C_I2SR_IIF )); //wait till xfer is done
MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF; //clear flag

for(i = 0 ; i length ; i++)
{
MCF_I2C_I2DR = data[i]; //send data byte addr
while( !(MCF_I2C_I2SR & MCF_I2C_I2SR_IIF )); //wait till xfer is done
MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF; //clear flag

/
}
return;
}


now, for some reason, when this function gets called, it never returns! when i run the debugger, i see the stack having the function that called this one, then a memory offset from IPSBAR, which is to a set of memory that is cleared! it seems to get through the first few tranfers, at least (slave address, device register address), i think! can anyone see any holes in my code? By the way, the device wants to see a transfer like this:

[start][slave addr][ACK][control byte][ACK][N data bytes][ack after each byte][stop]

I am running the bus at slower than 400kHz, which is the upper limit of the device, and am using the correct address, as per the datasheet.

I don't have interrupts enabled for this, or anything like that (though there are other interrupts running on the device).



...SPI is so much easier!!!!


Thanks in advance,
Trevor

--update--
i programmed the code to FLASH, and now it doesn't run off into space, but it doesn't look like the controller is getting initialized properly. can anyone see where an error might be?
If you could look at the datasheet, maybe, that would be great (this is a MAX7348 device). you don't have to, but any suggestions on my code would be awesome too!

/update

Message Edited by airswit on 05-13-200601:00 AM

Outcomes