??? 02/04/09 15:40 Read: times |
#162056 - dynamic parameters in an I2C definition possible? |
I'm trying to find a way to dynamically adjust the transmit parameters based on the device values that I want to send. The code below works the way I expect it to, the idea is that when I set the MAX_NUMBYTE_TX[0] to some number, that is the amount of data bytes the I2C databus transmits to the target slave device. In simulation, it works exactly as expected.
My only question is, my prototype and function has a listing of 7 actual passed parameters. I was thinking of using a switch/case to look at the MAX_NUMBYTE_TX[0] and then use the case parameter set for the number of data bytes that correspond to the amount of needed bytes to send to the target device. If I send two bytes, the compiler warns that two few actual parameters......which is expected. I want to code the I2C transmit dynamically based MAX_NUMBYTE_TX[0] value, and I don't want the compiler to warn about it. When I try to do the switch/case, it complains of mixed parameter values for that function. Is there a way to handle this without having to change the warning levels in the compiler. Obviously my goal is 0 errors and warnings. I believe I've pasted all the code below, any pointers would help. thanks! Chris Called from main.c file MAX_NUMBYTE_TX[0] = 0; //Transmit 1 bytes of DATA ONLY on I2C i2c_init(0x20, 0); //Set to master with address of 0x20, no general call i2c_transmit(0x3B, 0x03); // enable mux channels 0-1 while (i2c_getstatus() & I2C_BUSY); // wait until complete MAX_NUMBYTE_TX[0] = 1; i2c_init(0x20, 0); //Set to master with address of 0x20, no general call i2c_transmit(0x3B, 0x03, 0x04); // enable mux channels 0-1 while (i2c_getstatus() & I2C_BUSY); // wait until complete MAX_NUMBYTE_TX[0] = 2; i2c_init(0x20, 0); //Set to master with address of 0x20, no general call i2c_transmit(0x3B, 0x03, 0x04, 0x05); // enable mux channels 0-1 while (i2c_getstatus() & I2C_BUSY); // wait until complete ========================================================================= used in IO.c file uchar MAX_NUMBYTE_TX[] = {7}; uchar i2c_transmit(uchar address, uchar byte0, uchar byte1, uchar byte2, uchar byte3, uchar byte4, uchar byte5, uchar byte6) { transmit_bytes[BYTE_0] = byte0; //defined in header file transmit_bytes[BYTE_1] = byte1; //defined in header file transmit_bytes[BYTE_2] = byte2; //defined in header file transmit_bytes[BYTE_3] = byte3; //defined in header file transmit_bytes[BYTE_4] = byte4; //defined in header file transmit_bytes[BYTE_5] = byte5; //defined in header file transmit_bytes[BYTE_6] = byte6; //defined in header file // 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 //Data array definitions for I2C send #define BYTE_0 0 #define BYTE_1 1 #define BYTE_2 2 #define BYTE_3 3 #define BYTE_4 4 #define BYTE_5 5 #define BYTE_6 6 extern unsigned char i2c_transmit(unsigned char address, unsigned char byte0, unsigned char byte1,unsigned char byte2,unsigned char byte3, unsigned char byte4,unsigned char byte5,unsigned char byte6); ========================================================================= |
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 |