LPC1768 Open Drain Output settings

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1768 Open Drain Output settings

Jump to solution
1,407 Views
contr2889
Contributor III

Hi everyone,

   I am trying to use lpc1768 to have 2 pins with Open Drain output (p2.2 and p2.2) and external pull ups. When I set these pins only as output I get pulses with correct timing but when I add this line "LPC_PINCON->PINMODE_OD2 |= ((1<<1)|(1<<2))" I get a weird behavior in these pins, not matching the timing and getting extra pulses.

My code is the next:

void Sensor::init()
{
    LPC_PINCON->PINMODE_OD2 |= ((1<<1)|(1<<2));
    LPC_GPIO2->FIODIR |= ((1<<1)|(1<<2)); 
    LPC_GPIO2->FIOCLR |= ((1<<1)|(1<<2));
}

void Sensor::measure(void)
{
    LPC_GPIO2->FIOSET |= ((1<<1)|(1<<2));
    wait_us(50);
    LPC_GPIO2->FIOCLR |= ((1<<1)|(1<<2));
    wait_us(50);
    LPC_GPIO2->FIOSET |= ((1<<1)|(1<<2));
    wait_us(50);
    LPC_GPIO2->FIOCLR |= ((1<<1)|(1<<2));
}

 

What I am doing wrong to get OpenDrain output with the correct timing? 

Thanks for your help, Regards.

 

Labels (1)
0 Kudos
Reply
1 Solution
1,361 Views
contr2889
Contributor III

The solution for me was not use pins p2.1 and p2.2, instead I changed them for p0.24 and p0.25 to have two pins in open drain mode.

View solution in original post

0 Kudos
Reply
3 Replies
1,362 Views
contr2889
Contributor III

The solution for me was not use pins p2.1 and p2.2, instead I changed them for p0.24 and p0.25 to have two pins in open drain mode.

0 Kudos
Reply
1,394 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hello,

I noticed that with that line of code you just mentioned, you are writing a 110’b in the PINMODE_OD2 register and I believe that is incorrect, because that register can only be 1 or 0. In this case, the register stays with a value of 0, and that is configuring the register in not open drain mode. Could you please try to change that value to 1?

Regards, Daniel.

0 Kudos
Reply
1,381 Views
contr2889
Contributor III

@DanielRuvalcaba Thanks for your reply.

    I follow your advice and I changed my code to clearly set the bits in 1'b but I still have the same problem. Here you can see the test code that I implemented:

void Sensor::init()
{
    Log::info("PINSEL4: %X", LPC_PINCON->PINSEL4);
    Log::info("LPC_GPIO2->FIODIR: %X", LPC_GPIO2->FIODIR);
    Log::info("PINMODE4: %X", LPC_PINCON->PINMODE4);
    Log::info("PINMODE_OD2: %X", LPC_PINCON->PINMODE_OD2);

    LPC_PINCON->PINSEL4 &= 0xFFFFFFC3;
    LPC_GPIO2->FIODIR |= 0x00000006;
    LPC_PINCON->PINMODE4 |= 0x00000028;  
    LPC_PINCON->PINMODE4 &= 0xFFFFFFEB;
    LPC_PINCON->PINMODE_OD2 |= 0x00000006;

    Log::info("PINSEL4: %X", LPC_PINCON->PINSEL4);
    Log::info("LPC_GPIO2->FIODIR: %X", LPC_GPIO2->FIODIR);
    Log::info("PINMODE4: %X", LPC_PINCON->PINMODE4);
    Log::info("PINMODE_OD2: %X", LPC_PINCON->PINMODE_OD2);
}
void Sensor::measure(void)
{
    LPC_GPIO2->FIOSET |= 0x00000006;
    wait_us(50);
    LPC_GPIO2->FIOCLR |= 0x00000006;
    wait_us(50);
    LPC_GPIO2->FIOSET |= 0x00000006;
    wait_us(50);
    LPC_GPIO2->FIOCLR |= 0x00000006;
    wait_us(50);
}

And this is what I get in the logs:

    PINSEL4: 0
    LPC_GPIO2->FIODIR: 1A0
    PINMODE4: 28BFC
    PINMODE_OD2: 0
    PINSEL4: 0
    LPC_GPIO2->FIODIR: 1A6
    PINMODE4: 28BE8
    PINMODE_OD2: 6

Then I can see that every bit is set correctly but still I got no pulses on the pins p2.1 and p2.2. Every test was made with a 10k resistor to 3.3V for pullups, but nothing happens. But  if in the method measure() I put a longer delay as wait_us(1000), I get two pulses but with an incorrect random width.  

As I said before, If I set these pins as simpe outputs without opendrain, then I get two pulses with the correct width of 50us and separation of 50us.  

Which could be the problem here?

0 Kudos
Reply