Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
Anonymous
Not applicable

Hi all,

I am having some problems with using the ADC and outputting the result over I2C using CY8CKIT-042-BLE and would very much appreciate your help please!

I am trying to send 12-bit ADC output over I2C and have set up a 6-resistor potential divider to help me understand the different generated output compared to the actual voltage levels.

I am using:

Vref = VDDA/2

Unsigned differential mode

Vneg is externally set to VDDA/2

When I use the alternative resolution in the ADC and set this to 8-bit I get the output that I would expect as Vpos is changed from 0 to VDDA (3.3V), that is 0x00-0xFF.

However, when I change it back to 12-bit I get the following output:

3.3V     0x00FF

2.75V     0x006C

2.2V     0x00C0

1.65V     0x0016

1.1V     0x0069

0.55V     0x00C3

0V    0x0011

To me, it looks like the most significant 4-bits are missing.

In my code I am using the bit-shifting code to access the two bytes:

i2cbuf[1] = (adcVal >> 😎 & 0xFF; // First byte

i2cbuf[2] = adcVal & 0xFF; // Second byte

As a test, if I only bit-shift 4 bits then I output a copy of bits 4-7 which makes sense.

I am most likely making a simple mistake so I would be very grateful if someone could suggest reasons for this error and/or things for me to clarify/check to get to the bottom of this.

Many thanks,

Rich

0 Likes
1 Solution
Anonymous
Not applicable

Hi, thanks for the suggestions. I used the debugging tool (first time for

me) and realised that I'd declared the variable to hold the ADC output to

be 8-bit rather than 16-bit hence I wasn't seeing the most significant

bits. Thank you once again for the suggestions.

Best wishes,

Richard

On 6 November 2017 at 21:28, user_78878863 <community-manager@cypress.com>

View solution in original post

0 Likes
4 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Shouldn't this be i2cbuf[0] and [1], respective?

0 Likes
Anonymous
Not applicable

I have something else going into i2cbuf[0].

On 6 Nov 2017 8:35 pm, "user_78878863" <community-manager@cypress.com>

0 Likes

So maybe you should upload your complete project (or a minimal one showing the behaviour), together with a oscilloscope / logic analyzer shot of the I2C output (so we can see what gets send over the wires).

Alternatively: set a breakpoint just before the I2C send and verify that the buffer what it should be (or write it to the serial port and check with the PC).

0 Likes
Anonymous
Not applicable

Hi, thanks for the suggestions. I used the debugging tool (first time for

me) and realised that I'd declared the variable to hold the ADC output to

be 8-bit rather than 16-bit hence I wasn't seeing the most significant

bits. Thank you once again for the suggestions.

Best wishes,

Richard

On 6 November 2017 at 21:28, user_78878863 <community-manager@cypress.com>

0 Likes