![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Pointer to struct |
Posted: Mon Sep 12, 2011 9:48 am |
|
|
I have the following function to write to an external SPI EEPROM.
Code: | void FillBufferEE(long StartAddress, char *DataBuffer, char ByteCount)
{
#warning "Esta funcion no controla desbordamientos de buffer; el buffer debe tener suficiente espacio para la cantidad de datos solicitados"
char x;
while(EE_Busy())
{
delay_us(10);
}
output_low(CS);
spi_write(Read);
spi_write(make8(StartAddress,1));
spi_write(make8(StartAddress,0));
for(x=0;x<ByteCount;x++)
{
DataBuffer[x]=spi_read(0);
}
output_high(CS);
} |
And I think maybe I should declare it
Code: | void FillBufferEE(long StartAddress, char *DataBuffer[], char ByteCount) |
I'm calling the function in many program points and is working OK but when I call the function and pass as a destination buffer a 32bit UInteger inside an struct did'nt work, It seems like doing nothing.
Code: | FillBufferEE(Timer1EE,Timer1.Setting,4); |
_________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: Pointer to struct |
Posted: Mon Sep 12, 2011 10:16 am |
|
|
E_Blue wrote: | I have the following function to write to an external SPI EEPROM.
Code: | void FillBufferEE(long StartAddress, char *DataBuffer, char ByteCount) |
Code: | FillBufferEE(Timer1EE,Timer1.Setting,4); |
|
You need to pass the *address* of Timer1.Setting. You are passing its value, which will be interpreted as an pointer, with wrong results. You need the & operator:
Code: | FillBufferEE(Timer1EE,&Timer1.Setting,4); |
If you wanted to fill an array you could write
Code: | FillBufferEE(Timer1EE,My_Array,4); |
or
Code: | FillBufferEE(Timer1EE,&My_Array[0],4); |
both should produce the same result. An array name without [] *is* a pointer in C. To pass a pointer to a specfic array element you need the & just as for a simple variable whether its in a struct or not.
RF Developer |
|
![](templates/subSilver/images/spacer.gif) |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Pointer to struct |
Posted: Mon Sep 12, 2011 12:04 pm |
|
|
Thanks!, that works pretty well. ![Wink](images/smiles/icon_wink.gif) _________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|