View previous topic :: View next topic |
Author |
Message |
Ed Arnold
Joined: 02 Nov 2003 Posts: 18
|
pointer to array of structures |
Posted: Sat Apr 10, 2004 9:25 pm |
|
|
I have two PICs communicating thru i2c. I want to send an entire structure to the slave PIC. So I need to use a pointer, right. Only, this is an array of stuctures. I have never done this before and can't seem to find any examples anywhere. Any input or examples would be recieved with much thanks.
Code: |
static struct
{
int UID;
int time[3];
int VAL_A;
int VAL_B;
int KEY_CODE;
int DOLLARS;
int CENTS;
}TRANS_QUE[16], *p_tque;
|
Ed Arnold |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Sun Apr 11, 2004 10:47 am |
|
|
If you set your pointer to the first byte of the structure array as a starting point you can develop it from there. Once you have that done you can increment the pointer by the structure size times the structure index you want to send. I seem to remember someone posting about using a sizeof function to determine the size of a structure in relation to this. Another artical that may help is this one linked.
http://www.embedded.com/showArticle.jhtml?articleID=18312031 |
|
|
Ttelmah Guest
|
Re: pointer to array of structures |
Posted: Mon Apr 12, 2004 7:40 am |
|
|
Ed Arnold wrote: | I have two PICs communicating thru i2c. I want to send an entire structure to the slave PIC. So I need to use a pointer, right. Only, this is an array of stuctures. I have never done this before and can't seem to find any examples anywhere. Any input or examples would be recieved with much thanks.
Code: |
static struct
{
int UID;
int time[3];
int VAL_A;
int VAL_B;
int KEY_CODE;
int DOLLARS;
int CENTS;
}TRANS_QUE[16], *p_tque;
|
Ed Arnold |
If you do something like:
Code: |
static struct mystruct {
int UID;
int time[3];
int VAL_A;
int VAL_B;
int KEY_CODE;
int DOLLARS;
int CENTS;
}TRANS_QUE[16], *p_tque;
int8 counter;
char *ptr;
ptr=(char *)TRANS_QUE;
for (counter=0;counter<sizeof(mystruct*16);counter++) {
send_byte(*ptr++);
}
|
It should send the entire structure array using the routine 'send_byte' (suitable definition needed for this...).
Best Wishes |
|
|
|