Problem occurs when using external LED


(Daniel kirubakaran) #1

Hi,
Anybody worked with external led blink or turn on /off ?
Because i am facing this issue, Should i make some changes in wiring_digital?
It works well with my own code ,when i set and clear XOR,But in wiring_digital it is always cleared.Someone can clear my doubt.

And no problem with inbuilt led.

Thank you.


(Bruce Hoult) #2

Are you suggesting digitalWrite() doesn’t work?

I’ve never had any problem with it. Whether output pins are connected to LEDs or stepper motors or whatever is irrelevant.


(Daniel kirubakaran) #3

Yes, I don’t know why !
It happens only when using an LED ,My connections 're correct.
ok then i will analyze the problem.


(Bruce Hoult) #4

Can you be more explicit about your circuit?


(Daniel kirubakaran) #5

This is my code
if( strcmp(store,on) == 0){

 GPIO_REG(GPIO_OUTPUT_EN)      &=  ~(1 << PIN_15_OFFSET);
 GPIO_REG(GPIO_OUTPUT_VAL)     |=   (1 << PIN_15_OFFSET);
 GPIO_REG(GPIO_OUTPUT_XOR)     |=   (1 << PIN_15_OFFSET);

//digitalWrite(PIN_15_OFFSET,HIGH);

 _puts("Led on\n");
mtime_wait(1*32768);
}
else if( strcmp(store,off) == 0){

 GPIO_REG(GPIO_OUTPUT_EN)      |=  (1 << PIN_15_OFFSET);
 GPIO_REG(GPIO_OUTPUT_VAL)     |=  (1 << PIN_15_OFFSET);
 GPIO_REG(GPIO_OUTPUT_XOR)     |=  (1 << PIN_15_OFFSET);

//digitalWrite(PIN_15_OFFSET,LOW);
 _puts("Led off\n");

}

but when i use digitalWrite it doesn’t work.

I have connected the led pins to dig pin 15 and GND, I tried with other pins also.


(Bruce Hoult) #6

And your code :slight_smile:

You need a “pinMode(15, OUTPUT);” somewhere. And it should be “digitalWrite(15, HIGH);”, not PIN_15_OFFSET there. The digitalWrite() maps the value 15 to the appropriate PIN_15_OFFSET itself, which is board-dependent i.e. different for AVR or RISC-V or ARM boards.


(Daniel kirubakaran) #7

yeah, that “pinMode(PIN_15_OFFSET, OUTPUT);” was initialized above the code i forgot to show it.

Oh! really? Then i will change it to “15” and check it.


(Bruce Hoult) #8

Also, as with the built-in LED, you should wire the LED between the pin and 3.3 V or 5 V, not between the pin and GND, or you’ll get reversed sense of HIGH/LOW.

See the bottom left of P3 of https://sifive.cdn.prismic.io/sifive%2F080cdef9-4631-4c9b-b8f5-7937fbdec8a4_hifive1-a01-schematics.pdf


(Daniel kirubakaran) #9

Yes i had that issue!

Its working now bruce ! it was my mistake, i thought that i should use its offset values.

Thanks a lot, learnt a new thing today.:smiley: