Read a digital input pin then write it's value to a characteristic?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
PaDo_1228851
Level 3
Level 3
25 replies posted 10 replies posted 10 questions asked

The code immediately below works fine.  The value "5"  is successfully written to the characteristic:

   

uint8 tilt_0 = 5;

   

tilt_0_Handle.attrHandle = CYBLE_MYSERVICE_TILT_0_CHAR_HANDLE;

   

tilt_0_Handle.attrHandle.value.val = (uint8 *)&tilt_0;

   

tilt_0_Handle.attrHandle.value.len = 1;

   

CyBle_GattsWriteAttributeValue(&tilt_0_Handle, 0, NULL, CYBLE_GATT_DB_LOCALLY_INITITATED);

   

CyBle_GattsWriteRsp(connectionHandle);

   

But when the following substitution is made for the value "5" in the first line, the value of the pin (which can be either 1 or 0) is not written to the characteristic:

   

uint8 tilt_0 = MyDigitalInputPin_Read();

   

I've also tried writing the output values from the scanning comparator with no success.

   

Am I using the wrong data type for the pin read? 

   

Thanks.

0 Likes
1 Solution

Thanks for your response.  It was a timing issue.  You are right, I was running the code in an isr.  The pin was always reading 0 because I didn't give the light sensitive transistor switch (which the pin was reading) enough time to turn completely on.  I powered up the transistor well before calling the isr and the switch read fine.  Thanks for your comments.

View solution in original post

0 Likes
3 Replies
Anonymous
Not applicable

The Pin_Read() should return a uint8 from what I see in the PSOC Creator. My guess would be that it is reading the pin, but the value is not what you expect? Or if you are running the code in an isr, then it is taking too long to run, causing issues?

   

Maybe try reading the pin value, and buffering it to a value in main, and then send the buffered value in the response?

0 Likes

Thanks for your response.  It was a timing issue.  You are right, I was running the code in an isr.  The pin was always reading 0 because I didn't give the light sensitive transistor switch (which the pin was reading) enough time to turn completely on.  I powered up the transistor well before calling the isr and the switch read fine.  Thanks for your comments.

0 Likes
Anonymous
Not applicable

Glad you figured it out; you're welcome

   

Pratt

0 Likes