Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

Anonymous
Not applicable

Hi everyone!

   

I am intending to share data between two functions on a different .c files. On all examples I have seen on PSoC Creator,  all of them uses variables declared as a "extern", so it os possible share data between functions on different .c files .

   

I am trying to use pointers as a function arguments, but it seems I am doing something wrong. Here is a portion of my code:

   
        
  • Sensors.c file :
  •    
   

uint8 *ReadByteData;

   

uint8 MPU9250_alive_request(void){

   

I2CMaster_ReadByte(MPU9250_ADDRESS, wrData, ReadByteData);
UART_UartPutString("data is : 0x");
sprintf(UARTbufferASCII,"%x", *ReadByteData); //convert hex to ASCII
UART_UartPutString(UARTbufferASCII);
UART_UartPutString("\n\r");

   

}

   
        
  • I2CMaster.c file:
  •    
   

uint8 I2CMaster_ReadByte (uint32 address, uint8 *subAddress, uint8 *data){

   

I2C_I2CMasterReadBuf(address, data, 1, I2C_I2C_MODE_COMPLETE_XFER);

   

}

   

The issue is that the code above is not working, but if I declare uint8 *ReadByteData inside of the MPU9250_alive_request() function all is working good, but that variable wouldn't be visible on all variables of Sensors.c file. Why if I declare the variable inside the function works? As I know about pointer usage, the code above should work if I do that:

   
        
  • Sensors.c file :
  •    
   

uint8 *ReadByteData;

   

uint8 MPU9250_alive_request(void){

   

I2CMaster_ReadByte(MPU9250_ADDRESS, wrData, &ReadByteData);
UART_UartPutString("data is : 0x");
sprintf(UARTbufferASCII,"%x", *ReadByteData); //convert hex to ASCII
UART_UartPutString(UARTbufferASCII);
UART_UartPutString("\n\r");

   

}

   
        
  • I2CMaster.c file:
  •    
   

uint8 I2CMaster_ReadByte (uint32 address, uint8 *subAddress, uint8 *data){

   

I2C_I2CMasterReadBuf(address, data, 1, I2C_I2C_MODE_COMPLETE_XFER);

   

}

   

But the outcome is that is not working. On another projects using different IDE it has worked good, but I don't know why not here

   

It seems like PSoC creator is not behaving good with pointers. Could anyone help me?

   

Thank you so much in advance!

   

 

   

Josué

   

pd:Attached is the complete files code I'm speaking about

   
    0 Likes
    1 Reply
    Bob_Marlowe
    Expert II

    Welcome in the forum, Josué

       

    Since you already defined ReadByteData to be a pointer, you must not reference it once more. so you should write

       

    I2CMaster_ReadByte(MPU9250_ADDRESS, wrData, ReadByteData); // No "&" here

       

     

       

    Btw:

       

    What you think of

       

    UART_UartPutString("data is : 0x%x\n\r", (uint16)*ReadByteData);//convert hex to ASCII (%x expects an int, not a byte. So the cast)

       

    PSoC Creator 3.2 uses GCC as compiler and there are no issues known with pointers (so far).

       

     

       

    Happy coding

       

     

       

    Bob

    0 Likes