| ??? 02/05/09 15:04 Modified: 02/05/09 15:25 Read: times |
#162104 - Try this code Responding to: ???'s previous message |
I haven't compiled this code, but it should be pretty close
I2C.C file
unsigned char i2c_transmit(unsigned char address, unsigned char *transmit_bytes, unsigned char num_bytes_send)
{
//extern unsigned char byte1, byte2;
// if already busy then return current status
if (i2cstatus & I2C_BUSY) return i2cstatus;
// now we are busy performing a transfer
i2cstatus = I2C_BUSYTX;
// store slave address + W for use in ISR
slaveaddress = address << 1;
// transmit start condition
STA = 1;
// transmission started
return I2C_OK;
}
=========================================================================
Defined in i2c.h file
extern unsigned char i2c_transmit(unsigned char address, unsigned char *transmit_bytes, unsigned char num_bytes_send);
=========================================================================
Defined in IO.c file
unsigned char MAX_NUMBYTE_TX = 7;
=========================================================================
Defined in I/O.c
unsigned char transmit_bytes[MAX_NUMBYTE_TX]; //Holds I2C data bytes
//only
//Not address
=========================================================================
called from main.c
transmit_bytes[0]=0x03;
i2c_init(0x20, 0); //Set to master with address of 0x20, no general call
i2c_transmit(0x3B, &transmit_bytes, 1); // send 1 byte
while (i2c_getstatus() & I2C_BUSY); // wait until complete
transmit_bytes[0]=0x03;
transmit_bytes[1]=0x04;
i2c_init(0x20, 0); //Set to master with address of 0x20, no general call
i2c_transmit(0x3B, &transmit_bytes, 2); // send 2 bytes
while (i2c_getstatus() & I2C_BUSY); // wait until complete
transmit_bytes[0]=0xfe;
transmit_bytes[1]=0x04;
transmit_bytes[2]=0x05;
i2c_init(0x20, 0); //Set to master with address of 0x20, no general call
i2c_transmit(0x3B, &transmit_bytes, 3); // send 3 bytes
while (i2c_getstatus() & I2C_BUSY); // wait until complete
I forgot to mention that your i2c_transmit routine needs to loop on the num_bytes_send parameter to send as many bytes. I think you can manage that part. |
| Topic | Author | Date |
| dynamic parameters in an I2C definition possible? | 01/01/70 00:00 | |
| how about | 01/01/70 00:00 | |
| trans_byte buffer? | 01/01/70 00:00 | |
| something like: | 01/01/70 00:00 | |
| Updated, but errors on my part | 01/01/70 00:00 | |
| This | 01/01/70 00:00 | |
| I must be stuck on stupid | 01/01/70 00:00 | |
| I Think it is this | 01/01/70 00:00 | |
| Array of pointers to characters | 01/01/70 00:00 | |
| Try this code | 01/01/70 00:00 | |
| Works great!...One question though | 01/01/70 00:00 | |
| The warning is real | 01/01/70 00:00 | |
| Not exactly as I coded | 01/01/70 00:00 | |
Update......Problem solved | 01/01/70 00:00 |



