8 years, 7 months ago.

AnalogIn on a Xuntong PTR5188 (nrf5188) board

Hi, I'm using a Xuntong PTR5188 (nrf5188) board for my project soldered on a custom PCB. I'd like to use one of the two ADC pins available on the Xuntong board (P0.26, P0.27) for analog inout. However, if I initialise the pins the code still compiles but the nrf51 freezes after programming. If I change to one of the standard analog in pins (P0.00 - P00.06) the MCU works fine.

AnalogIn ain(p26);

Any idea what needs to be done to fix my problem?

Thanks a lot, Jens

Ok, so I tried to use P0.26 & 27 as analogIn pins on the nrf51-DK and it crashes the MCU too. On the back of the DK the function for these two PINs is described as XL2 & XL1. So can't they be used as AnalogIn? The nrf docu says pins can be used:

1) General purpose I/O pin 2) ADC/LPCOMP input 0 3)Connection for 32.768 kHz crystal

posted by Jens Strümper 14 Sep 2015

Ok, seems these two PINs are not covered by by mbed's analogin api. I imported mbed-src and added a line for P0.27 to the end of the pinMap array in analogin_api.c.

static const PinMap PinMap_ADC[] = {
    {p1, ADC0_0, 4},
    {p2, ADC0_0, 8},
    {p3, ADC0_0, 16},
    {p4, ADC0_0, 32},
    {p5, ADC0_0, 64},
    {p6, ADC0_0, 128},
    {p27, ADC0_0, 256},
    {NC, NC, 0}
};

On the DK the external XTAL is connected, so it's not possible to use it as GPIO or analog pin unless some solder points are cut.

posted by Jens Strümper 14 Sep 2015

Update: So the compile problem was fixed but it still didn't read from analog in. I posted a question in the nordic forum and got help. https://devzone.nordicsemi.com/question/51677/adc-on-nrf51-pin-26-27/

The pinmap needs to be corrected:

static const PinMap PinMap_ADC[] = {
    {p1, ADC0_0, 4},
    {p2, ADC0_0, 8},
    {p3, ADC0_0, 16},
    {p4, ADC0_0, 32},
    {p5, ADC0_0, 64},
    {p6, ADC0_0, 128},
    {p26, ADC0_0, 1},
    {p27, ADC0_0, 2},
    {NC, NC, 0}
};

The correct values written to the register are "1" for p26 and "2" for p27.

posted by Jens Strümper 18 Sep 2015

I'm also using the same PTR51822 modules for a design but I am trying to use P0.26 and P0.27 as Digital outs. I checked your other thread at the nordic devzone and you say that the P0.26 and P0.27 pins are broken out for ADC only. I could not find this information from Xuntong. Can you confirm they are only ADC and can not be used as outputs.

Thanks, Duncan

posted by D McCloud 21 Sep 2015

Hi Duncan, I've probably miss phrased my post at the nordic devzone. P0.26 & P0.27 can be used as digital outs as well. I think this does not even require any changes to the underlying mbed api. Do you have any problems? One note: you may have already discovered this - if you use the HRM1017 board your code will run on the ptr1822 out of the box as this board uses the internal oscillator like the ptr1822 does. There are some people using the nrf-DK as target and then modifying the mbed library. But this is not necessary if you use the HRM1017.

Cheers, Jens

posted by Jens Strümper 22 Sep 2015
Be the first to answer this question.