Hello all, I have a Z8 encore platform and am trying to learn some c. Below r some snippets of code from Zilogs website using the SPI bus. I am posting to see if anyone can shed some light on the cryptic flow going on below with the pointer. In particular two questions:
Question #1 The Read_Temperature function gets called in the isr_timer0 and passes what appears to be the left value of the pointers as arguments to a function which is defined to accept the right value of pointers as arguments?? (Very confusing)
#2 The Read_Temperature function definition then appears to have arguments that are the same as the return arguments of the DS1722_Read function?? (once again very confusing)
This pointer stuff can drive a person nuts!
*********************************************CODE SNIPPET********************************************************* //declarations unsigned char DS1722_Read (unsigned char r_addr); unsigned char Read_Temperature (unsigned char *H_data, unsigned char *L_data); unsigned char SPI_Read (unsigned char addr); void isr_timer0(void);#pragma interrupt void isr_timer0(void) { unsigned char *high_data; unsigned char *low_data; Read_Temperature (high_data, low_data); }
unsigned char Read_Temperature(unsigned char *H_data, unsigned char *L_data) {
*H_data = DS1722_Read(HIGH_Read_address); //Read MSB Temperature *L_data = DS1722_Read(LOW_Read_address); //Read LSB Temperature }unsigned char DS1722_Read(unsigned char r_addr) { unsigned char r_data=0; r_data = SPI_Read (r_addr); return (r_data); }
unsigned char SPI_Read (unsigned char addr) { unsigned char data;
SPIMODE |= SSV_HIGH; // SS pin high
SPIDATA = addr; // Write Address to SPI Data Reg. SPI_Transmit_Data_Empty (); // Wait for Transmit Buffer Empty SPIDATA = 0x00; // Start SPI Read with dummy write SPI_Transmit_Data_Empty (); // Wait for Transmit Buffer Empty data = SPIDATA; // Read SPI Data Reg. SPIMODE &= ~SSV_HIGH; // SS pin low
return data; }
*********************************************CODE SNIPPET*********************************************************thanks for all the responses! Steve Wenner