Ok im using a MSPF5659 and originally had alot of trouble getting i2c to work properly. now a driver for some led's i have will never work with i2c because the chip is not designed to ack back.... well through help on the forums i got an i2c bit banged function that worked great for the led driver. i now need a receive function and was wondering if anyone had any pointers.. the pins are port mapped and i was going to just switch the port mapping to gpio whenever i did the led driver but its been decided above me to just do it all bit banged. i know i can use my normal function as far as sending the address but then have to re direct the gpio pins as inputs and read bit by bit into bytes and store the data into an array... any ideas
this is what i have to transmit out
//function to transmit one byte in master transmit
void TransmitByte (unsigned char Value)
{
unsigned char c;
unsigned int i;
// Add 9th bit
i = ((unsigned int)Value<<1) +1;
for (c=9; c>0; c--)
{
// Set SCL low
I2C_OUT &= ~USCL;
// Set bit state
if ((i & 0x0100) != 0) {I2C_OUT |= USDA;} else {I2C_OUT &= ~USDA;}
// Rotate bits
i <<= 1;
// Set SCL high
I2C_OUT |= USCL;
}
// Exit with SCL low
I2C_OUT &= ~USCL;
}
//function to bitbang start, stop, and bytes over i2c
void MasterTransmit (unsigned char Address, unsigned char* Data, unsigned int Number)
{
unsigned int i;
unsigned char* p;
// Set START condition
I2C_OUT |= USCL + USDA;
I2C_OUT &= ~USDA;
// Transmit address
// Strip bit 0
TransmitByte((Address<<1) & 0xFE);
// Transmit data
p = Data;
for (i=Number; i>0; i--) {TransmitByte(*p++);}
// Set STOP condition
I2C_OUT &= ~USDA;
I2C_OUT |= USCL;
I2C_OUT |= USDA;
}