I have a 2 bit encoder connected to pins, DAI_P5 and DAI_P6. Is there a way to read the pin values in C? Is there also a way to see the values in VisualDSP?
DAI_PIN_STAT register gives the status of the DAI pins. Bits 4 and 5 gives the value of DAI_PB05 and DAI_PB06 respectively. In C you could read the value of the register DAI_PIN_STAT by using *pDAI_PIN_STAT.
In VDSP you can open the DAI pin register window to see this value. This is available under the Register option under the DAI registers.
If I do printf("%d", pDAI_PIN_STAT), it always shows 0 in the console, but if I look in the DAI register, it changes between 0 and 1. I'm not sure what I'm doing wrong.
The pDAI_PIN_STAT is a pointer to unsigned int register DAI_PIN_STAT (see the Cdef file of the processor you are using). As a result you cannot access the bits of this register as array. This is the reason you are getting the value of 0 when you access the bit as an array. The value of this register returns an unsigned int value. You could approriately And and shift it to get the value of the bit position.
For instance, If you need to know the value of bit position 4 you could do the following
unsigned int i;
i = *pDAI_PIN_STAT;
i = i & 0x10; // clears all other bits except bit 4
i = i>>4; // the value of i gives the DAI_PB05 value.
Hope this helps
With your suggestion, I was able to see 1's and 0's. However I'm coming across a different problem. I connected the least significant bit of the 2 bit encoder to DAI_P5. I made a loop to continually poll the encoder and print out the bit value of DAI_P5. I am not turning the knob of the encoder, yet the values for the LSB constantly keep changing. Do you have any insights on this?
Edit: When I attach the LSB to DAI_P6, I am once again reading all 0's. I set
Do I need to do anything else to use those pins as GPIO pins?
When you are using the DAI pins as input you need to set the corresponding pin buffer enable to low as follows
Sorry that was a typo. I do have the pin buffer enables set low with:
and I'm still getting the same problems. DAI_P6 remains unchanged. Even with nothing connected to DAI_P5, random 0's and 1's are being outputted.
Do I need to do any additional routing to use the pins as GPIO?
Make sure you do not enable the pin buffer anywhere else in the code. It would be a good idea to check the corresponding SRU PBEN register value in the register window.
Also it would be a good idea to monitor the DAI pin line with a scope. This would let you know how the input looks like at the DAI pin.
Retrieving data ...