AnsweredAssumed Answered

Pass struct to function

Question asked by Tim Riley on Feb 23, 2017
Latest reply on Mar 2, 2017 by Tim Riley

I seem to be having some difficulty in passing a struct to a function. No errors generated by the make process but upon inspection the values inside the function are not equal to the values outside.

 

 

THE STRUCT:

struct sciData{
  uint8_t rxBuf[RSBuffSIZE]; // Receive buffer
  uint16_t RSindex; // receive buffer counter
  uint16_t RSread; // receive buffer counter

  uint32_t tempVal; //scratchpad calc storage space
  uint8_t tempChars[TBUFF_SIZE]; //temporary scratchpad for received chars
  //Data Transmit Parameters
  uint8_t txBuf[SendBuffSIZE]; /* Send buffer */
  uint16_t numTXBytes;
  uint16_t OutBytes; /* Number of bytes to send */
  uint16_t SentBytes; /* Number of bytes sent */
  uint16_t TRANSMIT; // transmit flag to let prog know interrupt
  // driven transmission in progress
  uint8_t tPtr; //pointer to current buffer item
  uint8_t dataReady; //flag to indicate return data ready
  uint8_t charCount; //number of chars received
  uint8_t commChar;
  uint16_t charsExpected;
};

 

 

STRUCT DEFINE IN MAIN:

struct sciData sci3Dat;

 

CALL FROM MAIN

//Send Mode change to Top Controller
sci3Dat.txBuf[0] = 'p';
sci3Dat.txBuf[1] = 'G';
sci3Dat.txBuf[2] = TC_START;
sci3Dat.numTXBytes = 3;

  (NOTE: At this point sci3Dat.numTXBytes = 3)

#ifdef SCI3
  SendSerialData3(&sci3Dat); //past end of data
  while(sci3Dat.TRANSMIT);
#endif

 

 

INSIDE THE FUNCTION:

/* routine called to start string transmission */
void SendSerialData3(struct sciData *sd3){
        (NOTE: At this point sd3->numTXBytes = 0)

   sd3->OutBytes = sd3->numTXBytes - 1;
   sd3->SentBytes = 0;
   sd3->TRANSMIT = 1; // We're transmitting data

   /* Set transmit buffer empty * transmit complete interrupts */
   INTR_OFF();
   SCI3CR2 = 0xEc;
   INTR_ON();
}

 

Other values are incorrect also, just included the numTXBytes as an example. Pointer to a function should be fairly simple right, but I am not sure where I have gone wrong here.

 

Any Ideas?

Outcomes